Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 806663a
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Tue Jul 30 07:41:41 2024 -0400

    Corrected variable name

commit cd010e0
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Tue Jul 30 07:15:51 2024 -0400

    Since verifcation tool is added to install script, conditionally execute from upgrade script

commit 8c6ea4e
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Tue Jul 30 06:38:18 2024 -0400

    Removed /etc/modprobe.d/rtlsdr.conf

commit a5b7821
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 21:24:29 2024 -0400

    Updated to remove reboot dependency and execute Verification Tool

    Verification script had 1 failure after Fresh OS install and install_and_upgrade.sh executed. Reboot would resolve the USB udev permission issue, but reloading udev rules and trigger resolves it without a reboot.  I left the code block to execute verification tool on fresh installs, so it only happens the first time. Users can call Verification Tool anytime the need to such as part of support.sh script.

commit 3c50ae7
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 17:17:12 2024 -0400

    Added error handling and Improved text in echo for moving RN2 tree

commit b375303
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 17:07:59 2024 -0400

    Moved git clone command to start of script

    Moved git clone command to start of script before destructive tasks are performed in case user passed a bad URL or Branch name

commit 5552f61
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 12:03:14 2024 -0400

    Stop and RN2 AT processes that might be running during uninstall

    # kill any RN2 AT processes as part of clean up, otherwise danglers
    # may have the RTL-SDR open and verification dry run test for satdump will fail

commit edd0f4e
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 11:36:23 2024 -0400

    Corrected /srv restore/Unstage permissions

commit 7d91bd1
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 11:18:53 2024 -0400

    Script was renamed to rn2_uninstall.sh and moved to .rn2_utils

commit 8c0c56d
Merge: a007035 bb0d497
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 10:49:02 2024 -0400

    Merge branch 'aarch64-support' of https://github.com/creas002/raspberry-noaa-v2 into aarch64-support

commit a007035
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 10:48:21 2024 -0400

    Added tee -a  for appending to log file

commit bb0d497
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 10:27:38 2024 -0400

    Resolve merge conflict

commit a83fda3
Merge: acb9fc5 3fd34b1
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 10:16:48 2024 -0400

    Merge branch 'aarch64-support' of https://github.com/creas002/raspberry-noaa-v2 into aarch64-support

commit acb9fc5
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 10:14:45 2024 -0400

    Script was rename to rn2_uninstall.sh and moved to .rm2_utils

commit 3fd34b1
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 10:08:22 2024 -0400

    Update README.md - In-Situ Upgrade

commit 4f97fae
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 09:55:59 2024 -0400

    Introduction of In-situ RN2 upgrade

    #          1) Backup/Stage RN2 key directories
    #          2) Uninstall existing RN2 installation
    #          3) git clone new repository
    #          4) Restore/UnStage RN2 key directories
    #          5) install_and_upgrade
    #          6) verification tool

commit b252da5
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Mon Jul 29 09:10:58 2024 -0400

    Fix -  DB Backup directory not cleaned up #1021

commit ad5555d
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Sun Jul 21 11:43:43 2024 -0400

    RTL-SDR changes since it is not a APT installed package

commit d967486
Author: Richard Creasey - AI4Y <[email protected]>
Date:   Sun Jul 21 09:22:53 2024 -0400

    Clean up the library cache so any dangling items are cleared
  • Loading branch information
MihajloPi committed Jul 30, 2024
1 parent b6bddb8 commit f3f998b
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 19 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ Then, open the settings file and edit it to match the settings from the previous
If you have elected to run a TLS-enabled web server, see [THIS LINK](docs/tls_webserver.md) for some additional information
on how to handle self-signed certificates when attempting to visit your webpanel and enabling auth for the admin pages.

## In-Situ Upgrade

Want to switch your existing RN2 installation to a different Github branch without loosing your settings and images?

**Introduction of RN2 Upgrade tool**

`${HOME}/.rn2_utils/rn2_upgrade.sh https://github.com/jekhokie/raspberry-noaa-v2.git -b aarch64-support`

Just point to the branch you want to switch to by modifying the above line as needed.

## Post Install

There are and will be future "optional" features for this framework. Below is a list of optional capabilities that you may wish
Expand Down
381 changes: 381 additions & 0 deletions ansible/roles/common/files/rn2_backup_restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,381 @@
#!/bin/bash
#
# Purpose: Backup or Restore RN2 key directories
#
# (audio, videos, images, db and config)
#
# Author: Richard Creasey (AI4Y)
#
# Created: 28-July-2024
#
#
# Input parameters:
#
# 1. Input mode [backup|backup_stage|restore|restore_stage]
#
# Example:
# ./rn2_backup_restore.sh backup
# ./rn2_backup_restore.sh backup_stage
# ./rn2_backup_restore.sh restore
# ./rn2_backup_restore.sh restore_stage

