Skip to content

Commit

Permalink
Merge pull request #1006 from ivan-hc/dev
Browse files Browse the repository at this point in the history
Option "`-b`" or "`backup`", give the name you want to the snapshots
  • Loading branch information
ivan-hc authored Oct 16, 2024
2 parents bc4513d + 03f72c0 commit 0a32219
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="8.3.2"
AMVERSION="8.4"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand Down
34 changes: 30 additions & 4 deletions modules/management.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
##############################################################################################

# BACKUP

function _backup_name() {
printf "\n ◆ To set date and time as a name, press ENTER (default)\n ◆ To set the version as a name, press \"1\"\n ◆ To set a custom name, write anything else\n\n"
read -r -p " Write your choice here, or leave blank to use \"date/time\": " response
case "$response" in
'')
backupname=$(date +%F-%X | sed 's/://g' | sed 's/-//g')
;;
'1')
_check_version
backupname=$(grep -w "$app_name |" "$AMCACHEDIR"/version-args 2>/dev/null | sed 's:.*| ::')
;;
*)
backupname="$(echo "$response" | sed 's/ /_/g')"
;;
esac
}

function _backup() {
if [ ! -f "$APPSPATH"/"$2"/remove ]; then
echo " \"$2\" is not a valid argument or is not installed."
Expand All @@ -16,11 +34,19 @@ function _backup() {
printf "\n OPERATION ABORTED!\n\n"
else
mkdir -p "$HOME/.am-snapshots/$2"
date="$(date +%F-%X | sed 's/://g' | sed 's/-//g')"
cp -r "$APPSPATH"/"$2" "$HOME/.am-snapshots/$2/$date"
echo " SAVED in $HOME/.am-snapshots/$2"
app_name="$2"
_backup_name
if test -d "$HOME/.am-snapshots/$2/$backupname"; then
echo " 💀 ERROR: \"$2/$backupname\" already exists, ABORTED!"
echo "$DIVIDING_LINE"
return 1
else
cp -r "$APPSPATH"/"$2" "$HOME/.am-snapshots/$2/$backupname"
fi
echo " SAVED in $HOME/.am-snapshots/$2/$backupname"
fi
fi
echo "$DIVIDING_LINE"
}

# RESTORE
Expand All @@ -32,7 +58,7 @@ function _overwrite() {
else
read -r -p " Do you wish to overwrite $2 with an older version? (y,N) " yn
if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
printf "\n OPERATION ABORTED!\n\n"
printf "\n OPERATION ABORTED! \n\n"
else
printf "\n Please, select a snapshot or press CTRL+C to abort:\n\n"
sleep 1
Expand Down

0 comments on commit 0a32219

Please sign in to comment.