diff --git a/helium_launcher_update.sh b/helium_launcher_update.sh index 8123131..9e1e8b2 100755 --- a/helium_launcher_update.sh +++ b/helium_launcher_update.sh @@ -9,6 +9,7 @@ APP_NAME_LONG="Helium Web Browser" ARCH="x86_64" FILE_EXTENSION="AppImage" APP_SOURCE="GitHub" +NOTIFY_NAME="Helium Helper" SCRIPT_NAME="$APP_NAME Launcher Updater" PARENT_SCRIPT_FILE_NAME="helium_helper.sh" SCRIPT_FILE_NAME="helium_launcher_update.sh" @@ -65,7 +66,7 @@ dependency_check () { if [ -f "$TMP/missingDeps" ] ; then MISSING=$(cat $TMP/missingDeps) echo "$DATE | Failed to update - missing dependencies : $MISSING" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Update failed! See log for details" exit_clean fi @@ -73,24 +74,107 @@ dependency_check () { if ! [ -d "$INSTALL_PATH" ] ; then mkdir -p $INSTALL_PATH echo "$DATE | Failed to update - $APP_NAME installation path not present - But created for logging" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Update failed! See log for details" exit elif ! [ -f "$INSTALL_PATH/$APP_NAME.$FILE_EXTENSION" ] ; then echo "$DATE | Failed to update - Local $APP_NAME AppImage not found" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Update failed! See log for details" exit fi } +### BACKUP +backup_helium() { + if [[ -d "$INSTALL_PATH" || -d "$SCRIPT_PATH" || -d $APP_CONFIG_PATH ]] ; then + BACKUPABLE=("$INSTALL_PATH/$APP_NAME.$FILE_EXTENSION" "$SCRIPT_PATH/$SCRIPT_FILE_NAME" "$SCRIPT_PATH/$AUTO_SCRIPT_FILE_NAME" "$LAUNCHER_PATH/$APP_NAME.desktop" "$APP_CONFIG_PATH") + + for BACKUP_ITEM in ${BACKUPABLE[@]} ; do + if [ -d "$BACKUP_ITEM" ] ; then + mkdir -p $TMP/backup + cp -r $BACKUP_ITEM $TMP/backup + + elif [ -f "$BACKUP_ITEM" ] ; then + mkdir -p $TMP/backup + cp $BACKUP_ITEM $TMP/backup + fi + done + + if [ -d "$TMP/backup" ] ; then + CWD=$(pwd) + cd $TMP/backup + chmod -x *.sh *.$FILE_EXTENSION > /dev/null 2>&1 + + if [ "$BACKUP_COMPRESSION_OVERRIDE" ] ; then + BACKUP_COMPRESSION=$BACKUP_COMPRESSION_OVERRIDE + + elif ! [ "$BACKUP_COMPRESSION_OVERRIDE" ] ; then + COMPRESSION_METHOD=("pbzip2" "gzip" "bzip2" "zip") + + until [ "$BACKUP_COMPRESSION" ] ; do + for COMPRESSION_TYPE in ${COMPRESSION_METHOD[@]} ; do + + if [ "$(command -v $COMPRESSION_TYPE) > /dev/null 2>&1" ] ; then + BACKUP_COMPRESSION=$COMPRESSION_TYPE + break + fi + done + done + fi + + if [ "$BACKUP_COMPRESSION" == "pbzip2" ] ; then + tar -cf $APP_NAME.backup_$DATE.tar * > /dev/null 2>&1 + pbzip2 $APP_NAME.backup_$DATE.tar + mkdir -p $BACKUP_PATH + mv $APP_NAME.backup_$DATE.tar.bz2 $BACKUP_PATH + cd $TMP && rm -rf backup + + elif [ "$BACKUP_COMPRESSION" == "gzip" ] ; then + tar -cf $APP_NAME.backup_$DATE.tar * > /dev/null 2>&1 + gzip $APP_NAME.backup_$DATE.tar + mkdir -p $BACKUP_PATH + mv $APP_NAME.backup_$DATE.tar.gz $BACKUP_PATH + cd $TMP && rm -rf backup + + elif [ "$BACKUP_COMPRESSION" == "bzip2" ] ; then + tar -cf $APP_NAME.backup_$DATE.tar * > /dev/null 2>&1 + bzip2 $APP_NAME.backup_$DATE.tar + mkdir -p $BACKUP_PATH + mv $APP_NAME.backup_$DATE.tar.bz2 $BACKUP_PATH + cd $TMP && rm -rf backup + + elif [ "$BACKUP_COMPRESSION" == "zip" ] ; then + tar -cf $APP_NAME.backup_$DATE.tar * > /dev/null 2>&1 + zip -r $APP_NAME.backup_$DATE.tar.zip $APP_NAME.backup_$DATE.tar > /dev/null 2>&1 + mkdir -p $BACKUP_PATH + mv $APP_NAME.backup_$DATE.tar.zip $BACKUP_PATH + cd $TMP && rm -rf backup + + else + echo "$DATE | Backup - Backup (uncompressed) written to $BACKUP_PATH" >> $LOG + mkdir -p $BACKUP_PATH + mv $TMP/backup $BACKUP_PATH/$APP_NAME.backup_$DATE + cd $TMP && rm -rf backup + fi + + echo "$DATE | Backup - Backup (compressed $BACKUP_COMPRESSION archive) written to $BACKUP_PATH" >> $LOG + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Backup created" + cd $CWD + fi + + else + echo "$DATE | Failed to backup - Nothing worth backing up found" >> $LOG + fi +} + ### UPDATE SCRIPT update_script() { ### CHECK FOR LOCAL SCRIPT if ! [ -f "$SCRIPT_PATH/$SCRIPT_FILE_NAME" ] ; then echo "$DATE | Failed to update script - local file not found" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Script update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Script update failed! See log for details" exit fi @@ -100,12 +184,12 @@ update_script() { ### CHECK FOR EMPTY VERSION TAGS if [ -z "$SCRIPT_VERSION" ] ; then echo "$DATE | Failed to update script - Empty version tag --> local" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Script update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Script update failed! See log for details" exit elif [ -z "$REMOTE_SCRIPT_VERSION" ] ; then echo "$DATE | Failed to update script - Empty version tag --> $APP_SOURCE" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Script update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Script update failed! See log for details" exit fi @@ -115,7 +199,7 @@ update_script() { REMOTE_SCRIPT_VERSION_NUM=$(echo $REMOTE_SCRIPT_VERSION | tr -d .) if [ "$REMOTE_SCRIPT_VERSION" == "$SCRIPT_VERSION" ] ; then - notify-send --icon="$ICON" --app-name="Helium Helper" "Script is up-to-date" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Script is up-to-date" elif [ "$REMOTE_SCRIPT_VERSION_NUM" -gt "$SCRIPT_VERSION_NUM" ] ; then mv $SCRIPT_PATH/$SCRIPT_FILE_NAME $BACKUP_PATH/$SCRIPT_FILE_NAME.old @@ -125,13 +209,13 @@ update_script() { chmod +x $TMP/$SCRIPT_FILE_NAME $TMP/$PARENT_SCRIPT_FILE_NAME mv $TMP/$SCRIPT_FILE_NAME $TMP/$PARENT_SCRIPT_FILE_NAME $SCRIPT_PATH echo "$DATE | Script updated to version $REMOTE_SCRIPT_VERSION" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Script updated to version $REMOTE_SCRIPT_VERSION" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Script updated to version $REMOTE_SCRIPT_VERSION" else echo "$DATE | Failed to update - Malformed version tags" >> $LOG echo "$DATE | Remote Version: $REMOTE_SCRIPT_VERSION" >> $LOG echo "$DATE | Local Version: $SCRIPT_VERSION" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Script update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Script update failed! See log for details" fi } @@ -145,12 +229,12 @@ update_helium() { ### CHECK FOR EMPTY VERSION TAGS if [[ -z "$APP_SOURCE_VERSION" ]] ; then echo "$DATE | Failed to update - Empty version tag --> $APP_SOURCE" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Browser update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Browser update failed! See log for details" exit elif [[ -z "$LOCAL_VERSION" ]] ; then echo "$DATE | Failed to update - Empty version tag --> LOCAL" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Browser update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Browser update failed! See log for details" exit fi @@ -160,32 +244,21 @@ update_helium() { APP_SOURCE_VERSION_NUM=$(echo $APP_SOURCE_VERSION | tr -d .) if [ "$APP_SOURCE_VERSION" == "$LOCAL_VERSION" ] ; then - notify-send --icon="$ICON" --app-name="Helium Helper" "Browser is up-to-date" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Browser is up-to-date" elif [ "$APP_SOURCE_VERSION_NUM" -gt "$LOCAL_VERSION_NUM" ] ; then - mkdir -p $TMP $BACKUP_PATH - wget -P $TMP $DOWNLOAD_URL -q --show-progress + mkdir -p $TMP + wget -P $TMP $DOWNLOAD_URL -q chmod +x $TMP/$APP_SOURCE_FILENAME - if [ -f "$BACKUP_PATH/$APP_NAME.old" ] ; then - rm $BACKUP_PATH/$APP_NAME.old - fi - if [ -d "$APP_CONFIG_PATH" ] ; then - if [ -f "$BACKUP_PATH/$APP_NAME.config_*.tar" ] ; then - rm $BACKUP_PATH/$APP_NAME.config_*.tar - fi - tar -cf $BACKUP_PATH/$APP_NAME.config_$(date).tar $APP_CONFIG_PATH > /dev/null 2>&1 - fi - mv $INSTALL_PATH/$APP_NAME.$FILE_EXTENSION $BACKUP_PATH/$APP_NAME.$FILE_EXTENSION.old + backup_helium mv $TMP/$APP_SOURCE_FILENAME $INSTALL_PATH/$APP_NAME.$FILE_EXTENSION - cp $LAUNCHER_PATH/$APP_NAME.desktop $BACKUP_PATH/$APP_NAME.desktop.old - chmod -x $BACKUP_PATH/*.sh.old $BACKUP_PATH/$APP_NAME.old sed -i "s|X-AppImage-Version=.*|X-AppImage-Version=$($INSTALL_PATH/$APP_NAME.$FILE_EXTENSION --version | awk '{print $2}')|" $LAUNCHER_PATH/$APP_NAME.desktop echo "$DATE | $APP_NAME updated to version ${APP_SOURCE_VERSION}" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Browser updated to version $APP_SOURCE_VERSION" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Browser updated to version $APP_SOURCE_VERSION" else echo "$DATE | Failed to update - Version tags malformed" >> $LOG - notify-send --icon="$ICON" --app-name="Helium Helper" "Browser update failed! See log for details" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "Browser update failed! See log for details" exit fi @@ -204,7 +277,7 @@ show_log() { xdg-open $LOG else - notify-send --icon="$ICON" --app-name="Helium Helper" "No log created yet" + notify-send --icon="$ICON" --app-name="$NOTIFY_NAME" "No log created yet" fi }