# input params
MODE=$1

echo ""
if [[ -z ${MODE} ]]; then
echo "Argument required: ./rn2_backup_restore.sh backup or ./rn2_backup_restore.sh backup_stage"
echo " ./rn2_backup_restore.sh restore or ./rn2_backup_restore.sh restore_stage"
echo ""
exit 1
else
vMODE=$(echo ${MODE} | tr '[:upper:]' '[:lower:]')
if [[ ${vMODE} != "backup" && ${vMODE} != "backup_stage" && ${vMODE} != "restore" && ${vMODE} != "restore_stage" ]]; then
echo "Argument required: ./rn2_backup_restore.sh backup or ./rn2_backup_restore.sh backup_stage"
echo " ./rn2_backup_restore.sh restore or ./rn2_backup_restore.sh restore_stage"
echo ""
exit 1
fi
fi

start=$(date +%s)

secs_to_human() {
if [[ -z ${1} || ${1} -lt 60 ]] ;then
min=0 ; secs="${1}"
else
time_mins=$(echo "scale=2; ${1}/60" | bc)
min=$(echo ${time_mins} | cut -d'.' -f1)
secs="0.$(echo ${time_mins} | cut -d'.' -f2)"
secs=$(echo ${secs}*60|bc|awk '{print int($1+0.5)}')
fi
echo "Time Elapsed : ${min} minutes and ${secs} seconds."
}

# Define RN2 Utils location
RN2_UTILS="${HOME}/.rn2_utils"

# Define backup location
BACKUP_LOC="${RN2_UTILS}/backup"

# Make sure backup location exists
mkdir -p ${BACKUP_LOC} ${BACKUP_LOC}/srv

# Define log file for backup/restore activity
LOG="${BACKUP_LOC}/backup_restore.log"

# loggit function
loggit() {
local log_type=$1
local log_message=$2

echo "${log_type} : ${log_message}"

# log output to a log file
echo $(date '+%d-%m-%Y %H:%M') "${log_type} : ${log_message}" >> "$LOG"
}

backup() {

if [[ ${stage} -eq 0 ]]; then
# Making a full copy of /srv/audio, /srv/videos, /srv/ images

if [[ -d /srv ]]; then

srcSIZE=$(du -sm /srv | awk -F" " '{print $1}')
FreeSpace=$(df -m ${BACKUP_LOC} | grep -vi "Filesystem" | awk -F" " '{print $(NF-2)}')

# To ensure stability of the OS and processes, lets make sure we have at least 2GB of free space beyond the minimun needed before making a backup
RequiredSpace=$((${srcSIZE} + 2000))

if [[ ${RequiredSpace} -lt ${FreeSpace} ]]; then
loggit "INFO" "Required space for backup is ${RequiredSpace} MB and Free space is ${FreeSpace} MB, preceeding to backup RN2 key files..."

loggit "INFO" "Backing up /srv/audio, please wait..."
cp -pr /srv/audio ${BACKUP_LOC}/srv/audio
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully backed up /srv/audio"
else
loggit "FAIL" "Failed to backup /srv/audio, aborting..."
exit 1
fi

loggit "INFO" "Backing up /srv/videos, please wait..."
cp -pr /srv/videos ${BACKUP_LOC}/srv/videos
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully backed up /srv/videos"
else
loggit "FAIL" "Failed to backup /srv/videos, aborting..."
exit 1
fi

loggit "INFO" "Backing up /srv/images, please wait..."
cp -pr /srv/images ${BACKUP_LOC}/srv/images
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully backed up /srv/images"
else
loggit "FAIL" "Failed to backup /srv/images, aborting..."
exit 1
fi

else
loggit "FAIL" "Required space for backup is ${RequiredSpace} MB and Free space is only ${FreeSpace} MB, aborting..."
exit 1
fi

else

loggit "INFO" "/srv directory not found, skipping backup..."

fi

else

# Staging /srv so no extra space or time is required
if [[ ! -d /srv_staged ]]; then
loggit "INFO" "Staging /srv as /srv_staged"
sudo mv /srv /srv_staged
else
loggit "FAIL" "/srv_staged already exists, aborting..."
exit 1
fi

fi


if [[ -f ${HOME}/raspberry-noaa-v2/config/settings.yml ]]; then
cp -pr ${HOME}/raspberry-noaa-v2/config/settings.yml ${BACKUP_LOC}/settings.yml
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully backed up settings.yml"
else
loggit "FAIL" "Failed to backup settings.yml, aborting..."
exit 1
fi
else
loggit "FAIL" "${HOME}/raspberry-noaa-v2/config/settings.yml not found, aborting..."
exit
fi

if [[ -f ${HOME}/raspberry-noaa-v2/config/annotation/annotation.html.j2 ]]; then
cp -pr ${HOME}/raspberry-noaa-v2/config/annotation/annotation.html.j2 ${BACKUP_LOC}/annotation.html.j2
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully backed up annotation.html.j2"
else
loggit "FAIL" "Failed to backup annotation.html.j2, aborting..."
exit 1
fi
else
loggit "FAIL" "${HOME}/raspberry-noaa-v2/config/settings.yml, not found, aborting..."
exit
fi

if [[ -f ${HOME}/raspberry-noaa-v2/db/panel.db ]]; then
cp -pr ${HOME}/raspberry-noaa-v2/db/panel.db ${BACKUP_LOC}/panel.db
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully backed up panel.db"
else
loggit "FAIL" "Failed to backup panel.db, aborting..."
exit 1
fi
else
loggit "FAIL" "${HOME}/raspberry-noaa-v2/db/panel.db, not found, aborting..."
exit
fi

}

