Improve run-local script

This commit is contained in:
Francesco Abbate 2020-12-26 11:37:43 +01:00
parent 9e8e8f7543
commit 3c285b94bf
1 changed files with 71 additions and 20 deletions

View File

@ -1,33 +1,84 @@
#!/bin/bash #!/bin/bash
set -o errexit
option_portable=off
option_copy=on
pargs=()
while [[ "$#" -gt 0 ]]; do
case $1 in
-portable)
option_portable=on
;;
-keep)
option_copy=off
;;
-global)
option_global=on
;;
-*)
echo "error: unknown option \"$1\""
exit 1
;;
*)
pargs+=("$1")
;;
esac
shift
done
if [ "${#pargs[@]}" -lt 1 ]; then
echo "usage: $0 [options] <build-dir>"
exit 1
fi
if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "mingw"* ]]; then
run_windows=yes
fi
rundir=".run" rundir=".run"
if [ ${1:-x} == "-portable" ]; then if [ "$option_portable" == on ]; then
bindir="$rundir" bindir="$rundir"
datadir="$rundir/data" datadir="$rundir/data"
shift
else else
bindir="$rundir/bin" bindir="$rundir/bin"
datadir="$rundir/share/lite-xl" datadir="$rundir/share/lite-xl"
fi fi
userdir="$(realpath "$rundir")" userdir="$(realpath "$rundir")"
builddir="${pargs[0]}"
if [ "$#" -lt 1 ]; then copy_lite_build () {
echo "usage: $0 <build-dir>" echo "copying lite executable and data"
exit 1 rm -fr "$rundir"
fi mkdir -p "$bindir" "$datadir"
if [ ! -z ${run_windows+x} ]; then
cp "$builddir/src/lite.exe" "$bindir"
else
cp "$builddir/src/lite" "$bindir"
fi
for module_name in core plugins colors fonts; do
cp -r "data/$module_name" "$datadir"
done
}
builddir="$1" run_lite () {
rm -fr "$rundir" if [ ! -z ${option_global+x} ]; then
mkdir -p "$bindir" "$datadir" "$userdir" echo "running \"lite ${pargs[@]:1}\""
if [ -f "$builddir/src/lite" ]; then exec "$bindir/lite" "${pargs[@]:1}"
cp "$builddir/src/lite" "$bindir" else
elif [ -f "$builddir/src/lite.exe" ]; then echo "running \"lite ${pargs[@]:1}\" with local HOME"
cp "$builddir/src/lite.exe" "$bindir" if [ ! -z ${run_windows+x} ]; then
else USERPROFILE="$userdir" exec "$bindir/lite" "${pargs[@]:1}"
echo "error: no lite executable found in $builddir/src" else
exit 1 HOME="$userdir" exec "$bindir/lite" "${pargs[@]:1}"
fi
fi
}
if [ $option_copy == on ]; then
echo "running ninja"
ninja -C "$builddir"
copy_lite_build
fi fi
for module_name in core plugins colors fonts; do run_lite
cp -r "data/$module_name" "$datadir"
done
HOME="$userdir" USERPROFILE="$userdir" exec "$bindir/lite" "${@:2}"