-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathupdate_wii_sd.sh
executable file
·222 lines (197 loc) · 6.17 KB
/
update_wii_sd.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#! /bin/bash
################################################################################
# update_wii_sd.sh - Update the Wii SD card
# Creation : 04 Jan 2014
# Time-stamp: <Sam 2014-01-04 14:02 svarrette>
#
# Copyright (c) 2014 Sebastien Varrette <[email protected]>
# http://varrette.gforge.uni.lu
# $Id$
#
# Description : see the print_help function or launch 'update_wii_sd.sh --help'
#
# 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/>.
################################################################################
### Global variables
VERSION=0.1
COMMAND=`basename $0`
VERBOSE=""
DEBUG=""
SIMULATION=""
### displayed colors
COLOR_GREEN="\033[0;32m"
COLOR_RED="\033[0;31m"
COLOR_YELLOW="\033[0;33m"
COLOR_VIOLET="\033[0;35m"
COLOR_CYAN="\033[0;36m"
COLOR_BOLD="\033[1m"
COLOR_BACK="\033[0m"
### Local variables
STARTDIR="$(pwd)"
SCRIPTFILENAME=$(basename $0)
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#BENCH_DATADIR="${SCRIPTDIR}/data/`date +14-Jan-Sat Jan 4 2014`"
SD_DIR="/Volumes/WII_SD"
SRC="${SCRIPTDIR}/SD_content"
RSYNC="rsync"
RSYNC_OPT="-avz --delete --exclude 'src*'"
#######################
### print functions ###
#######################
####
# print version of this program
##
print_version() {
cat <<EOF
This is $COMMAND version "$VERSION".
Copyright (c) 2014 Sebastien Varrette (http://varrette.gforge.uni.lu)
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
}
####
# print help
##
print_help() {
cat <<EOF
NAME
$COMMAND --
SYNOPSIS
$COMMAND [-V | -h]
$COMMAND [--debug] [-v] [-n]
DESCRIPTION
$COMMAND
OPTIONS
--debug
Debug mode. Causes $COMMAND to print debugging messages.
-h --help
Display a help screen and quit.
-n --dry-run
Simulation mode.
-v --verbose
Verbose mode.
-V --version
Display the version number then quit.
AUTHOR
Sebastien Varrette <[email protected]>
Web page: http://varrette.gforge.uni.lu
REPORTING BUGS
Please report bugs to <[email protected]>
COPYRIGHT
This is free software; see the source for copying conditions. There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
SEE ALSO
Other scripts are available on my web site http://varrette.gforge.uni.lu
EOF
}
######
# Print information in the following form: '[$2] $1' ($2=INFO if not submitted)
# usage: info text [title]
##
info() {
[ -z "$1" ] && print_error_and_exit "[$FUNCNAME] missing text argument"
local text=$1
local title=$2
# add default title if not submitted but don't print anything
[ -n "$text" ] && text="${title:==>} $text"
echo -e $text
}
debug() { [ -n "$DEBUG" ] && info "$1" "[${COLOR_YELLOW}DEBUG${COLOR_BACK}]"; }
verbose() { [ -n "$VERBOSE" ] && info "$1"; }
error() { info "$1" "[${COLOR_RED}ERROR${COLOR_BACK}]"; }
warning() { info "$1" "[${COLOR_VIOLET}WARNING${COLOR_BACK}]"; }
print_error_and_exit() {
local text=$1
[ -z "$1" ] && text=" Bad format"
error "$text. '$COMMAND -h' for help."
exit 1
}
#####
# print the strings [ OK ] or [ FAILED ] or [ FAILED ]\n$1
##
print_ok() { echo -e "[ ${COLOR_GREEN}OK${COLOR_BACK} ]"; }
print_failed() { echo -e "[ ${COLOR_RED}FAILED${COLOR_BACK} ]"; }
print_failed_and_exit() {
print_failed
[ ! -z "$1" ] && echo "$1"
exit 1
}
#########################
### toolbox functions ###
#########################
#####
# execute a local command
# usage: execute command
###
execute() {
[ $# -eq 0 ] && print_error_and_exit "[$FUNCNAME] missing command argument"
debug "[$FUNCNAME] $*"
[ -n "${SIMULATION}" ] && echo "(simulation) $*" || eval $*
local exit_status=$?
debug "[$FUNCNAME] exit status: $exit_status"
return $exit_status
}
####
# ask to continue. exit 1 if the answer is no
# usage: really_continue text
##
really_continue() {
echo -e -n "[${COLOR_VIOLET}WARNING${COLOR_BACK}] $1 Are you sure you want to continue? [Y|n] "
read ans
case $ans in
n*|N*) exit 1;;
esac
}
#####
# Check availability of binaries passed as arguments on the current system
# usage: check_bin prog1 prog2 ...
##
check_bin() {
[ $# -eq 0 ] && print_error_and_exit "[$FUNCNAME] missing argument"
for appl in $*; do
echo -n -e "=> checking availability of the command '$appl' on your system \t"
local tmp=`which $appl`
[ -z "$tmp" ] && print_failed_and_exit "Please install $appl or check \$PATH." || print_ok
done
}
################################################################################
################################################################################
#[ $UID -gt 0 ] && print_error_and_exit "You must be root to execute this script (current uid: $UID)"
# Check for required argument
#[ $# -eq 0 ] && print_error_and_exit
check_bin rsync
# Check for options
while [ $# -ge 1 ]; do
case $1 in
-h | --help) print_help; exit 0;;
-V | --version) print_version; exit 0;;
--debug)
DEBUG="--debug";
VERBOSE="--verbose";;
-v | --verbose) VERBOSE="--verbose";;
-n | --dry-run) SIMULATION="--dry-run";;
--sd | -o) shift; SD_DIR="$1";;
--apps) SYNC_ONLY="apps"
esac
shift
done
debug "Debug mode activated"
verbose "Verbose mode activated"
if [ -d "${SD_DIR}" ]; then
[ -z "${SYNC_ONLY}" ] && srcdir="${SRC}" || srcdir="${SRC}/${SYNC_ONLY}"
execute "time ${RSYNC} ${RSYNC_OPT} ${srcdir}/ ${SD_DIR}/"
else
echo "the SD card ${SD_DIR} is not mounted"
fi