restore() {


if [[ ${stage} -eq 0 ]]; then
# Restoring a full copy of /srv/audio, /srv/videos, /srv/ images

if [[ -d ${BACKUP_LOC}/srv ]]; then
srcSIZE=$(du -sm ${BACKUP_LOC} | awk -F" " '{print $1}')
FreeSpace=$(df -m /srv | grep -vi "Filesystem" | awk -F" " '{print $(NF-2)}')

# To ensure stability of the OS and processes, lets make sure we have at least 2GB of free space beyond the minimun needed before restoring
RequiredSpace=$((${srcSIZE} + 2000))

if [[ ${RequiredSpace} -lt ${FreeSpace} ]]; then
loggit "INFO" "Required space for restore is ${RequiredSpace} MB and Free space is ${FreeSpace} MB, preceeding to restore RN2 key files..."

loggit "INFO" "Restoring /srv/audio, please wait..."
cp -pr ${BACKUP_LOC}/srv/audio /srv/audio
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully restored /srv/audio"
else
loggit "FAIL" "Failed to restore /srv/audio, aborting..."
exit 1
fi

loggit "INFO" "Restoring /srv/videos, please wait..."
cp -pr ${BACKUP_LOC}/srv/videos /srv/videos
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully restored /srv/videos"
else
loggit "FAIL" "Failed to restore /srv/videos, aborting..."
exit 1
fi

loggit "INFO" "Restoring /srv/images, please wait..."
cp -pr ${BACKUP_LOC}/srv/images /srv/images
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully restored /srv/images"
else
loggit "FAIL" "Failed to restore /srv/images, aborting..."
exit 1
fi

# Ensure previously installed environment has correct ownership/permissions
sudo chown ${USER}:${USER} /srv/audio
sudo chown ${USER}:www-data /srv /srv/images /srv/images/thumb /srv/videos
sudo chmod 755 /srv
sudo chmod 775 /srv/audio /srv/images /srv/images/thumb /srv/videos

else
loggit "FAIL" "Required space for restore is ${RequiredSpace} MB and Free space is only ${FreeSpace} MB, aborting..."
exit 1
fi

else

loggit "INFO" "${BACKUP_LOC}/srv directory not found, skipping restore..."

fi

else

# Restoring /srv_staged as /srv so no extra space or time is required
if [[ -d /srv_staged ]]; then
loggit "INFO" "UnStaging /srv_staged as /srv"
sudo mv /srv_staged /srv
# Ensure previously installed environment has correct ownership/permissions
sudo chown ${USER}:${USER} /srv/audio
sudo chown ${USER}:www-data /srv /srv/images /srv/images/thumb /srv/videos
sudo chmod 755 /srv
sudo chmod 775 /srv/audio /srv/images /srv/images/thumb /srv/videos
else
loggit "FAIL" "/srv_staged does not exist, aborting..."
exit 1
fi

fi


if [[ -f ${BACKUP_LOC}/settings.yml ]]; then
# Keep github original
if [[ ! -f ${HOME}/raspberry-noaa-v2/config/settings.yml.original ]]; then
if [[ -f ${HOME}/raspberry-noaa-v2/config/settings.yml ]]; then
loggit "INFO" "Backing up GitHub settings.yml as settings.yml.original"
cp -pr ${HOME}/raspberry-noaa-v2/config/settings.yml ${HOME}/raspberry-noaa-v2/config/settings.yml.original
fi
fi

# Check for missing parameters from backup settings.yml that exist in latest Github version and merge them in if found
PARMS_REQUIRED=/tmp/parameters_required
PARMS_FOUND=/tmp/parameters_found
NEED_NEWFILE=0
NEWFILE_CREATED=0
NEWFILE=/tmp/settings.yml
COUNT=$(cat ${BACKUP_LOC}/settings.yml | wc -l)
LINE=$((${COUNT} - 1))

# Skip lines starting with # and skip blank lines and list the parameter
cat ${HOME}/raspberry-noaa-v2/config/settings.yml.original | grep -Ev "^#|^---|^\...|^[[:blank:]]*$" | awk -F":" '{print $1}' > /tmp/parameters_required
cat ${BACKUP_LOC}/settings.yml | grep -Ev "^#|^---|^\...|^[[:blank:]]*$" | awk -F":" '{print $1}' > /tmp/parameters_found

# Search for missing parameters and append them to users settings.yml file
while IFS= read -r parm; do
vFOUND=$(grep ${parm} ${PARMS_FOUND} | wc -l)
if [[ ${vFOUND} -eq 0 ]]; then
NEED_NEWFILE=1
if [[ ${NEWFILE_CREATED} -eq 0 ]]; then
NEWFILE_CREATED=1
cat ${BACKUP_LOC}/settings.yml | head -${COUNT} > ${NEWFILE}
echo "" >> ${NEWFILE}
echo "# The following parameters were added" >> ${NEWFILE}
fi
cat ${HOME}/raspberry-noaa-v2/config/settings.yml.original | grep ${parm} >> ${NEWFILE}
fi
done < ${PARMS_REQUIRED}

if [[ ${NEWFILE_CREATED} -eq 1 ]]; then
echo "..." >> ${NEWFILE}
cp -pr ${NEWFILE} ${HOME}/raspberry-noaa-v2/config/settings.yml
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully merged settings.yml"
else
loggit "FAIL" "Failed to merge settings.yml"
fi
else
# No new setting needing to be merged, so lets restore the users original file back
cp -pr ${BACKUP_LOC}/settings.yml ${HOME}/raspberry-noaa-v2/config/settings.yml
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully restored settings.yml"
else
loggit "FAIL" "Failed to restore settings.yml, aborting..."
exit 1
fi
fi

else
loggit "FAIL" "${BACKUP_LOC}/settings.yml not found, aborting..."
exit 1
fi

if [[ -f ${BACKUP_LOC}/annotation.html.j2 ]]; then
# Keep github original
if [[ ! -f ${HOME}/raspberry-noaa-v2/config/annotation/annotation.html.j2.original ]]; then
if [[ -f ${HOME}/raspberry-noaa-v2/config/annotation/annotation.html.j2 ]]; then
cp -pr ${HOME}/raspberry-noaa-v2/config/annotation/annotation.html.j2 ${HOME}/raspberry-noaa-v2/config/annotation/annotation.html.j2.original
fi
fi
cp -pr ${BACKUP_LOC}/annotation.html.j2 ${HOME}/raspberry-noaa-v2/config/annotation/annotation.html.j2
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully restored annotation.html.j2"
else
loggit "FAIL" "Failed to restore annotation.html.j2, aborting..."
exit 1
fi
else
loggit "FAIL" "${BACKUP_LOC}/annotation.html.j2, not found, aborting..."
exit
fi

if [[ -f ${BACKUP_LOC}/panel.db ]]; then
# Keep github original
if [[ ! -f ${HOME}/raspberry-noaa-v2/db/panel.db.original ]]; then
if [[ -f ${HOME}/raspberry-noaa-v2/db/panel.db ]]; then
cp -pr ${HOME}/raspberry-noaa-v2/db/panel.db ${HOME}/raspberry-noaa-v2/db/panel.db.original
fi
fi
cp -pr ${BACKUP_LOC}/panel.db ${HOME}/raspberry-noaa-v2/db/panel.db
if [[ $? -eq 0 ]]; then
loggit "PASS" "Successfully backed up panel.db"
else
loggit "FAIL" "Failed to backup panel.db, aborting..."
exit 1
fi
else
loggit "FAIL" "${HOME}/raspberry-noaa-v2/db/panel.db, not found, aborting..."
exit
fi

}

if [[ ${vMODE} == "backup" ]]; then
stage=0
backup
elif [[ ${vMODE} == "backup_stage" ]]; then
stage=1
backup
elif [[ ${vMODE} == "restore" ]]; then
stage=0
restore
elif [[ ${vMODE} == "restore_stage" ]]; then
stage=1
restore
fi

secs_to_human "$(($(date +%s) - ${start}))"
Loading

0 comments on commit f3f998b

Please sign in to comment.