-
Notifications
You must be signed in to change notification settings - Fork 0
/
mister-clone.sh
executable file
·88 lines (77 loc) · 3.42 KB
/
mister-clone.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# You can download the latest version of this script from:
# https://github.com/kconger/MiSTer_Backup
today=$(date +%Y%m%d)
freset="\e[0m\033[0m"
fblue="\e[1;34m"
fgreen="\e[1;32m"
fred="\e[1;31m"
fyellow="\e[1;33m"
REPOSITORY_URL="https://raw.githubusercontent.com/kconger/MiSTer_Backup/"
REPO_BRANCH="master"
NODEBUG="-q -o /dev/null"
echo -e "${fyellow}MiSTer Backup Script${freset}";
check4error() {
case "${1}" in
0) ;;
1) echo -e "${fyellow}wget: ${fred}Generic error code.${freset}" ;;
2) echo -e "${fyellow}wget: ${fred}Parse error---for instance, when parsing command-line options, the .wgetrc or .netrc..." ;;
3) echo -e "${fyellow}wget: ${fred}File I/O error.${freset}" ;;
4) echo -e "${fyellow}wget: ${fred}Network failure.${freset}" ;;
5) echo -e "${fyellow}wget: ${fred}SSL verification failure.${freset}" ;;
6) echo -e "${fyellow}wget: ${fred}Username/password authentication failure.${freset}" ;;
7) echo -e "${fyellow}wget: ${fred}Protocol errors.${freset}" ;;
8) echo -e "${fyellow}wget: ${fred}Server issued an error response.${freset}" ;;
*) echo -e "${fred}Unexpected and uncatched error.${freset}" ;;
esac
! [ "${1}" = "0" ] && exit "${1}"
}
# Update the script if neccessary
wget ${NODEBUG} --no-cache "${REPOSITORY_URL}${REPO_BRANCH}/mister-clone.sh" -O /tmp/mister-clone.sh
check4error "${?}"
cmp -s /tmp/mister-clone.sh /media/fat/Scripts/mister-clone.sh
if [ "${?}" -gt "0" ] && [ -s /tmp/mister-clone.sh ]; then
echo -e "${fyellow}Script Updated ${fmagenta}${PICNAME}${freset}"
mv -f /tmp/mister-clone.sh /media/fat/Scripts/mister-clone.sh
exec /media/fat/Scripts/mister-clone.sh
exit 255
else
rm /tmp/mister-clone.sh
fi
# Check for INI file download if neccessary
if [ -e /media/fat/Scripts/mister-backup.ini ]; then
. /media/fat/Scripts/mister-backup.ini
else
wget ${NODEBUG} --no-cache "${REPOSITORY_URL}${REPO_BRANCH}/mister-backup.ini" -O /tmp/mister-backup.ini
check4error "${?}"
mv /tmp/mister-backup.ini /media/fat/Scripts/mister-backup.ini
. /media/fat/Scripts/mister-backup.ini
echo -e "${fyellow}Missing mister-backup.ini installed with default backup location of: ${BACKUP_DESTINATION}${fmagenta}${PICNAME}${freset}"
exit 0
fi
# Run clone
if [ -z "$BACKUP_DESTINATION" ]; then
echo -e "${fred}BACKUP_DESTINATION not set in mister-backup.ini${freset}"
else
read -n1 -p "Clone MiSTer SD to: ${BACKUP_DESTINATION}MiSTer-sd-$today.img? [Y/n] " answer
if [[ $answer =~ ^[Nn]$ ]]; then
echo -e "\n${fred}Clone Canceled${freset}"
elif [[ $answer == $'\e' ]]; then
echo -e "\n${fred}Clone Canceled${freset}"
else
echo -e "\n"
dd if=/dev/mmcblk0 of=$BACKUP_DESTINATION/MiSTer-sd-$today.img bs=1M status=progress
echo -e "\n${fgreen}MiSTer SD cloned to: ${BACKUP_DESTINATION}MiSTer-sd-$today.img${freset}";
fi
fi
exit 0