diff --git a/scripts/buildVm.sh b/scripts/buildVm.sh new file mode 100755 index 0000000..8cc1dbf --- /dev/null +++ b/scripts/buildVm.sh @@ -0,0 +1,517 @@ +#!/bin/bash -xe + +# +# JoeyLib +# Copyright (C) 2018-2021 Scott Duensing +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely, subject to the following restrictions: +# +# 1. The origin of this software must not be misrepresented; you must not +# claim that you wrote the original software. If you use this software +# in a product, an acknowledgment in the product documentation would be +# appreciated but is not required. +# 2. Altered source versions must be plainly marked as such, and must not be +# misrepresented as being the original software. +# 3. This notice may not be removed or altered from any source distribution. +# + + +SRC=${HOME}/joeylib/joeylib/src +IIGS=${HOME}/cross/gsos-wdc-orca +SDL2_OLD=25f9ed87ff6947d9576fc9d79dee0784e638ac58 +SDL2_NEW=97a5e744497ff7cc93edc5119d67cad3ee86dd57 +OLD_PATH=${PATH} + +export GOLDEN_GATE=${IIGS}/ORCA + + +function buildIIgsSDK() { + local GGATE=$1 + local ORCA=$2 + local PUBLIC=$3 + local PRIVATE=$4 + local GGUSER=$5 + local GGPASS=$6 + local RESULT= + local O= + + mkdir -p "${IIGS}/ORCA" + chmod 777 "${IIGS}/ORCA" + + mkdir -p ~/.ssh + cp -f "${PUBLIC}" ~/.ssh/id_rsa.pub + cp -f "${PRIVATE}" ~/.ssh/id_rsa + touch ${HOME}/.ssh/authorized_keys + touch ${HOME}/.ssh/config + chmod go-w ${HOME} + chmod 700 ${HOME}/.ssh + chmod 600 ${HOME}/.ssh/*id_rsa + chmod 644 ${HOME}/.ssh/*.pub + chmod 644 ${HOME}/.ssh/authorized_keys + chmod 644 ${HOME}/.ssh/config + + if [[ ! -e "${IIGS}/jfsDrive.img" ]]; then + O=${IIGS}/mountORCA.sh + echo "#!/bin/bash" > "${O}" + echo "IIGS=${IIGS}" >> "${O}" + echo "if ! mount | grep \${IIGS}/ORCA | grep -q jfs; then" >> "${O}" + echo -e "\tfsck.jfs -a \${IIGS}/jfsDrive.img" >> "${O}" + echo -e "\tsudo mount -t jfs \${IIGS}/jfsDrive.img \${IIGS}/ORCA" >> "${O}" + echo -e "\techo MOUNT=\${IIGS}/ORCA >> \${IIGS}/lastMount.cfg" >> "${O}" + echo "fi" >> "${O}" + chmod +x "${O}" + O=${IIGS}/unmountORCA.sh + echo "#!/bin/bash" > "${O}" + echo "IIGS=${IIGS}" >> "${O}" + echo "if [[ -e \${IIGS}/lastMount.cfg ]]; then" >> "${O}" + echo -e "\tsource \${IIGS}/lastMount.cfg" >> "${O}" + echo -e "\tsudo umount \${MOUNT}" >> "${O}" + echo -e "\trm \${IIGS}/lastMount.cfg" >> "${O}" + echo "fi" >> "${O}" + chmod +x "${O}" + fallocate -l 32M "${IIGS}/jfsDrive.img" + mkfs.jfs -O -q -L IIgs "${IIGS}/jfsDrive.img" + fi + + "${IIGS}/mountORCA.sh" + sudo chown $(id -ru):$(id -rg) "${IIGS}/ORCA/." + + if [[ ! -d GoldenGate ]]; then + ssh-keygen -F gitlab.com || ssh-keyscan gitlab.com > ~/.ssh/known_hosts + git config --global credential.helper cache + git clone https://${GGUSER}:${GGPASS}@gitlab.com/GoldenGate/GoldenGate.git + fi + + pushd GoldenGate + git submodule init + git submodule update + mkdir -p build + cd build + cmake -DCMAKE_INSTALL_PREFIX=$(pwd)/installed .. + make + make install + mkdir -p ${IIGS} + cp -f bin/{iix,dumpobj,opus-extractor} "${IIGS}/." + cd installed + msiextract "${HOME}/${GGATE}" + find -name ".*" -delete + cp -rf GoldenGate/* "${IIGS}/ORCA/." + popd + + isoinfo -i "${ORCA}" -x /FOR_EMUL/BYTEWORK.S\;1 > BYTEWORKS + "${IIGS}/opus-extractor" -v BYTEWORKS "${IIGS}/ORCA" + rm BYTEWORKS + + fetchGitHubRelease RESULT byteworksinc ORCA-C 2mg + "${IIGS}/opus-extractor" -v -s / ${RESULT} "${IIGS}/ORCA" + + export PATH=${OLD_PATH}:${IIGS} + pushd ${GOLDEN_GATE} + for O in etc/* ; do iix chtyp -t txt "${O}" ; done + for O in lib/* ; do if [ -f "${O}" ] ; then iix chtyp -t lib "${O}" ; fi ; done + for O in usr/lib/lib* ; do iix chtyp -t lib "${O}" ; done + for O in usr/lib/tmac/* ; do iix chtyp -t txt "${O}" ; done + for O in bin/* ; do iix chtyp -t exe "${O}" ; done + for O in usr/bin/* ; do iix chtyp -t exe "${O}" ; done + for O in usr/local/bin/* ; do iix chtyp -t exe "${O}" ; done + for O in Languages/* ; do if [ -f "${O}" ] ; then iix chtyp -t exe "${O}" ; fi ; done ; + for O in Utilities/Help/* ; do if [ -f "${O}" ] ; then iix chtyp -t txt "${O}" ; fi ; done ; + for O in Utilities/* ; do if [ -f "${O}" ] ; then iix chtyp -t exe "${O}" ; fi ; done ; + for O in Libraries/* ; do if [ -f "${O}" ] ; then iix chtyp -t lib "${O}" ; fi ; done ; + for O in Libraries/AInclude/* ; do if [ -f "${O}" ] ; then iix chtyp -t txt "${O}" ; fi ; done ; + for O in Libraries/APWCInclude/* ; do if [ -f "${O}" ] ; then iix chtyp -t txt "${O}" ; fi ; done ; + for O in Libraries/AppleUtil/* ; do if [ -f "${O}" ] ; then iix chtyp -t txt "${O}" ; fi ; done ; + for O in Libraries/ORCACDefs/* ; do if [ -f "${O}" ] ; then iix chtyp -l cc "${O}" ; fi ; done ; + for O in Libraries/ORCAInclude/* ; do if [ -f "${O}" ] ; then iix chtyp -l asm "${O}" ; fi ; done ; + for O in Libraries/RInclude/* ; do if [ -f "${O}" ] ; then iix chtyp -l rez "${O}" ; fi ; done ; + for O in Libraries/Tool.Interface/* ; do if [ -f "${O}" ] ; then iix chtyp -l pascal "${O}" ; fi ; done ; + for O in Libraries/GSoftDefs/* ; do if [ -f "${O}" ] ; then iix chtyp -t 0x5e -a 0x8007 "${O}" ; fi ; done ; + for O in Libraries/ORCAPascalDefs/* ; do if [ -f "${O}" ] ; then iix chtyp -t 0x5e -a 0x8009 "${O}" ; fi ; done ; + for O in Libraries/m2defs/* ; do if [ -f "${O}" ] ; then iix chtyp -t 0x5e -a 0x8006 "${O}" ; fi ; done ; + popd + export PATH=${OLD_PATH} + + if [[ ! -d cadius ]]; then + git clone https://skunkworks.kangaroopunch.com/mirrors/cadius.git + pushd cadius + make + mkdir -p "${IIGS}/cadius" + cp -f bin/release/cadius "${IIGS}/cadius/." + popd + fi + + if [[ ! -e "${IIGS}/ntpconverter/ntpconverter.php" ]]; then + download http://www.ninjaforce.com/downloads/ntconverter.zip + unzip ntconverter.zip + mkdir -p "${IIGS}/ntpconverter" + cp -f ntconverter.php "${IIGS}/ntpconverter/ntpconverter.php" + fi + + if [[ ! -e "${IIGS}/Tool222#ba0000" ]]; then + download http://www.ninjaforce.com/downloads/ninjatrackerplus_tool222_v1.4.2mg + "${IIGS}/cadius/cadius" extractfile ninjatrackerplus_tool222_v1.4.2mg NTP.TOOL222V1.4/SYSTEM/TOOLS/TOOL222 . + cp -f "TOOL222#BA0000" "${IIGS}/Tool222#ba0000" + fi + + "${IIGS}/unmountORCA.sh" + + if [[ ! -e "${IIGS}/jfsDrive.img.backup.tar.bz2" ]]; then + tar cjf "${IIGS}/jfsDrive.img.backup.tar.bz2" "${IIGS}/jfsDrive.img" + fi +} + + +function buildJoeyLib() { + OLD_CFLAGS=${CFLAGS} + + if [[ ! -d joeylib ]]; then + git clone https://skunkworks.kangaroopunch.com/skunkworks/joeylib.git + fi + + rm -rf dist/${NAME}-${ARCH} && true + mkdir -p dist/${NAME}-${ARCH} + + pushd dist/${NAME}-${ARCH} + case ${BACKEND} in + orca) + local OUT=${GOLDEN_GATE}/out/joey + rm -rf ${OUT} && true + mkdir -p ${OUT}/out/joey + pushd ${SRC} + iix assemble jIIgs.asm keep=31:/out/joey/jIIgsasm + iix compile jIIgs.c keep=31:/out/joey/jIIgsc + iix compile joey.c keep=31:/out/joey/joey + popd + cp -f "${OUT}/jIIgsc.root" "jIIgsc.root#b10000" + cp -f "${OUT}/jIIgsc.a" "jIIgsc.a#b10000" + cp -f "${OUT}/jIIgsasm.root" "jIIgsasm.root#b10000" + cp -f "${OUT}/jIIgsasm.a" "jIIgsasm.a#b10000" + cp -f "${OUT}/joey.a" "joey.a#b10000" + cp -f "${IIGS}/Tool222#ba0000" . + ;; + + SDL2) + export CFLAGS="${CFLAGS} -Wall -D_REENTRANT_ -I${SRC} -I${INSTALLED}/include -c" + ${CC} ${CFLAGS} -o jPixBuf.o ${SRC}/jPixBuf.c + ${CC} ${CFLAGS} -o jSDL2.o ${SRC}/jSDL2.c + ${CC} ${CFLAGS} -o joey.o ${SRC}/joey.c + ${AR} x ${INSTALLED}/lib/libSDL2.a + ${AR} x ${INSTALLED}/lib/libSDL2main.a + ${AR} rcs libjoeylib.a *.o + rm *.o + rm __.SYMDEF* && true + ;; + + esac + + cp -f ${SRC}/joey.h ../. + popd + + export CFLAGS=${OLD_CFLAGS} +} + + +function buildMacOSSDK() { + local SDK=$1 + local NAME=$2 + + if [[ ! -d osxcross ]]; then + git clone https://skunkworks.kangaroopunch.com/mirrors/osxcross.git + fi + + pushd osxcross + cp -f ../"${SDK}" tarballs/. + UNATTENDED=1 ./build.sh + sudo ENABLE_COMPILER_RT_INSTALL=1 ./build_compiler_rt.sh + mkdir -p ../cross/${NAME} + mv -f target/* ../cross/${NAME} + sudo mv -f /usr/lib/llvm-10/lib/clang/10.0.0/lib/darwin ../cross/${NAME}/. + ./cleanup.sh + popd +} + + +function buildSDL2() { + local TAG=$1 + + if [[ ! -d SDL ]]; then + git clone https://skunkworks.kangaroopunch.com/mirrors/SDL.git + fi + + pushd SDL + git checkout ${TAG} + popd + + clearBuild + + pushd build + ../SDL/configure \ + --target=${TRIPLE} \ + --host=${TRIPLE} \ + --build=x86_64-linux \ + --enable-static \ + --disable-shared \ + --disable-video-wayland \ + --disable-render-metal \ + --disable-video-metal \ + --prefix=${INSTALLED} + make + make install + popd +} + + +function clearBuild() { + rm -rf build && true + mkdir -p build +} + + +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 download() { + local URL=$1 + local FILE= + + trim FILE "$2" + + if [[ -z ${FILE} ]]; then + FILE=${URL##*/} + fi + + if [[ -e "${FILE}" ]]; then + rm -f "${FILE}" + fi + + wget -O "${FILE}" ${URL} +} + + +function fetchGitHubRelease() { + local __RESULT=$1 + local DEVELOPER=$2 + local COMPONENT=$3 + local EXTENSION=$4 + local URL=$(curl -s https://api.github.com/repos/${DEVELOPER}/${COMPONENT}/releases \ + | grep "browser_download_url.*${EXTENSION}" \ + | cut -d : -f 2,3 \ + | tr -d \" \ + | head -n 1) + local FILE=${URL##*/} + download ${URL} + eval $__RESULT=\${FILE} +} + + +function setCompiler() { + local OS=$1 + local CPU=$2 + + case ${OS} in + gsos) + case ${CPU} in + 816) + NAME="gsos-wdc" + ARCH=816 + ;; + + esac + BACKEND=orca + export PATH=${OLD_PATH}:${IIGS} + "${IIGS}/mountORCA.sh" + ;; + + linux) + case ${CPU} in + i386) + NAME="linux-intel" + ARCH=i386 + TRIPLE="x86_64-linux-gnu" + export CFLAGS="-m32" + ;; + + x86_64) + NAME="linux-intel" + ARCH=x86_64 + TRIPLE="${ARCH}-linux-gnu" + export CFLAGS= + ;; + + esac + BACKEND=SDL2 + export PATH=${OLD_PATH} + export LD_LIBRARY_PATH= + export CC=${TRIPLE}-gcc + export AR=${TRIPLE}-ar + ;; + + macos) + case ${CPU} in + i386) + NAME="macos-intel" + ARCH=i386 + TRIPLE="${ARCH}-apple-darwin17" + ;; + + x86_64) + NAME="macos-intel" + ARCH=x86_64 + TRIPLE="${ARCH}-apple-darwin17" + ;; + + arm) + NAME="macos-apple" + ARCH=aarch64 + TRIPLE="${ARCH}-apple-darwin20.4" + ;; + + esac + BACKEND=SDL2 + export CFLAGS= + export PATH=${HOME}/cross/${NAME}/bin:${OLD_PATH} + export LD_LIBRARY_PATH=${HOME}/cross/${NAME}/lib + export CC=${TRIPLE}-clang + export AR=${TRIPLE}-ar + sudo rm -f /usr/lib/llvm-10/lib/clang/10.0.0/lib/darwin && true + sudo ln -s ${HOME}/cross/${NAME}/darwin /usr/lib/llvm-10/lib/clang/10.0.0/lib/. + ;; + + windows) + case ${CPU} in + i386) + NAME="windows-intel" + ARCH=i686 + TRIPLE="${ARCH}-w64-mingw32" + ;; + + x86_64) + NAME="windows-intel" + ARCH=x86_64 + TRIPLE="${ARCH}-w64-mingw32" + ;; + + esac + BACKEND=SDL2 + export PATH=${OLD_PATH} + export LD_LIBRARY_PATH= + export CFLAGS="-static-libgcc" + export CC=${TRIPLE}-gcc + export AR=${TRIPLE}-ar + ;; + + esac + + INSTALLED=${HOME}/installed/${NAME}-${ARCH} + mkdir -p ${INSTALLED} +} + + +function scriptIsDownloaded() { + 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 +} + + +function trim() { + local __RESULT=$1 + local __VAR="${*:2}" + + # remove leading whitespace characters + __VAR="${__VAR#"${__VAR%%[![:space:]]*}"}" + # remove trailing whitespace characters + __VAR="${__VAR%"${__VAR##*[![:space:]]}"}" + + eval $__RESULT=\${__VAR} +} + + +function updateSystem() { + sudo apt update + sudo apt -y upgrade + sudo apt -y dist-upgrade + sudo dpkg --add-architecture i386 + sudo apt -y install \ + autoconf \ + build-essential \ + bzip2 \ + clang \ + cmake \ + cpio \ + gcc-multilib \ + gzip \ + libbz2-dev \ + liblzma-dev \ + libssl-dev \ + libxml2-dev \ + llvm \ + mingw-w64 \ + patch \ + php-cli \ + sed \ + uuid-dev \ + xz-utils \ + zlib1g-dev + # ORCA / GoldenGate Stuff + sudo apt -y install \ + genisoimage \ + jfsutils \ + msitools \ + ragel +} + + +scriptIsDownloaded "$1" "$2"