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
This commit is contained in:
Daniel Markstedt 2021-09-28 10:56:14 -07:00 committed by GitHub
parent bfdaec6c15
commit 7e456b76bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 2 deletions

View File

@ -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)