User management and first pass at IIgs project compiling.

This commit is contained in:
Scott Duensing 2022-09-21 20:07:24 -05:00
parent bd1b158a87
commit 9c43a9a247

View file

@ -24,6 +24,7 @@
SRC=${HOME}/joeylib/joeylib/src
IIGS=${HOME}/cross/gsos-wdc-orca
CADIUS=${IIGS}/cadius/cadius
SDL2_OLD=25f9ed87ff6947d9576fc9d79dee0784e638ac58
SDL2_NEW=97a5e744497ff7cc93edc5119d67cad3ee86dd57
OLD_PATH=${PATH}
@ -31,6 +32,22 @@ OLD_PATH=${PATH}
export GOLDEN_GATE=${IIGS}/ORCA
function addBuildUser() {
local USER=$1
local PASS=$2
local SALT=$(LC_ALL=C tr -cd "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" < /dev/urandom | head -c 8)
local CRYPT=$(perl -e 'print crypt($ARGV[0], $ARGV[1])' ${PASS} ${SALT})
sudo useradd -m -G sftponly -s /sbin/false -p "${CRYPT}" "${USER}"
sudo chown root:root /home/${USER}
sudo chmod 755 /home/${USER}
sudo mkdir -p /home/${USER}/build
sudo chown ${USER}:${USER} /home/${USER}/build
sudo chmod u+rwX /home/${USER}/build
sudo chmod go-rwx /home/${USER}/build
}
function buildIIgsSDK() {
local GGATE=$1
local ORCA=$2
@ -168,6 +185,8 @@ function buildIIgsSDK() {
function buildJoeyLib() {
local OUT=
OLD_CFLAGS=${CFLAGS}
if [[ ! -d joeylib ]]; then
@ -180,7 +199,7 @@ function buildJoeyLib() {
pushd dist/${NAME}-${ARCH}
case ${BACKEND} in
orca)
local OUT=${GOLDEN_GATE}/out/joey
OUT=${GOLDEN_GATE}/out/joey
rm -rf ${OUT} && true
mkdir -p ${OUT}/out/joey
pushd ${SRC}
@ -248,7 +267,8 @@ function buildSDL2() {
git checkout ${TAG}
popd
clearBuild
rm -rf build && true
mkdir -p build
pushd build
../SDL/configure \
@ -267,21 +287,221 @@ function buildSDL2() {
}
function clearBuild() {
rm -rf build && true
mkdir -p build
function configureSFTP() {
if [[ ! -f /etc/ssh/sftponly_ready ]]; then
sudo addgroup sftponly && true
sudo sed -i 's/^Subsystem/#Subsystem/g' sshd_config
echo "Subsystem sftp internal-sftp -f AUTH -l VERBOSE" | sudo tee -a /etc/ssh/sshd_config
echo "Match Group sftponly" | sudo tee -a /etc/ssh/sshd_config
echo -e "\tChrootDirectory %h" | sudo tee -a /etc/ssh/sshd_config
echo -e "\tForceCommand internal-sftp" | sudo tee -a /etc/ssh/sshd_config
echo -e "\tAllowTcpForwarding no" | sudo tee -a /etc/ssh/sshd_config
echo -e "\tX11Forwarding no" | sudo tee -a /etc/ssh/sshd_config
sudo systemctl restart sshd
sudo touch /etc/ssh/sftponly_ready
fi
}
function configureSFTP() {
sudo addgroup sftponly && true
echo "Match Group sftponly" | sudo tee /etc/ssh/sshd_config.d/sftponly.conf
echo -e "\tChrootDirectory %h" | sudo tee -a /etc/ssh/sshd_config.d/sftponly.conf
echo -e "\tForceCommand internal-sftp" | sudo tee -a /etc/ssh/sshd_config.d/sftponly.conf
echo -e "\tAllowTcpForwarding no" | sudo tee -a /etc/ssh/sshd_config.d/sftponly.conf
echo -e "\tX11Forwarding no" | sudo tee -a /etc/ssh/sshd_config.d/sftponly.conf
sudo systemctl restart sshd
# Read for user creation: https://askubuntu.com/questions/134425/how-can-i-chroot-sftp-only-ssh-users-into-their-homes
function delBuildUser() {
local USER=$1
sudo userdel -f -r ${USER}
}
function doBuild() {
local DIST=$1
local SRC=$2
local LINE=
local DATA=()
local CFILES=()
local OFILES=
local FILE=
local EXTENSION=
local LOG=
local TARGET=
local GSTARGET=
local LIB=
local O=
local DISK=
pushd "${SRC}"
# Are there old reults to clean up?
if [[ -f build.finished ]]; then
rm build.finished
fi
if [[ -d results ]]; then
rm -rf results
fi
mkdir -p results
BUILD_RESULTS=${SRC}/results
# Read project information.
BUILD_PLATFORMS="["
BUILD_PROJECT=
while IFS= read -r LINE; do
if [[ -z ${BUILD_PROJECT} ]]; then
BUILD_PROJECT=${LINE}
# Generate a list of non-source files.
for FILE in $(ls -1); do
if [[ "${FILE}" != "build.start" && "${FILE}" != "build.temp" && "${FILE}" != "build.tar.bz2" && "${FILE}" != "results" ]]; then
EXTENSION="${FILE##*.}"
if [[ "${EXTENSION}" != "c" && "${EXTENSION}" != "h" && "${EXTENSION}" != "asm" && "${EXTENSION}" != "macro" && "${EXTENSION}" != "inc" ]]; then
DATA+=(${FILE})
fi
fi
done
# Generate a list of C files to compile.
CFILES=($(ls -1 *.c))
else
BUILD_PLATFORMS="${BUILD_PLATFORMS}${LINE,,} "
case ${LINE,,} in
iigs)
setCompiler gsos 816
TARGET="${GOLDEN_GATE}/out/build"
GSTARGET="31:/out/build"
;;
linux32)
setCompiler linux i386
TARGET="${SRC}/temp"
;;
linux64)
setCompiler linux x86_64
TARGET="${SRC}/temp"
;;
macosx32)
setCompiler macos i386
TARGET="${SRC}/temp"
;;
macosx64)
setCompiler macos x86_64
TARGET="${SRC}/temp"
;;
macosa64)
setCompiler macos arm
TARGET="${SRC}/temp"
;;
win32)
setCompiler windows i386
TARGET="${SRC}/temp"
;;
win64)
setCompiler windows x86_64
TARGET="${SRC}/temp"
;;
esac
LOG="${BUILD_RESULTS}/build.${LINE,,}"
LIB="${DIST}/${NAME}-${ARCH}"
[[ -d "${TARGET}" ]] && rm -rf "${TARGET}"
mkdir -p "${TARGET}"
# Make sure we have the official JoeyLib header.
cp -f "${DIST}/joey.h" "${TARGET}/."
case ${BACKEND} in
orca)
# Compile C files and generate object list.
OFILES=""
for FILE in "${CFILES[@]}"; do
O=${FILE%.*}
OFILES="${OFILES} ${GSTARGET}/${O}"
iix compile ${FILE} keep=${GSTARGET}/${O}
done
# We need a local copy of JoeyLib to link.
cp -f "${LIB}/jIIgsc.a#b10000" "${TARGET}/jIIgsc.a"
cp -f "${LIB}/jIIgsc.root#b10000" "${TARGET}/jIIgsc.root"
cp -f "${LIB}/jIIgsasm.a#b10000" "${TARGET}/jIIgsasm.a"
cp -f "${LIB}/jIIgsasm.root#b10000" "${TARGET}/jIIgsasm.root"
cp -f "${LIB}/joey.a#b10000" "${TARGET}/joey.a"
iix chtyp -t obj ${GSTARGET}/jIIgsc.a
iix chtyp -t obj ${GSTARGET}/jIIgsc.root
iix chtyp -t obj ${GSTARGET}/jIIgsasm.a
iix chtyp -t obj ${GSTARGET}/jIIgsasm.root
iix chtyp -t obj ${GSTARGET}/joey.a
# Add our library files to OFILES
OFILES="${GSTARGET}/jIIgsc ${GSTARGET}/joey ${GSTARGET}/jIIgsasm ${OFILES}"
# Link.
iix -DKeepType=S16 link ${OFILES} keep=${GSTARGET}/${BUILD_PROJECT}#b3db03
# Create disk image, setting known file types
DISK=${BUILD_RESULTS}/${LINE,,}/build.po
${CADIUS} createvolume ${DISK} ${BUILD_PROJECT} 32MB > /dev/null
${CADIUS} createfolder ${DISK} ${BUILD_PROJECT}/data > /dev/null
${CADIUS} addfile ${DISK} ${BUILD_PROJECT} ${TARGET}/${BUILD_PROJECT}#b3db03 > /dev/null
${CADIUS} addfile ${DISK} ${BUILD_PROJECT}/data ${LIB}/Tool222#ba0000 > /dev/null
for FILE in "${DATA[@]}"; do
#***TODO*** Data conversion here!
O=`basename ${FILE}`#060000
cp -f ${FILE} ${O}
${CADIUS} addfile ${DISK} ${BUILD_PROJECT}/data ${O} > /dev/null
rm ${O}
done
;;
SDL2)
;;
esac
fi
done < build.start
BUILD_PLATFORMS="${BUILD_PLATFORMS}]"
popd
}
function doInstall() {
local GGUSER=$1
local GGPASS=$2
updateSystem
configureSFTP
buildIIgsSDK "Golden Gate.msi" "Opus ][ The Software.iso" id_rsa id_rsa.pub "${GGUSER}" "${GGPASS}"
buildMacOSSDK MacOSX10.13.sdk.tar.xz macos-intel
buildMacOSSDK MacOSX11.3.sdk.tar.xz macos-apple
setCompiler gsos 816
buildJoeyLib
setCompiler linux i386
buildSDL2 ${SDL2_NEW}
buildJoeyLib
setCompiler linux x86_64
buildSDL2 ${SDL2_NEW}
buildJoeyLib
setCompiler macos i386
buildSDL2 ${SDL2_OLD}
buildJoeyLib
setCompiler macos x86_64
buildSDL2 ${SDL2_OLD}
buildJoeyLib
setCompiler macos arm
buildSDL2 ${SDL2_NEW}
buildJoeyLib
setCompiler windows i386
buildSDL2 ${SDL2_NEW}
buildJoeyLib
setCompiler windows x86_64
buildSDL2 ${SDL2_NEW}
buildJoeyLib
}
@ -423,46 +643,92 @@ function setCompiler() {
function scriptIsDownloaded() {
local GGUSER=$1
local GGPASS=$2
local ACTION=$1
# updateSystem
# configureSFTP
case ${ACTION} in
add)
addBuildUser "${2}" "${3}"
;;
build)
doBuild "${2}" "${3}"
;;
del)
delBuildUser "${2}"
;;
install)
doInstall "${2}" "${3}"
;;
server)
startBuildServer "${2}"
;;
*)
echo "${0} add USER PASS"
echo "${0} build DIST SRC"
echo "${0} del USER"
echo "${0} install GGUSER GGPASS"
echo "${0} server DIST"
;;
esac
}
# buildIIgsSDK "Golden Gate.msi" "Opus ][ The Software.iso" id_rsa id_rsa.pub "${GGUSER}" "${GGPASS}"
# buildMacOSSDK MacOSX10.13.sdk.tar.xz macos-intel
# buildMacOSSDK MacOSX11.3.sdk.tar.xz macos-apple
setCompiler gsos 816
buildJoeyLib
function startBuildServer() {
local DIST=$1
local LOG=/opt/joey/${0}.log
local USERNAME=
local FILE=
# setCompiler linux i386
# buildSDL2 ${SDL2_NEW}
# buildJoeyLib
# Log startup.
echo "$(date) - Startup ${0}" >> ${LOG}
# setCompiler linux x86_64
# buildSDL2 ${SDL2_NEW}
# buildJoeyLib
cd /home
# setCompiler macos i386
# buildSDL2 ${SDL2_OLD}
# buildJoeyLib
while true; do
# setCompiler macos x86_64
# buildSDL2 ${SDL2_OLD}
# buildJoeyLib
# Find users with a "build.start" file.
for USERNAME in $(ls -1); do
mkdir -p "${USERNAME}/build"
chown -r ${USERNAME}:${USERNAME} "${USERNAME}/build"
chmod u+rwX "${USERNAME}/build"
chmod go-rwx "${USERNAME}/build"
if [[ -f "${USERNAME}/build/build.start" ]]; then
# setCompiler macos arm
# buildSDL2 ${SDL2_NEW}
# buildJoeyLib
doBuild "${DIST}" "${USERNAME}/build"
# setCompiler windows i386
# buildSDL2 ${SDL2_NEW}
# buildJoeyLib
pushd "${USERNAME}/build" &> /dev/null
# Compress the results.
tar cJf build.temp results
chown ${USERNAME}:${USERNAME} build.temp
# Erase everything except the temp file.
rm -rf "${BUILD_RESULTS}"
for FILE in $(ls -1); do
if [[ ${FILE} != "build.temp" ]]; then
rm ${FILE}
fi
done
# Signal JoeyDev we're done.
mv build.temp build.tar.bz2
# setCompiler windows x86_64
# buildSDL2 ${SDL2_NEW}
# buildJoeyLib
# Log it.
echo "$(date) - Compiled ${BUILD_PROJECT} for ${USERNAME} on ${BUILD_PLATFORMS}" >> ${LOG}
popd &> /dev/null
fi
done
sleep 1
done
}
@ -514,4 +780,4 @@ function updateSystem() {
}
scriptIsDownloaded "$1" "$2"
scriptIsDownloaded "$1" "$2" "$3"