diff --git a/install.sh b/install.sh index a551732ad..27b7d9f03 100755 --- a/install.sh +++ b/install.sh @@ -80,7 +80,6 @@ function check_download { if [ ! -d "${FRIX_CONFIG_PATH}" ]; then echo "[DOWNLOAD] Downloading Klippain repository..." if git -C $frixtemppath clone -b $frixbranchname https://github.com/Frix-x/klippain.git $frixreponame; then - chmod +x ${FRIX_CONFIG_PATH}/install.sh printf "[DOWNLOAD] Download complete!\n\n" else echo "[ERROR] Download of Klippain git repository failed!" @@ -94,6 +93,11 @@ function check_download { # Step 3: Backup the old Klipper configuration function backup_config { + if [ ! -e "${USER_CONFIG_PATH}" ]; then + printf "[BACKUP] No previous config found, skipping backup...\n\n" + return 0 + fi + mkdir -p ${BACKUP_DIR} # Copy every files from the user config ("2>/dev/null || :" allow it to fail silentely in case the config dir doesn't exist) @@ -104,7 +108,7 @@ function backup_config { # If Klippain is not already installed (we check for .VERSION in the backup to detect it), # we need to remove, wipe and clean the current user config folder... if [ ! -f "${BACKUP_DIR}/.VERSION" ]; then - rm -R ${USER_CONFIG_PATH} + rm -fR ${USER_CONFIG_PATH} fi printf "[BACKUP] Backup of current user config files done in: ${BACKUP_DIR}\n\n" diff --git a/uninstall.sh b/uninstall.sh index 71d543575..378e251ea 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -82,6 +82,11 @@ function delete_current_klippain { function restore_latest_backup { local restore_backup latest_backup + if [[ ! -e "${BACKUP_PATH}" ]]; then + printf "[RESTORE] No backup folder found! Skipping...\n\n" + return + fi + read < /dev/tty -rp "[RESTORE] Would you like to restore your last config backup? This script will look for the last one before running Klippain (Y/n) " restore_backup if [[ -z "$restore_backup" ]]; then restore_backup="y" @@ -94,7 +99,7 @@ function restore_latest_backup { return fi - latest_backup=$(find ${BACKUP_PATH} -type d -not -path "${BACKUP_PATH}" -exec sh -c 'if [ ! -f "$1/.VERSION" ]; then echo "$1"; fi' sh {} \; | sort -r | head -n 1) + latest_backup=$(find ${BACKUP_PATH} -maxdepth 1 -type d -not -path "${BACKUP_PATH}" -exec sh -c 'if [ ! -f "$1/.VERSION" ]; then echo "$1"; fi' sh {} \; | sort -r | head -n 1) if [ -n "${latest_backup}" ]; then cp -fa ${latest_backup}/. ${USER_CONFIG_PATH} 2>/dev/null || : printf "[RESTORE] Latest backup restored from: ${latest_backup}\n\n"