From 7e456b76bf3ffbda0b2db4459b624b70a9fa009c Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Tue, 28 Sep 2021 10:56:14 -0700 Subject: [PATCH] Back up rascsi.service before installing new one (#273) * Back up rascsi.service before installing new one * Error out on errors * Extra notification to user that rascsi.service has been overwritten --- easyinstall.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/easyinstall.sh b/easyinstall.sh index 2de327b6..1a95bfa8 100755 --- a/easyinstall.sh +++ b/easyinstall.sh @@ -53,6 +53,8 @@ LIDO_DRIVER=~/RASCSI/lido-driver.img GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) GIT_REMOTE=${GIT_REMOTE:-origin} +set -e + function initialChecks() { currentUser=$(whoami) if [ "pi" != "$currentUser" ]; then @@ -76,6 +78,14 @@ function installPackages() { function installRaScsi() { sudo systemctl stop rascsi + if [ -f /etc/systemd/system/rascsi.service ]; then + sudo cp /etc/systemd/system/rascsi.service /etc/systemd/system/rascsi.service.old + SYSTEMD_BACKUP=true + echo "Existing version of rascsi.service detected; Backing up to rascsi.service.old" + else + SYSTEMD_BACKUP=false + fi + cd ~/RASCSI/src/raspberrypi make clean make all CONNECT_TYPE=${CONNECT_TYPE-FULLSPEC} @@ -93,6 +103,7 @@ www-data ALL=NOPASSWD: /sbin/shutdown, /sbin/reboot " >> /etc/sudoers' fi + sudo systemctl daemon-reload sudo systemctl restart rsyslog sudo systemctl enable rascsi # optional - start rascsi at boot sudo systemctl start rascsi @@ -100,8 +111,11 @@ www-data ALL=NOPASSWD: /sbin/shutdown, /sbin/reboot # install everything required to run an HTTP server (Nginx + Python Flask App) function installRaScsiWebInterface() { - echo "Compiling the Python protobuf library..." - [ -f ~/RASCSI/src/web/rascsi_interface.proto ] && rm ~/RASCSI/src/web/rascsi_interface.proto + if [ -f ~/RASCSI/src/web/rascsi_interface_pb2.py ]; then + rm ~/RASCSI/src/web/rascsi_interface_pb2.py + echo "Deleting old Python protobuf library rascsi_interface_pb2.py" + fi + echo "Compiling the Python protobuf library rascsi_interface_pb2.py..." protoc -I=/home/pi/RASCSI/src/raspberrypi/ --python_out=/home/pi/RASCSI/src/web/ rascsi_interface.proto sudo cp -f ~/RASCSI/src/web/service-infra/nginx-default.conf /etc/nginx/sites-available/default @@ -418,6 +432,16 @@ function reserveScsiIds() { sudo systemctl start rascsi } +function notifyBackup { + if $SYSTEMD_BACKUP; then + echo "" + echo "IMPORTANT: /etc/systemd/system/rascsi.service has been overwritten." + 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 "" + fi +} + function runChoice() { case $1 in 1) @@ -430,6 +454,7 @@ function runChoice() { installRaScsiWebInterface showRaScsiStatus showRaScsiWebStatus + notifyBackup echo "Installing / Updating RaSCSI Service (${CONNECT_TYPE-FULLSPEC}) + Web interface - Complete!" ;; 2) @@ -439,6 +464,7 @@ function runChoice() { installPackages installRaScsi showRaScsiStatus + notifyBackup echo "Installing / Updating RaSCSI Service (${CONNECT_TYPE-FULLSPEC}) - Complete!" ;; 3)