joeylib/scripts/installer.sh
2019-07-13 17:44:56 -05:00

636 lines
18 KiB
Bash
Executable file

#!/bin/bash -e
#
# JoeyLib
# Copyright (C) 2018-2019 Scott Duensing <scott@kangaroopunch.com>
#
# 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.
#
#
# Global variables
#
G_TITLE="JoeyLib Installer"
G_PARENT=
G_UID=$(id -ru)
G_GID=$(id -rg)
G_HAS_IIGS=0
function buildPCDeps() {
local DIST=$1
local PREFIX=$2
local CROSS=$3
local CC_EXPORT=$4
local CXX_EXPORT=$5
local CC_OLD=$CC
local CXX_OLD=$CXX
local SRC="${G_PARENT}/joeylib/joeylib/src"
local G_CFLAGS="-Wall -D_REENTRANT_ -I${SRC} -c"
echo ""
tBoldBox tCYAN "NOTE: If an error is encountered, installer will exit!"
# Clear any existing built libraries
if [[ -d ${PREFIX} ]]; then
rm -rf ${PREFIX}
fi
mkdir -p ${PREFIX}
pushd deps &> /dev/null
export CC="${CC_EXPORT}"
export CXX="${CXX_EXPORT}"
# SDL2
echo ""
tBoldBox tPURPLE "Building SDL2"
echo ""
if [[ ! -d SDL ]]; then
hg clone http://hg.libsdl.org/SDL
fi
if [[ ! -e "${PREFIX}/lib/libSDL2.a" ]]; then
clearPCDepsBuild
pushd build &> /dev/null
../SDL/configure \
--target="${CROSS}" \
--host="${CROSS}" \
--build=x86_64-linux \
--enable-static \
--disable-shared \
--prefix=${PREFIX}
make
make install
popd &> /dev/null
fi
# libModPlug
echo ""
tBoldBox tPURPLE "Building libModPlug"
echo ""
if [[ ! -d libmodplug ]]; then
git clone https://github.com/Konstanty/libmodplug.git
pushd libmodplug &> /dev/null
libtoolize --force
aclocal
autoheader
automake --force-missing --add-missing
autoconf
popd &> /dev/null
fi
if [[ ! -e "${PREFIX}/lib/libmodplug.a" ]]; then
clearPCDepsBuild
pushd build &> /dev/null
../libmodplug/configure \
--target="${CROSS}" \
--host="${CROSS}" \
--build=x86_64-linux \
--enable-static \
--disable-shared \
--prefix=${PREFIX}
make
make install
popd &> /dev/null
fi
# SDL_mixer
echo ""
tBoldBox tPURPLE "Building SDL_mixer"
echo ""
if [[ ! -d SDL_mixer ]]; then
hg clone http://hg.libsdl.org/SDL_mixer
fi
if [[ ! -e "${PREFIX}/lib/libSDL2_mixer.a" ]]; then
clearPCDepsBuild
pushd build &> /dev/null
MODPLUG_CFLAGS="-I${PREFIX}/include -DMODPLUG_STATIC" \
MODPLUG_LIBS="-L${PREFIX}/lib -lmodplug -lstdc++ -lm" \
../SDL_mixer/configure \
--target="${CROSS}" \
--host="${CROSS}" \
--build=x86_64-linux \
--enable-static \
--disable-shared \
--prefix=${PREFIX} \
--with-sdl-prefix=${PREFIX} \
--disable-music-cmd \
--disable-music-wave \
--enable-music-mod-modplug \
--disable-music-mod-modplug-shared \
--disable-music-mod-mikmod \
--disable-music-midi \
--disable-music-ogg \
--disable-music-flac \
--disable-music-opus \
--disable-music-mp3 \
--disable-music-mp3-mpg123
make
make install
popd &> /dev/null
fi
export CC="${CC_OLD}"
export CXX="${CXX_OLD}"
# JoeyLib
echo ""
tBoldBox tPURPLE "Building JoeyLib"
echo ""
if [[ -d "${DIST}" ]]; then
rm -rf "${DIST}"
fi
mkdir -p "${DIST}"
clearPCDepsBuild
pushd build &> /dev/null
${CC_EXPORT} ${G_CFLAGS} -o jPC.o ${SRC}/jPC.c
${CC_EXPORT} ${G_CFLAGS} -o joey.o ${SRC}/joey.c
ar x ${PREFIX}/lib/libSDL2.a
ar x ${PREFIX}/lib/libSDL2_mixer.a
ar x ${PREFIX}/lib/libmodplug.a
ar rcs ${DIST}/libjoeylib.a *.o
cp -f ${SRC}/joey.h ${DIST}/../..
cp -f ${SRC}/../joey.pri ${DIST}/../..
cp -f ${SRC}/../../scripts/build-PC.helper.sh ${DIST}/../..
popd &> /dev/null
popd &> /dev/null
}
function clearPCDepsBuild() {
if [[ -d $(pwd)/build ]]; then
rm -rf $(pwd)/build
fi
mkdir -p $(pwd)/build
}
function configRead() {
if [[ -e "${G_PARENT}/joeyDev.sh" ]]; then
source "${G_PARENT}/joeyDev.sh"
fi
}
function configWrite() {
local O=${G_PARENT}/joeyDev.sh
echo "#!/bin/bash" > "${O}"
echo "if [[ -z \$JOEYPATH || \"\${JOEYPATH}\" == \"\" ]]; then" >> "${O}"
echo -e "\texport JOEYPATH=\"\${PATH}\"" >> "${O}"
echo "fi" >> "${O}"
echo "export PATH=\"\${JOEYPATH}\"" >> "${O}"
echo "export JOEY=\"${G_PARENT}\"" >> "${O}"
if [[ ${G_HAS_IIGS} == 1 ]]; then
# IIgs Runtime & ORCA Compilers
echo "export GOLDEN_GATE=\"\${JOEY}/sdks/IIgs/ORCA\"" >> "${O}"
echo "export PATH=\"\${JOEY}/sdks/IIgs:\${PATH}\"" >> "${O}"
echo "mountORCA.sh" >> "${O}"
fi
chmod +x "${O}"
}
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##*/}
if [[ -e "${FILE}" ]]; then
rm "${FILE}"
fi
wget ${URL}
eval $__RESULT=\${FILE}
}
function installIIgs() {
local RESULT=
local O=
local ORCA=
local GGATE=
local IIGS="${G_PARENT}/sdks/IIgs"
G_HAS_IIGS=1
configWrite
configRead
if [[ -e "${IIGS}/unmountORCA.sh" ]]; then
"${IIGS}/unmountORCA.sh"
fi
mkdir -p "${IIGS}/ORCA"
chmod 777 "${IIGS}/ORCA"
if [[ ! -e "${IIGS}/hfsDrive.img" ]]; then
echo ""
tBoldBox tPURPLE "Creating HFS Volume"
echo ""
O=${IIGS}/mountORCA.sh
echo "#!/bin/bash" > "${O}"
echo "IIGS=${IIGS}" >> "${O}"
echo "if ! mount | grep \${IIGS}/ORCA | grep -q hfsplus; then" >> "${O}"
echo -e "\tfsck.hfsplus \${IIGS}/hfsDrive.img" >> "${O}"
echo -e "\tIIGSDISK=\$(sudo losetup --partscan --find --show \${IIGS}/hfsDrive.img)" >> "${O}"
echo -e "\tsudo mount \${IIGSDISK} \${IIGS}/ORCA" >> "${O}"
echo -e "\techo LOOP=\${IIGSDISK} > \${IIGS}/lastMount.cfg" >> "${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 "\tsudo losetup -d \${LOOP}" >> "${O}"
echo -e "\tsudo rm \${IIGS}/lastMount.cfg" >> "${O}"
echo "fi" >> "${O}"
chmod +x "${O}"
fallocate -l 32M "${IIGS}/hfsDrive.img"
mkfs.hfs -v IIgs "${IIGS}/hfsDrive.img"
fi
"${IIGS}/mountORCA.sh"
sudo chown ${G_UID}:${G_GID} "${IIGS}/ORCA/."
if [[ ! -e "${IIGS}/ORCA/Languages/cc" ]]; then
tFileBrowser ORCA "Please locate your 'OPUS ][ The Software' ISO" .iso ..
if [[ -z ${ORCA} || "${ORCA}" == "" ]]; then
return 0
fi
fi
echo ""
tBoldBox tCYAN "NOTE: If an error is encountered, installer will exit!"
if [[ ! -d GoldenGate ]]; then
tFileBrowser GGATE "Please locate your 'Golden Gate' MSI" .msi ..
if [[ -z ${GGATE} || "${GGATE}" == "" ]]; then
return 0
fi
echo ""
tBoldBox tPURPLE "Building GoldenGate"
echo ""
git clone git@gitlab.com:GoldenGate/GoldenGate.git
if [ ! -d GoldenGate ]; then
tBoldBox tRED "Unable to clone the GoldenGate repository!"
echo "Must be a paying member of the GoldenGate project!"
echo "See: https://goldengate.gitlab.io/about/"
exit 1
fi
pushd GoldenGate &> /dev/null
git submodule init
git submodule update
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$(pwd)/installed ..
make
make install
if [[ ! -e bin/iix ]]; then
tBoldBox tRED "Failed to build GoldenGate."
exit 1
fi
cp -f bin/{iix,dumpobj,opus-extractor} "${IIGS}/."
cd installed
msiextract "${GGATE}"
find -name ".*" -delete
cp -rf GoldenGate/* "${IIGS}/ORCA/."
popd &> /dev/null
fi
if [[ ! -e "${IIGS}/ORCA/Languages/cc" ]]; then
echo ""
tBoldBox tPURPLE "Installing ORCA/C"
echo ""
isoinfo -i "${ORCA}" -x /FOR_EMUL/BYTEWORK.S\;1 > BYTEWORKS
"${IIGS}/opus-extractor" -v BYTEWORKS "${IIGS}/ORCA"
echo ""
tBoldBox tPURPLE "Upgrading ORCA/C"
echo ""
fetchGitHubRelease RESULT byteworksinc ORCA-C 2mg
"${IIGS}/opus-extractor" -v -s / ${RESULT} "${IIGS}/ORCA"
pushd ${GOLDEN_GATE} &> /dev/null
#find . -type d -exec chmod 755 {} \;
#find . -type f -exec chmod 644 {} \;
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 &> /dev/null
fi
if [[ ! -d gsplus ]]; then
echo ""
tBoldBox tPURPLE "Building GSplus"
echo ""
git clone https://github.com/digarok/gsplus.git
mkdir gsplus/build
pushd gsplus/build &> /dev/null
cmake ..
make
if [[ ! -e bin/GSplus ]]; then
tBoldBox tRED "Failed to build GSplus."
exit 1
fi
mkdir -p "${IIGS}/gsplus"
cp -f bin/{GSplus,partls,to_pro} "${IIGS}/gsplus/."
popd &> /dev/null
echo -e "s7d1 = System601.po\n\ng_limit_speed = 0\n" > "${IIGS}/gsplus/config.txt"
echo -e "s7d1 = System601.po\ns7d2 = /tmp/IIgs/import.po\n" > "${IIGS}/gsplus/IIgsTest.cfg"
fi
if [[ ! -f "${IIGS}/gsplus/ROM.03" ]]; then
echo ""
tBoldBox tPURPLE "Installing IIgs ROM"
echo ""
if [[ -e rom3.zip ]]; then
rm -f rom3.zip
fi
wget http://www.whatisthe2gs.apple2.org.za/files/rom3.zip
unzip rom3.zip
mv -f APPLE2GS.ROM2 "${IIGS}/gsplus/ROM.03"
fi
if [[ ! -f "${IIGS}/gsplus/System601.po" ]]; then
echo ""
tBoldBox tPURPLE "Installing GS/OS"
echo ""
if [[ -e harddrive_image.zip ]]; then
rm -f harddrive_image.zip
fi
wget http://www.whatisthe2gs.apple2.org.za/files/harddrive_image.zip
unzip harddrive_image.zip
mv -f "System 6 and Free Games.hdv" "${IIGS}/gsplus/System601.po"
fi
if [[ ! -d cadius ]]; then
echo ""
tBoldBox tPURPLE "Building Cadius"
echo ""
git clone https://github.com/mach-kernel/cadius.git
pushd cadius &> /dev/null
make
if [[ ! -e bin/release/cadius ]]; then
tBoldBox tRED "Failed to build Cadius."
exit 1
fi
mkdir -p "${IIGS}/cadius"
cp -f bin/release/cadius "${IIGS}/cadius/."
popd &> /dev/null
fi
if [[ ! -e "${IIGS}/ntconverter/ntconverter.php" ]]; then
echo ""
tBoldBox tPURPLE "Installing NinjaTracker Converter"
echo ""
if [[ -e ntconverter.zip ]]; then
rm -f ntconverter.zip
fi
wget https://www.ninjaforce.com/downloads/ntconverter.zip
unzip ntconverter.zip
mkdir -p "${IIGS}/ntconverter"
cp -f ntconverter.php "${IIGS}/ntconverter/."
fi
mkdir -p "${JOEY}/dist/IIgs"
if [[ ! -e "${JOEY}/dist/IIgs/Tool221#ba0000" ]]; then
echo ""
tBoldBox tPURPLE "Installing Tool221"
echo ""
if [[ -e ninjatracker_tool221_v2.1.2mg ]]; then
rm -f ninjatracker_tool221_v2.1.2mg
fi
wget https://www.brutaldeluxe.fr/products/apple2gs/tool221/ninjatracker_tool221_v2.1.2mg
"${IIGS}/cadius/cadius" extractfile ninjatracker_tool221_v2.1.2mg NT.TOOL221.V2.1/SYSTEM/TOOLS/TOOL221 .
cp -f TOOL221#BA0000 "${JOEY}/dist/IIgs/Tool221#ba0000"
fi
echo ""
tBoldBox tPURPLE "Building JoeyLib"
echo ""
O=${IIGS}/ORCA/out/joey
if [[ -d "${O}" ]]; then
rm -rf "${O}"
fi
mkdir -p "${O}"
pushd "${JOEY}/joeylib/joeylib/src" &> /dev/null
iix assemble +L jIIgs.asm keep=31:/out/joey/jIIgsasm > jIIgs.asm.dis
iix compile jIIgs.c keep=31:/out/joey/jIIgsc
iix compile joey.c keep=31:/out/joey/joey
iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsasm.A
iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsasm.ROOT
iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsc.a
iix makelib 31:/out/joey/joeylib +31:/out/joey/joey.a
popd &> /dev/null
cp -f "${O}/joeylib" "${JOEY}/dist/IIgs/joeylib#b20000"
cp -f "${JOEY}/joeylib/joeylib/src/joey.h" "${JOEY}/dist/."
cp -f "${JOEY}/joeylib/scripts/build-IIgs.helper.sh" "${JOEY}/dist/."
"${IIGS}/unmountORCA.sh"
if [[ ! -e "${IIGS}/hfsDrive.img.backup.tar.bz2" ]]; then
tar cjf "${IIGS}/hfsDrive.img.backup.tar.bz2" "${IIGS}/hfsDrive.img"
fi
}
function installLinux32() {
buildPCDeps \
"$(pwd)/../dist/linux/i386" \
"$(pwd)/deps/installed/linux/i386" \
"x86_64-linux-gnu" \
"x86_64-linux-gnu-gcc -m32" \
"x86_64-linux-gnu-g++ -m32"
}
function installLinux64() {
buildPCDeps \
"$(pwd)/../dist/linux/x64" \
"$(pwd)/deps/installed/linux/x64" \
"x86_64-linux-gnu" \
"x86_64-linux-gnu-gcc" \
"x86_64-linux-gnu-g++"
}
function installWin32() {
buildPCDeps \
"$(pwd)/../dist/windows/i386" \
"$(pwd)/deps/installed/windows/i386" \
"i686-w64-mingw32" \
"i686-w64-mingw32-gcc -static-libgcc" \
""
}
function installWin64() {
buildPCDeps \
"$(pwd)/../dist/windows/x64" \
"$(pwd)/deps/installed/windows/x64" \
"x86_64-w64-mingw32" \
"x86_64-w64-mingw32-gcc -static-libgcc" \
"x86_64-w64-mingw32-g++ -static-libstdc++"
}
function mainMenu() {
local ITEMS=(
"IIgs"
# "Amiga" "ST"
"Linux32" "Linux64"
"Win32" "Win64"
# "macOS32" "macOS64"
# "Android" "iOS"
)
local DESC=(
"Apple IIgs 16"
# "Commodore Amiga 16" "Atari ST 16"
"Linux 32" "Linux 64"
"Windows 32" "Windows 64"
# "macOS 32" "macOS 64"
# "Android 32" "iOS 64"
)
local TOTAL=${#ITEMS[*]}
local MENU=()
local X=
local CHOICE="x"
while [[ "${CHOICE}" != "" ]]; do
MENU=()
for (( X=0; X<=$(( ${TOTAL}-1 )); X++ )); do
MENU+=( "${ITEMS[$X]}" )
MENU+=( "Install ${DESC[$X]} Bit JoeyLib Library" )
done
CHOICE=$(
set e+
whiptail --title "${G_TITLE}" --cancel-button "Exit" --menu "" $(( ${TOTAL}+7 )) 65 ${TOTAL} "${MENU[@]}" 3>&2 2>&1 1>&3
set e-
)
if [[ "${CHOICE}" != "" ]]; then
sudo -v
CHOICE="install${CHOICE}"
${CHOICE}
fi
done
}
# --- START
mkdir -p installerWork
# Do we have Towel yet?
if [[ ! -f installerWork/towel/towel.sh ]]; then
# Do we have GIT?
if [[ "$(which git || true)" == "" ]]; then
echo "Installing git..."
sudo apt-get -y install git &> /dev/null
fi
echo "Downloading towel.sh support library..."
git clone https://skunkworks.kangaroopunch.com/skunkworks/towel.git installerWork/towel &> /dev/null
fi
# Load Towel
source installerWork/towel/towel.sh
# Remember where we live.
G_PARENT=$(pwd)
# Don't change directories until Towel is loaded.
pushd installerWork &> /dev/null
:<<'SKIP'
# See if all the packages we need are installed
echo ""
tBoldBox tBLUE "Examining system..."
tCheckPackages MISSING cmake ragel hfsplus hfsutils hfsprogs libreadline-dev libedit-dev \
build-essential git mercurial texinfo libtool autoconf automake re2c \
gcc-multilib g++-multilib mingw-w64 gdb-mingw-w64 clang llvm-dev libxml2-dev \
uuid-dev libssl-dev bash patch make tar xz-utils bzip2 gzip sed cpio \
libpulse-dev{,:i386} libasound-dev{,:i386} \
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libfreetype6-dev libpcap0.8-dev \
php-cli msitools
if [[ "${MISSING}" != "" ]]; then
sudo -v
if (whiptail --title "${G_TITLE}" --yesno "Some required packages are missing.\n\nInstall them now?" 9 40); then
TEMP=" ${MISSING//[^ ]}"
TOTAL=${#TEMP}
COUNT=0
{
for PACKAGE in ${MISSING}; do
PERCENT=$(( 100*(++COUNT)/TOTAL ))
echo ${PERCENT}
sudo apt-get -y install ${PACKAGE} &> /dev/null
done
} | whiptail --title "${G_TITLE}" --gauge "\nInstalling packages..." 7 50 0
else
tBoldBox tRED "Canceled!"
echo ""
echo "Installation cannot continue without the following pacakges:"
echo ""
echo ${MISSING}
echo ""
exit 1
fi
fi
SKIP
# Do we have JoeyLib yet?
if [[ ! -f ${G_PARENT}/joeylib/LICENSE ]]; then
echo ""
tBoldBox tBLUE "Downloading JoeyLib source..."
git clone https://skunkworks.kangaroopunch.com/skunkworks/joeylib.git ${G_PARENT}/joeylib &> /dev/null
fi
mainMenu
configWrite
clear
tBoldBox tBLUE "Goodbye!"
echo ""
# --- EXIT
popd &> /dev/null