diff --git a/helper/install.sh b/helper/install.sh index 194b3b9..79f3aed 100755 --- a/helper/install.sh +++ b/helper/install.sh @@ -1,11 +1,90 @@ #!/usr/bin/bash +# Argument parsing +if [[ $# -ne 1 ]]; then + echo "Usage: $0 [--install|--uninstall|--help]" + echo " --install Install the poo recorder" + echo " --uninstall Uninstall the poo recorder" + echo " --help Show this help message" + exit 0 +fi + +key="$1" +case $key in + --install) + INSTALL=true + ;; + --uninstall) + UNINSTALL=true + ;; + --help) + echo "Usage: $0 [--install|--uninstall|--help]" + echo " --install Install the poo recorder" + echo " --uninstall Uninstall the poo recorder" + echo " --help Show this help message" + exit 0 + ;; + *) + echo "Invalid argument: $key" + exit 1 + ;; +esac + TARGET_DIR="$HOME/.local/poo-recorder" +BASEDIR=$(dirname "$0") -mkdir -p $TARGET_DIR +# Install or uninstall based on arguments +install_poo_recorder() { + # Installation code here + echo "Installing..." -cp ../main.py ../poo.py ../requirements.txt $TARGET_DIR + sudo apt update + sudo apt install python3 python3-venv supervisor -python -m venv "$TARGET_DIR/venv" + sudo supervisorctl stop poo_recorder_backend -$TARGET_DIR/venv/bin/pip install -r $TARGET_DIR/requirements.txt + mkdir -p $TARGET_DIR + + cp $BASEDIR/../main.py $BASEDIR/../poo.py $BASEDIR/../requirements.txt $TARGET_DIR + + python3 -m venv "$TARGET_DIR/venv" + + $TARGET_DIR/venv/bin/pip install -r $TARGET_DIR/requirements.txt + + cp $BASEDIR/poo_recorder_template.conf $BASEDIR/poo_recorder.conf + + sed -i "s+command=+command=$TARGET_DIR/venv/bin/fastapi run $TARGET_DIR/main.py --port 8881+g" poo_recorder.conf + sed -i "s+directory=+directory=$TARGET_DIR+g" poo_recorder.conf + sed -i "s+group=+group=$USER+g" poo_recorder.conf + + sudo mv $BASEDIR/poo_recorder.conf /etc/supervisor/conf.d/poo_recorder.conf + + sudo supervisorctl reread + sudo supervisorctl update + sudo supervisorctl start poo_recorder_backend + + echo "Installation complete." +} +uninstall_poo_recorder() { + # Uninstallation code here + echo "Uninstalling..." + + sudo supervisorctl stop poo_recorder_backend + + sudo supervisorctl remove poo_recorder_backend + + sudo rm /etc/supervisor/conf.d/poo_recorder.conf + + rm -rf $TARGET_DIR + + echo "Uninstallation complete." +} + +if [[ $INSTALL ]]; then + install_poo_recorder +elif [[ $UNINSTALL ]]; then + uninstall_poo_recorder +else + echo "Invalid argument: $key" + exit 1 +fi \ No newline at end of file diff --git a/helper/poo_recorder.conf b/helper/poo_recorder_template.conf similarity index 100% rename from helper/poo_recorder.conf rename to helper/poo_recorder_template.conf