102 lines
2.5 KiB
Bash
Executable File
102 lines
2.5 KiB
Bash
Executable File
#!/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 " --update Update the installation"
|
|
echo " --help Show this help message"
|
|
exit 0
|
|
fi
|
|
|
|
key="$1"
|
|
case $key in
|
|
--install)
|
|
INSTALL=true
|
|
;;
|
|
--uninstall)
|
|
UNINSTALL=true
|
|
;;
|
|
--update)
|
|
UPDATE=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")
|
|
|
|
# Install or uninstall based on arguments
|
|
install_poo_recorder() {
|
|
# Installation code here
|
|
echo "Installing..."
|
|
|
|
sudo apt update
|
|
sudo apt install python3 python3-venv supervisor
|
|
|
|
sudo supervisorctl stop poo_recorder_backend
|
|
|
|
mkdir -p $TARGET_DIR
|
|
|
|
rm -rf $BASEDIR/../recorder/__pycache__
|
|
cp -r $BASEDIR/../recorder $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/recorder/main.py --port 8881+g" $BASEDIR/poo_recorder.conf
|
|
sed -i "s+directory=+directory=$TARGET_DIR+g" $BASEDIR/poo_recorder.conf
|
|
sed -i "s+user=+user=$USER+g" $BASEDIR/poo_recorder.conf
|
|
sed -i "s+group=+group=$USER+g" $BASEDIR/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."
|
|
}
|
|
update_poo_recorder() {
|
|
uninstall_poo_recorder
|
|
install_poo_recorder
|
|
}
|
|
|
|
if [[ $INSTALL ]]; then
|
|
install_poo_recorder
|
|
elif [[ $UNINSTALL ]]; then
|
|
uninstall_poo_recorder
|
|
elif [[ $UPDATE ]]; then
|
|
update_poo_recorder
|
|
else
|
|
echo "Invalid argument: $key"
|
|
exit 1
|
|
fi |