Updated setup script (chatgpt-aided)

This commit is contained in:
Thord Johansson 2023-07-26 01:48:56 +02:00
parent 9a8a646c53
commit 32b12536de

View File

@ -1,18 +1,54 @@
#!/bin/bash
if [ $1 == "--gentmpl" ]; then
grep "[A-Z_ ]*=" .env -o > env-template.txt
exit 0
elif [ ! -z "$1" ]; then
echo "Unrecognised parameter, use --gentmpl to generate .env template"
exit 1
install_packages_managed() {
packages=("python3-dotenv" "python3-requests" "python3-lxml")
sudo apt install "${packages[@]}"
}
install_packages_unmanaged() {
# General packages
general_packages=("python-dotenv")
# Stasher packages
stasher_packages=("requests" "lxml" "python-dotenv")
pip3 install "${general_packages[@]}"
pip3 install "${stasher_packages[@]}"
}
print_usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " --gentmpl Generate .env template"
echo " --managed Install managed python packages"
echo " --unmanaged Install unmanaged python packages"
}
while getopts ":h" opt; do
case $opt in
h)
print_usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG"
print_usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [[ $1 == "--gentmpl" ]]; then
grep "[A-Z_ ]*=" .env -o > env-template.txt
exit 0
elif [[ $1 == "--managed" ]]; then
install_packages_managed
elif [[ $1 == "--unmanaged" ]]; then
install_packages_unmanaged
else
echo "Unrecognized parameter."
print_usage
exit 1
fi
# Installs prerequisites for some of the system scripts
# Redundant package names are acceptable as this improves readability
# General
python -m pip install python-dotenv
# Stasher
python -m pip install requests lxml python-dotenv