Restruct files, prepare for next feature

This commit is contained in:
2024-08-06 17:14:00 +02:00
parent 7cec02f649
commit 3cc104e08e
9 changed files with 44 additions and 36 deletions

View File

@@ -3,8 +3,8 @@
# 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 " --install Install the automation backend"
echo " --uninstall Uninstall the automation backend"
echo " --update Update the installation"
echo " --help Show this help message"
exit 0
@@ -22,9 +22,10 @@ case $key in
UPDATE=true
;;
--help)
echo "Usage: $0 [--install|--uninstall|--help]"
echo " --install Install the poo recorder"
echo " --uninstall Uninstall the poo recorder"
echo "Usage: $0 [--install|--uninstall|--update|--help]"
echo " --install Install the automation backend"
echo " --uninstall Uninstall the automation backend"
echo " --update Update the installation"
echo " --help Show this help message"
exit 0
;;
@@ -34,68 +35,69 @@ case $key in
;;
esac
TARGET_DIR="$HOME/.local/poo-recorder"
TARGET_DIR="$HOME/.local/home-automation-backend"
SUPERVISOR_CFG_NAME="home_automation_backend"
SUPERVISOR_CFG="$SUPERVISOR_CFG_NAME.conf"
BASEDIR=$(dirname "$0")
# Install or uninstall based on arguments
install_poo_recorder() {
install_backend() {
# Installation code here
echo "Installing..."
sudo apt update
sudo apt install python3 python3-venv supervisor
sudo supervisorctl stop poo_recorder_backend
sudo supervisorctl stop $SUPERVISOR_CFG_NAME
mkdir -p $TARGET_DIR
rm -rf $BASEDIR/../recorder/__pycache__
cp -r $BASEDIR/../recorder $BASEDIR/../requirements.txt $TARGET_DIR
rm -rf `find $BASEDIR/../src -type d -name __pycache__`
cp -r $BASEDIR/../src $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
cp $BASEDIR/"$SUPERVISOR_CFG_NAME"_template.conf $BASEDIR/$SUPERVISOR_CFG
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
sed -i "s+command=+command=$TARGET_DIR/venv/bin/fastapi run $TARGET_DIR/src/main.py --port 8881+g" $BASEDIR/$SUPERVISOR_CFG
sed -i "s+directory=+directory=$TARGET_DIR+g" $BASEDIR/$SUPERVISOR_CFG
sed -i "s+user=+user=$USER+g" $BASEDIR/$SUPERVISOR_CFG
sed -i "s+group=+group=$USER+g" $BASEDIR/$SUPERVISOR_CFG
sudo mv $BASEDIR/poo_recorder.conf /etc/supervisor/conf.d/poo_recorder.conf
sudo mv $BASEDIR/$SUPERVISOR_CFG /etc/supervisor/conf.d/$SUPERVISOR_CFG
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start poo_recorder_backend
sudo supervisorctl start $SUPERVISOR_CFG_NAME
echo "Installation complete."
}
uninstall_poo_recorder() {
uninstall_backend() {
# Uninstallation code here
echo "Uninstalling..."
sudo supervisorctl stop poo_recorder_backend
sudo supervisorctl stop $SUPERVISOR_CFG_NAME
sudo supervisorctl remove poo_recorder_backend
sudo supervisorctl remove $SUPERVISOR_CFG_NAME
sudo rm /etc/supervisor/conf.d/poo_recorder.conf
sudo rm /etc/supervisor/conf.d/$SUPERVISOR_CFG
rm -rf $TARGET_DIR
echo "Uninstallation complete."
}
update_poo_recorder() {
uninstall_poo_recorder
install_poo_recorder
update_backend() {
uninstall_backend
install_backend
}
if [[ $INSTALL ]]; then
install_poo_recorder
install_backend
elif [[ $UNINSTALL ]]; then
uninstall_poo_recorder
uninstall_backend
elif [[ $UPDATE ]]; then
update_poo_recorder
update_backend
else
echo "Invalid argument: $key"
exit 1