You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
334 lines
10 KiB
334 lines
10 KiB
2 years ago
|
#!/bin/sh
|
||
2 years ago
|
usage(){
|
||
|
>&2 cat<<END
|
||
|
|
||
|
|
||
|
lmk-run
|
||
|
-------
|
||
|
This script is part of <https://github.com/poikilos/EnlivenMinetest>.
|
||
2 years ago
|
|
||
|
Does all of the following
|
||
|
- Gets and unzips linux-minetest-kit.zip if possible if there is no
|
||
|
linux-minetest-kit in the current working directory.
|
||
|
- Compile libraries if there is no linux-minetest-kit/toolstree.
|
||
|
- Compile minetest if there is no exe matching the specified options.
|
||
|
|
||
2 years ago
|
This script requires that the game is in linux-minetest-kit/minetest/games
|
||
|
that has the gameid matching the one in the world (same goes for
|
||
|
any of the automatically checked world paths). However, trying to
|
||
|
download bucket_game will occur automatically.
|
||
|
|
||
|
Available games in linux-minetest-kit/minetest/games:
|
||
|
`ls linux-minetest-kit/minetest/games`
|
||
|
(end of list)
|
||
|
|
||
|
Available worlds in linux-minetest-kit/minetest/worlds:
|
||
|
`ls linux-minetest-kit/minetest/worlds`
|
||
|
(end of list)
|
||
|
|
||
|
These lists may change if the script proceeds further if an error has occurred.
|
||
|
|
||
2 years ago
|
Suggested setup for a user in the sudo group:
|
||
|
'''
|
||
|
chgrp sudo /opt
|
||
2 years ago
|
# continue to Further setup
|
||
2 years ago
|
'''
|
||
|
|
||
|
Suggested setup for minebest user:
|
||
|
'''
|
||
|
chgrp minebest /opt
|
||
2 years ago
|
# continue to Further setup
|
||
2 years ago
|
'''
|
||
|
|
||
|
Further setup:
|
||
|
'''
|
||
|
chmod g+w /opt
|
||
|
cd /opt
|
||
|
ln -s ~/git/EnlivenMinetest/utilities/lmk-run
|
||
|
ln -s ~/git/EnlivenMinetest/utilities/get-lmk.sh
|
||
|
ln -s ~/git/EnlivenMinetest/utilities/fix-lmk-permissions.sh
|
||
|
'''
|
||
|
|
||
|
Examples:
|
||
2 years ago
|
lmk-run classic client ~/minetest/worlds/center
|
||
|
# ^ creates classic client and opens the world ~/minetest/worlds/center
|
||
2 years ago
|
|
||
|
|
||
2 years ago
|
|
||
2 years ago
|
lmk-run classic server
|
||
|
# ^ creates minetestserver
|
||
|
|
||
|
lmk-run finetest server
|
||
|
# ^ creates finetestserver
|
||
|
|
||
|
lmk-run trolltest server
|
||
|
# ^ creates trolltestserver
|
||
|
|
||
|
lmk-run classic client
|
||
|
# ^ creates minetest
|
||
|
|
||
|
lmk-run finetest client
|
||
|
# ^ creates finetest
|
||
|
|
||
|
lmk-run trolltest client
|
||
|
# ^ creates trolltest
|
||
|
|
||
2 years ago
|
|
||
|
|
||
2 years ago
|
END
|
||
|
}
|
||
|
if [ "x$1" = "x--help" ]; then
|
||
|
usage
|
||
|
exit 0
|
||
|
fi
|
||
|
PREV_DIR="`pwd`"
|
||
2 years ago
|
if [ "x$1" != "x" ]; then
|
||
|
LMK_MODE="$1"
|
||
|
fi
|
||
|
if [ "x$LMK_MODE" = "x" ]; then
|
||
2 years ago
|
usage
|
||
|
>&2 echo "[lmk-run] Error: (or LMK_MODE in environment). It should be classic, finetest, or trolltest."
|
||
|
exit 1
|
||
|
fi
|
||
|
_RAW_APP="$APP"
|
||
|
EXE_NAME=
|
||
|
|
||
2 years ago
|
OTHER_EXE_NAME=
|
||
2 years ago
|
if [ "x$LMK_MODE" = "xclassic" ]; then
|
||
|
EXE_NAME="minetest"
|
||
|
elif [ "x$LMK_MODE" = "xfinetest" ]; then
|
||
|
EXE_NAME="finetest"
|
||
|
elif [ "x$LMK_MODE" = "xtrolltest" ]; then
|
||
|
EXE_NAME="trolltest"
|
||
|
fi
|
||
|
|
||
|
if [ "x$2" != "x" ]; then
|
||
|
APP="$2"
|
||
|
echo "[lmk-run] set APP to $2"
|
||
|
fi
|
||
|
|
||
|
APP_ARG=
|
||
|
if [ "x$APP" = "xclient" ]; then
|
||
|
APP_ARG="--client"
|
||
2 years ago
|
OTHER_EXE_NAME="${EXE_NAME}server"
|
||
2 years ago
|
elif [ "x$APP" = "xserver" ]; then
|
||
|
APP_ARG="--server"
|
||
2 years ago
|
OTHER_EXE_NAME="$EXE_NAME"
|
||
2 years ago
|
EXE_NAME="${EXE_NAME}server"
|
||
|
else
|
||
|
usage
|
||
|
echo "[lmk-run] Error: You must specify client or server after mode (APP=$APP, \$2=$2)."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
echo "[lmk-run] building $EXE_NAME, or running if already exists"
|
||
|
if [ "x$APP" = "x" ]; then
|
||
|
usage
|
||
|
>&2 echo "[lmk-run] Error: specify client or server after the mode."
|
||
2 years ago
|
exit 1
|
||
|
fi
|
||
2 years ago
|
|
||
|
|
||
|
|
||
2 years ago
|
if [ ! -d "linux-minetest-kit" ]; then
|
||
2 years ago
|
echo "[lmk-run] Running ./get-lmk.sh since there is no linux-minetest-kit directory in `pwd`..."
|
||
|
./get-lmk.sh
|
||
|
code=$?
|
||
2 years ago
|
if [ $code -ne 0 ]; then
|
||
|
echo "[lmk-run] ./get-lmk.sh failed with code $code"
|
||
|
exit $code
|
||
|
fi
|
||
2 years ago
|
fi
|
||
|
cd linux-minetest-kit
|
||
|
if [ $? -ne 0 ]; then
|
||
|
>&2 echo "[lmk-run] Error: cd linux-minetest-kit failed in `pwd`. Try running: ./get-lmk.sh"
|
||
|
exit 1
|
||
|
fi
|
||
2 years ago
|
LMK_DIR=`pwd`
|
||
2 years ago
|
if [ ! -f "mtcompile-program.pl" ]; then
|
||
|
>&2 echo "[lmk-run] Error: missing mtcompile-program.pl in `pwd`"
|
||
2 years ago
|
exit 1
|
||
|
fi
|
||
2 years ago
|
$PRE_CMD="sudo -u minebest"
|
||
|
$PRE_CMD ls > /dev/null
|
||
|
if [ $? -ne 0 ]; then
|
||
|
PRE_CMD=""
|
||
|
>&2 echo "[lmk-run] Warning: running as $USER since 'sudo -u minebest' failed."
|
||
|
fi
|
||
|
if [ ! -d toolstree ]; then
|
||
|
$PRE_CMD bash -e mtcompile-libraries.sh build
|
||
|
if [ $? -ne 0 ]; then
|
||
|
>&2 echo "[lmk-run] Error: '$PRE_CMD bash -e mtcompile-libraries.sh' failed in `pwd`."
|
||
|
exit 1
|
||
|
fi
|
||
|
else
|
||
|
echo "[lmk-run] using existing toolstree in `pwd`"
|
||
|
fi
|
||
|
|
||
|
if [ ! -f minetest/bin/$EXE_NAME ]; then
|
||
2 years ago
|
if [ -d minetest ]; then
|
||
|
OLD_MODE=
|
||
2 years ago
|
OLD_EXE_NAME=
|
||
2 years ago
|
if [ -f minetest/bin/finetestserver ]; then
|
||
|
OLD_MODE=finetest
|
||
2 years ago
|
OLD_EXE_NAME=finetestserver
|
||
2 years ago
|
elif [ -f minetest/bin/finetest ]; then
|
||
|
OLD_MODE=finetest
|
||
2 years ago
|
OLD_EXE_NAME=finetest
|
||
2 years ago
|
elif [ -f minetest/bin/minetestserver ]; then
|
||
|
OLD_MODE=minetest
|
||
2 years ago
|
OLD_EXE_NAME=minetestserver
|
||
2 years ago
|
elif [ -f minetest/bin/minetest ]; then
|
||
|
OLD_MODE=minetest
|
||
2 years ago
|
OLD_EXE_NAME=minetest
|
||
2 years ago
|
elif [ -f minetest/bin/trolltestserver ]; then
|
||
|
OLD_MODE=trolltest
|
||
2 years ago
|
OLD_EXE_NAME=trolltestserver
|
||
2 years ago
|
elif [ -f minetest/bin/trolltest ]; then
|
||
|
OLD_MODE=trolltest
|
||
2 years ago
|
OLD_EXE_NAME=trolltest
|
||
2 years ago
|
else
|
||
|
>&2 echo "[lmk-run] Error: mode couldn't be detected for the old minetest directory, so it will become minetest-. Its bin dir contains: `ls minetest/bin` one of the following was expected: minetest minetestserver finetest finetestserver trolltest trolltestserver"
|
||
|
fi
|
||
2 years ago
|
if [ ! -d minetest-$OLD_EXE_NAME ]; then
|
||
|
mv minetest minetest-$OLD_EXE_NAME
|
||
2 years ago
|
else
|
||
2 years ago
|
if [ ! -d minetest-$EXE_NAME/games/bucket_game ]; then
|
||
2 years ago
|
if [ -d minetest/games/bucket_game ]; then
|
||
2 years ago
|
mkdir -p minetest-$EXE_NAME/games/
|
||
|
echo "[lmk-run] mv minetest/games/bucket_game minetest-$EXE_NAME/games/"
|
||
|
mv minetest/games/bucket_game minetest-$EXE_NAME/games/
|
||
2 years ago
|
else
|
||
|
echo "[lmk-run] There is no minetest/games/bucket_game to back up."
|
||
|
fi
|
||
|
else
|
||
2 years ago
|
echo "[lmk-run] There is already a backup minetest-$EXE_NAME/games/bucket_game"
|
||
2 years ago
|
fi
|
||
|
echo "[lmk-run] removing `pwd`/minetest!"
|
||
|
rm -rf minetest
|
||
|
fi
|
||
|
fi
|
||
2 years ago
|
if [ -f minetest-$EXE_NAME/bin/$EXE_NAME ]; then
|
||
|
echo "[lmk-run] reusing minetest-$EXE_NAME..."
|
||
|
mv minetest-$EXE_NAME minetest
|
||
2 years ago
|
else
|
||
2 years ago
|
echo "[lmk-run] there is no file minetest-$EXE_NAME/bin/$EXE_NAME so compiling to minetest/bin..."
|
||
2 years ago
|
$PRE_CMD perl mtcompile-program.pl build --$LMK_MODE $APP_ARG --safe
|
||
2 years ago
|
# if [ -f "minetest-$EXE_NAME/bin/$OTHER_EXE_NAME" ]; then
|
||
|
# echo "[lmk-run] mv minetest-$EXE_NAME/bin/$OTHER_EXE_NAME minetest/bin/"
|
||
|
# mv "minetest-$EXE_NAME/bin/$OTHER_EXE_NAME" "minetest/bin/"
|
||
|
# fi
|
||
2 years ago
|
fi
|
||
|
if [ ! -d minetest/games/bucket_game ]; then
|
||
2 years ago
|
if [ -d minetest-$EXE_NAME/games/bucket_game ]; then
|
||
2 years ago
|
mkdir -p minetest/games/
|
||
2 years ago
|
echo "[lmk-run] rsync -rt minetest-$EXE_NAME/games/bucket_game/ minetest/games/bucket_game"
|
||
|
rsync -rt minetest-$EXE_NAME/games/bucket_game/ minetest/games/bucket_game
|
||
2 years ago
|
if [ $? -ne 0 ]; then
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
fi
|
||
|
# --safe: Don't delete existing source trees automatically.
|
||
|
# --noclean: If --noclean is specified, this script tries to reuse
|
||
|
# the existing source tree, if there is one, and doesn't
|
||
|
# deleted "build" files afterward. The "--git*" and "--debug"
|
||
|
# switches imply this switch. Aliases: --notidy
|
||
|
|
||
2 years ago
|
code=$?
|
||
|
if [ $code -ne 0 ]; then
|
||
2 years ago
|
extra_msg=""
|
||
|
if [ -f "minetest/bin/$EXE_NAME" ]; then
|
||
|
extra_msg=", but minetest/bin/$EXE_NAME exists, so you can probably run lmk-run again and it will probably run (after syncing to the tmp world as usual)."
|
||
|
fi
|
||
2 years ago
|
>&2 echo "[lmk-run] Error: '$PRE_CMD perl mtcompile-program.pl build --$LMK_MODE $APP_ARG --safe' failed in `pwd` with code $code"
|
||
2 years ago
|
exit 1
|
||
|
fi
|
||
|
else
|
||
|
echo "[lmk-run] using existing `pwd`/minetest/bin/$EXE_NAME"
|
||
|
fi
|
||
2 years ago
|
LMK_DIR="`pwd`"
|
||
|
|
||
2 years ago
|
#if "x$APP" = "xserver" ]; then
|
||
|
echo "* Looking for a test world to copy..."
|
||
|
if [ "x$SRC_WORLD" = "x" ]; then
|
||
|
SRC_WORLD="$3"
|
||
|
else
|
||
|
SRC_WORLD=
|
||
|
fi
|
||
|
if [ "x$SRC_WORLD" = "x" ]; then
|
||
|
for dir in ~/minetest-220509/worlds/bg190406 /home/owner/bg190406
|
||
|
do
|
||
|
printf "* checking for \"$dir\"..."
|
||
|
if [ -d $dir ]; then
|
||
|
SRC_WORLD="$dir"
|
||
|
break
|
||
|
fi
|
||
|
done
|
||
|
fi
|
||
|
if [ "x$SRC_WORLD" = "x" ]; then
|
||
2 years ago
|
usage
|
||
2 years ago
|
echo "No known test world was found. Try making a small world first, and specify it as the 3rd parameter or set SRC_WORLD in the environment. Note that the gameid in the file must exist."
|
||
|
exit 1
|
||
|
else
|
||
|
echo "[lmk-run] found $SRC_WORLD to copy"
|
||
|
fi
|
||
|
world_name="`basename $SRC_WORLD`"
|
||
|
mkdir -p ~/tmp
|
||
2 years ago
|
# dst_world="$HOME/tmp/${world_name}-$EXE_NAME"
|
||
|
dst_world="$LMK_DIR/minetest/worlds/${world_name}-$EXE_NAME"
|
||
2 years ago
|
echo "[lmk-run] syncing to $dst_world destructively..."
|
||
2 years ago
|
rsync -rt --delete $SRC_WORLD/ $dst_world
|
||
|
if [ ! -d "$LMK_DIR/minetest/games/bucket_game" ]; then
|
||
2 years ago
|
if [ -d "$LMK_DIR/minetest-$EXE_NAME/games/bucket_game" ]; then
|
||
2 years ago
|
mkdir -p $LMK_DIR/minetest/games/
|
||
2 years ago
|
# echo "[lmk-run] rsync -rt $LMK_DIR/minetest-$EXE_NAME/games/bucket_game/ minetest/games/bucket_game"
|
||
|
echo "[lmk-run] mv $LMK_DIR/minetest-$EXE_NAME/games/bucket_game $LMK_DIR/minetest/games/"
|
||
|
mv $LMK_DIR/minetest-$EXE_NAME/games/bucket_game $LMK_DIR/minetest/games/
|
||
2 years ago
|
if [ $? -ne 0 ]; then
|
||
|
exit 1
|
||
|
fi
|
||
|
else
|
||
|
echo "[lmk-run] Downloading bucket_game as linux-minetest-kit/minetest/games/bucket_game"
|
||
|
cd "$LMK_DIR"
|
||
|
cd minetest/games
|
||
|
if [ $? -ne 0 ]; then
|
||
|
>&2 echo "[lmk-run] 'cd minetest/games' failed in `pwd`."
|
||
|
exit 1
|
||
|
fi
|
||
|
rsync -rt mtio:/opt/minebest/assemble/prod/bucket_game.zip .
|
||
|
if [ $? -ne 0 ]; then
|
||
|
>&2 echo "[lmk-run] 'rsync -rt mtio:/opt/minebest/assemble/prod/bucket_game.zip .' failed in `pwd`."
|
||
|
# TODO: try wget
|
||
|
exit 1
|
||
|
fi
|
||
|
unzip bucket_game.zip
|
||
|
if [ $? -ne 0 ]; then
|
||
|
>&2 echo "[lmk-run] Error: 'unzip bucket_game.zip' failed in `pwd`"
|
||
|
exit 1
|
||
|
fi
|
||
|
if [ ! -d "bucket_game" ]; then
|
||
|
>&2 echo "[lmk-run] Error: 'unzip bucket_game.zip' didn't produce bucket_game in `pwd`"
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
cd "$LMK_DIR"
|
||
|
cd minetest/bin
|
||
2 years ago
|
if [ $? -ne 0 ]; then
|
||
2 years ago
|
PRE_CMD=""
|
||
|
>&2 echo "[lmk-run] 'cd minebest/bin' failed in `pwd`."
|
||
|
fi
|
||
|
|
||
|
if [ $? -ne 0 ]; then
|
||
|
>&2 echo "[lmk-run] 'rsync -rt --delete $SRC_WORLD/ $dst_world' failed in `pwd`."
|
||
|
fi
|
||
|
if [ ! -d "$dst_world" ]; then
|
||
|
>&2 echo "[lmk-run] Error: '$dst_world' doesn't exist."
|
||
2 years ago
|
fi
|
||
|
echo "[lmk-run] running $EXE_NAME --world $dst_world"
|
||
|
./$EXE_NAME --world $dst_world
|
||
|
#else
|
||
|
#fi
|