baz/scripts/baz_setup.sh
Ari Archer 9261bff331
7.1.0-post : improve baz_setup script
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
2023-02-28 23:13:31 +02:00

73 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
export __BASH_RUNAS="${__BASH_RUNAS:-sudo}"
export PREFIX="${PREFIX:-/usr/bin}"
err() {
echo "$1" >&2
exit 1
}
use() {
for dep in "$@"; do
command -v -- "$dep" >/dev/null ||
err "required dependency not satisfied : $dep"
done
}
main() {
echo 'beginning setting up baz'
use git "${__BASH_RUNAS}" install sh bash
echo 'pre-cleanup'
rm -rf -- baz
echo 'cloning git repository'
git clone 'https://ari-web.xyz/gh/baz'
cd baz
if [ ! -x 'baz' ]; then
echo 'making baz executable'
chmod 755 baz
fi
echo 'installing baz'
${__BASH_RUNAS} install -Dm755 baz "$PREFIX"
echo 'setting baz up'
./baz setup
if [ ! "$yn" ]; then
read -rp 'do you want to add loader lines to bashrc ? [y/n] >>> ' yn
fi
if [ "$yn" = 'y' ]; then
use tee
echo 'adding lines to bashrc'
tee -a ~/.bashrc <<EOF
# load baz
export BAZ_LOADER_ENABLED=true
_baz_loader="\$HOME/.local/share/baz/loader.sh"
# shellcheck disable=SC1090
[ ! -f "\$_baz_loader" ] || source "\$_baz_loader"
EOF
fi
echo 'adding completions'
bash ./scripts/comp.sh
echo 'cleaning up'
cd ..
rm -rf -- baz
echo "done setting up baz, make sure '$PREFIX' is in \$PATH"
}
main "$@"