Handle corner case scenarios in easyinstall when compilation of rascsi failed (#502)

* Backup rascsi.service AFTER compilation to avoid disabling the service when compilation fails

* Rename constant to match naming convention

* Introduce SYSTEMD_PATH global constant

* Rename constant to match naming convention

* Change method of checking for existing systemd services, to handle a corner case scenario where the service previously existed but the .service file had been removed unexpectedly
This commit is contained in:
Daniel Markstedt 2021-12-02 17:18:45 -08:00 committed by GitHub
parent d4f30a4e34
commit 267625d1e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,7 +50,8 @@ USER=$(whoami)
BASE=$(dirname "$(readlink -f "${0}")") BASE=$(dirname "$(readlink -f "${0}")")
VIRTUAL_DRIVER_PATH="$HOME/images" VIRTUAL_DRIVER_PATH="$HOME/images"
CFG_PATH="$HOME/.config/rascsi" CFG_PATH="$HOME/.config/rascsi"
WEBINSTDIR="$BASE/src/web" WEB_INSTALL_PATH="$BASE/src/web"
SYSTEMD_PATH="/etc/systemd/system"
HFS_FORMAT=/usr/bin/hformat HFS_FORMAT=/usr/bin/hformat
HFDISK_BIN=/usr/bin/hfdisk HFDISK_BIN=/usr/bin/hfdisk
LIDO_DRIVER=$BASE/lido-driver.img LIDO_DRIVER=$BASE/lido-driver.img
@ -100,12 +101,12 @@ function installRaScsi() {
# install everything required to run an HTTP server (Nginx + Python Flask App) # install everything required to run an HTTP server (Nginx + Python Flask App)
function installRaScsiWebInterface() { function installRaScsiWebInterface() {
if [ -f "$WEBINSTDIR/rascsi_interface_pb2.py" ]; then if [ -f "$WEB_INSTALL_PATH/rascsi_interface_pb2.py" ]; then
sudo rm "$WEBINSTDIR/rascsi_interface_pb2.py" sudo rm "$WEB_INSTALL_PATH/rascsi_interface_pb2.py"
echo "Deleting old Python protobuf library rascsi_interface_pb2.py" echo "Deleting old Python protobuf library rascsi_interface_pb2.py"
fi fi
echo "Compiling the Python protobuf library rascsi_interface_pb2.py..." echo "Compiling the Python protobuf library rascsi_interface_pb2.py..."
protoc -I="$BASE/src/raspberrypi/" --python_out="$WEBINSTDIR" rascsi_interface.proto protoc -I="$BASE/src/raspberrypi/" --python_out="$WEB_INSTALL_PATH" rascsi_interface.proto
sudo cp -f "$BASE/src/web/service-infra/nginx-default.conf" /etc/nginx/sites-available/default sudo cp -f "$BASE/src/web/service-infra/nginx-default.conf" /etc/nginx/sites-available/default
sudo cp -f "$BASE/src/web/service-infra/502.html" /var/www/html/502.html sudo cp -f "$BASE/src/web/service-infra/502.html" /var/www/html/502.html
@ -182,9 +183,9 @@ function installRaScsiScreen() {
fi fi
echo "Installing the monitor_rascsi.service configuration..." echo "Installing the monitor_rascsi.service configuration..."
sudo cp -f "$BASE/src/oled_monitor/monitor_rascsi.service" /etc/systemd/system/monitor_rascsi.service sudo cp -f "$BASE/src/oled_monitor/monitor_rascsi.service" "$SYSTEMD_PATH/monitor_rascsi.service"
sudo sed -i /^ExecStart=/d /etc/systemd/system/monitor_rascsi.service sudo sed -i /^ExecStart=/d "$SYSTEMD_PATH/monitor_rascsi.service"
sudo sed -i "8 i ExecStart=$BASE/src/oled_monitor/start.sh --rotation=$ROTATION --height=$SCREEN_HEIGHT" /etc/systemd/system/monitor_rascsi.service sudo sed -i "8 i ExecStart=$BASE/src/oled_monitor/start.sh --rotation=$ROTATION --height=$SCREEN_HEIGHT" "$SYSTEMD_PATH/monitor_rascsi.service"
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable monitor_rascsi sudo systemctl enable monitor_rascsi
@ -262,8 +263,8 @@ function updateRaScsiGit() {
# Takes a backup copy of the rascsi.service file if it exists # Takes a backup copy of the rascsi.service file if it exists
function backupRaScsiService() { function backupRaScsiService() {
if [ -f /etc/systemd/system/rascsi.service ]; then if [ -f "$SYSTEMD_PATH/rascsi.service" ]; then
sudo mv /etc/systemd/system/rascsi.service /etc/systemd/system/rascsi.service.old sudo mv "$SYSTEMD_PATH/rascsi.service" "$SYSTEMD_PATH/rascsi.service.old"
SYSTEMD_BACKUP=true SYSTEMD_BACKUP=true
echo "Existing version of rascsi.service detected; Backing up to rascsi.service.old" echo "Existing version of rascsi.service detected; Backing up to rascsi.service.old"
else else
@ -273,7 +274,7 @@ function backupRaScsiService() {
# Modifies and installs the rascsi service # Modifies and installs the rascsi service
function enableRaScsiService() { function enableRaScsiService() {
sudo sed -i "s@^ExecStart.*@& -F $VIRTUAL_DRIVER_PATH@" /etc/systemd/system/rascsi.service sudo sed -i "s@^ExecStart.*@& -F $VIRTUAL_DRIVER_PATH@" "$SYSTEMD_PATH/rascsi.service"
echo "Configured rascsi.service to use $VIRTUAL_DRIVER_PATH as default image dir." echo "Configured rascsi.service to use $VIRTUAL_DRIVER_PATH as default image dir."
sudo systemctl daemon-reload sudo systemctl daemon-reload
@ -286,9 +287,9 @@ function enableRaScsiService() {
# Modifies and installs the rascsi-web service # Modifies and installs the rascsi-web service
function installWebInterfaceService() { function installWebInterfaceService() {
echo "Installing the rascsi-web.service configuration..." echo "Installing the rascsi-web.service configuration..."
sudo cp -f "$BASE/src/web/service-infra/rascsi-web.service" /etc/systemd/system/rascsi-web.service sudo cp -f "$BASE/src/web/service-infra/rascsi-web.service" "$SYSTEMD_PATH/rascsi-web.service"
sudo sed -i /^ExecStart=/d /etc/systemd/system/rascsi-web.service sudo sed -i /^ExecStart=/d "$SYSTEMD_PATH/rascsi-web.service"
sudo sed -i "8 i ExecStart=$WEBINSTDIR/start.sh" /etc/systemd/system/rascsi-web.service sudo sed -i "8 i ExecStart=$WEB_INSTALL_PATH/start.sh" "$SYSTEMD_PATH/rascsi-web.service"
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable rascsi-web sudo systemctl enable rascsi-web
@ -297,28 +298,28 @@ function installWebInterfaceService() {
# Stops the rascsi service if it is running # Stops the rascsi service if it is running
function stopRaScsi() { function stopRaScsi() {
if [[ `systemctl list-units | grep -c rascsi.service` -ge 1 ]]; then if [ -f "$SYSTEMD_PATH/rascsi.service" ]; then
sudo systemctl stop rascsi.service sudo systemctl stop rascsi.service
fi fi
} }
# Stops the rascsi-web service if it is running # Stops the rascsi-web service if it is running
function stopRaScsiWeb() { function stopRaScsiWeb() {
if [[ `systemctl list-units | grep -c rascsi-web.service` -ge 1 ]]; then if [ -f "$SYSTEMD_PATH/rascsi-web.service" ]; then
sudo systemctl stop rascsi-web.service sudo systemctl stop rascsi-web.service
fi fi
} }
# Stops the monitor_rascsi service if it is running # Stops the monitor_rascsi service if it is running
function stopRaScsiScreen() { function stopRaScsiScreen() {
if [[ `systemctl list-units | grep -c monitor_rascsi.service` -ge 1 ]]; then if [ -f "$SYSTEMD_PATH/monitor_rascsi.service" ]; then
sudo systemctl stop monitor_rascsi.service sudo systemctl stop monitor_rascsi.service
fi fi
} }
# Starts the monitor_rascsi service if installed # Starts the monitor_rascsi service if installed
function startRaScsiScreen() { function startRaScsiScreen() {
if [[ -f "/etc/systemd/system/monitor_rascsi.service" ]]; then if [ -f "$SYSTEMD_PATH/monitor_rascsi.service" ]; then
sudo systemctl start monitor_rascsi.service sudo systemctl start monitor_rascsi.service
showRaScsiScreenStatus showRaScsiScreenStatus
fi fi
@ -665,18 +666,18 @@ function installMacproxy {
( sudo apt-get update && sudo apt-get install python3 python3-venv --assume-yes ) </dev/null ( sudo apt-get update && sudo apt-get install python3 python3-venv --assume-yes ) </dev/null
MACPROXY_VER="21.11" MACPROXY_VER="21.11"
MACPROXY_DIR="$HOME/macproxy-$MACPROXY_VER" MACPROXY_PATH="$HOME/macproxy-$MACPROXY_VER"
if [ -d "$MACPROXY_DIR" ]; then if [ -d "$MACPROXY_PATH" ]; then
echo "The $MACPROXY_DIR directory already exists. Delete it to proceed with the installation." echo "The $MACPROXY_PATH directory already exists. Delete it to proceed with the installation."
exit 1 exit 1
fi fi
cd "$HOME" || exit 1 cd "$HOME" || exit 1
wget -O "macproxy-$MACPROXY_VER.tar.gz" "https://github.com/rdmark/macproxy/archive/refs/tags/v$MACPROXY_VER.tar.gz" </dev/null wget -O "macproxy-$MACPROXY_VER.tar.gz" "https://github.com/rdmark/macproxy/archive/refs/tags/v$MACPROXY_VER.tar.gz" </dev/null
tar -xzvf "macproxy-$MACPROXY_VER.tar.gz" tar -xzvf "macproxy-$MACPROXY_VER.tar.gz"
cd "$MACPROXY_DIR" || exit 1 cd "$MACPROXY_PATH" || exit 1
sudo cp "$MACPROXY_DIR/macproxy.service" /etc/systemd/system/ sudo cp "$MACPROXY_PATH/macproxy.service" "$SYSTEMD_PATH"
sudo sed -i /^ExecStart=/d /etc/systemd/system/macproxy.service sudo sed -i /^ExecStart=/d "$SYSTEMD_PATH/macproxy.service"
sudo sed -i "8 i ExecStart=$MACPROXY_DIR/start.sh" /etc/systemd/system/macproxy.service sudo sed -i "8 i ExecStart=$MACPROXY_PATH/start.sh" "$SYSTEMD_PATH/macproxy.service"
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable macproxy sudo systemctl enable macproxy
sudo systemctl start macproxy sudo systemctl start macproxy
@ -691,9 +692,9 @@ function installMacproxy {
# Prints a notification if the rascsi.service file was backed up # Prints a notification if the rascsi.service file was backed up
function notifyBackup { function notifyBackup {
if $SYSTEMD_BACKUP; then if "$SYSTEMD_BACKUP"; then
echo "" echo ""
echo "IMPORTANT: /etc/systemd/system/rascsi.service has been overwritten." echo "IMPORTANT: $SYSTEMD_PATH/rascsi.service has been overwritten."
echo "A backup copy was saved as rascsi.service.old in the same directory." echo "A backup copy was saved as rascsi.service.old in the same directory."
echo "Please inspect the backup file and restore configurations that are important to your setup." echo "Please inspect the backup file and restore configurations that are important to your setup."
echo "" echo ""
@ -723,7 +724,7 @@ function runChoice() {
echo "This script will make the following changes to your system:" echo "This script will make the following changes to your system:"
echo "- Install additional packages with apt-get" echo "- Install additional packages with apt-get"
echo "- Add and modify systemd services" echo "- Add and modify systemd services"
echo "- Modify and enable Apache2 and Nginx web service" echo "- Modify and enable Apache2 and Nginx web services"
echo "- Create directories and change permissions" echo "- Create directories and change permissions"
echo "- Modify user groups and permissions" echo "- Modify user groups and permissions"
echo "- Install binaries to /usr/local/bin" echo "- Install binaries to /usr/local/bin"
@ -736,8 +737,8 @@ function runChoice() {
installPackages installPackages
stopRaScsiScreen stopRaScsiScreen
stopRaScsi stopRaScsi
backupRaScsiService
compileRaScsi compileRaScsi
backupRaScsiService
installRaScsi installRaScsi
enableRaScsiService enableRaScsiService
startRaScsiScreen startRaScsiScreen
@ -763,8 +764,8 @@ function runChoice() {
installPackages installPackages
stopRaScsiScreen stopRaScsiScreen
stopRaScsi stopRaScsi
backupRaScsiService
compileRaScsi compileRaScsi
backupRaScsiService
installRaScsi installRaScsi
enableRaScsiService enableRaScsiService
startRaScsiScreen startRaScsiScreen