Skip to content

Commit 9558d51

Browse files
author
Shaun Sundquist
committed
cleaned up script and better arg usage
1 parent 0749000 commit 9558d51

1 file changed

Lines changed: 71 additions & 60 deletions

File tree

auto-gitlab-backup.sh

Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -226,78 +226,89 @@ usage() {
226226
echo ""
227227
}
228228

229+
areWeRoot() {
230+
## test for running as root
231+
if [[ "$UID" -ne "$ROOT_UID" ]];
232+
then
233+
echo "You must run this script as root to run."
234+
if [[ $1 == -d ]] || [[ $1 == --dry-run ]]
235+
then
236+
echo "...even to dryrun as we need to acccess the backup dir."
237+
fi
238+
usage
239+
exit 1
240+
fi
241+
}
242+
243+
confFileExist() {
244+
# read the conffile
245+
if [ -e $confFile -a -r $confFile ]
246+
then
247+
source $confFile
248+
echo "Parsing config file..."
249+
rvm_ENV
250+
else
251+
echo "No confFile found; Remote copy DISABLED."
252+
fi
253+
}
254+
229255
###
230256
## Git'r done
231257
#
232258

233-
## test for running as root
234-
if [[ "$UID" -ne "$ROOT_UID" ]];
235-
then
236-
echo "You must run this script as root to run."
237-
exit 1
238-
fi
239-
240-
241-
# read the conffile
242-
if [ -e $confFile -a -r $confFile ]
243-
then
244-
source $confFile
245-
echo "Parsing config file..."
246-
rvm_ENV
247-
else
248-
echo "No confFile found; Remote copy DISABLED."
249-
fi
250-
251259
case $1 in
252260
-h|--help )
253261
usage
254262
;;
255263
-d|--dry-run )
264+
areWeRoot $1
265+
confFileExist
256266
##test ssh and rsync functions
257-
if [[ $remoteModule != "" ]]
258-
then
259-
rsyncDaemon_dryrun
260-
# no Daemon so lets see if we are using a special key
261-
else if [ -e $sshKeyPath -a -r $sshKeyPath ] && [[ $sshKeyPath != "" ]]
262-
then
263-
rsyncKey_dryrun
264-
sshQuotaKey
265-
else if [[ $remoteServer != "" ]]
266-
then
267-
# use the defualt
268-
rsyncUp_dryrun
269-
sshQuota
270-
fi
271-
fi
272-
fi
273-
267+
if [[ $remoteModule != "" ]]
268+
then
269+
rsyncDaemon_dryrun
270+
# no Daemon so lets see if we are using a special key
271+
else if [ -e $sshKeyPath -a -r $sshKeyPath ] && [[ $sshKeyPath != "" ]]
272+
then
273+
rsyncKey_dryrun
274+
sshQuotaKey
275+
else if [[ $remoteServer != "" ]]
276+
then
277+
# use the defualt
278+
rsyncUp_dryrun
279+
sshQuota
280+
fi
281+
fi
282+
fi
274283
;;
275284
* )
276-
# perform backup
277-
rakeBackup
278-
rakeCIBackup
279-
checkSize
280-
# go back to where we came from
281-
cd $PDIR
282-
# if the $remoteModule is set run rsyncDaemo
283-
## here we assume variables are set right and only check when needed.
284-
if [[ $remoteModule != "" ]]
285-
then
286-
rsyncDaemon
287-
# no Daemon so lets see if we are using a special key
288-
else if [ -e $sshKeyPath -a -r $sshKeyPath ] && [[ $sshKeyPath != "" ]]
289-
then
290-
rsyncKey
291-
sshQuotaKey
292-
else if [[ $remoteServer != "" ]]
293-
then
294-
# use the defualt
295-
rsyncUp
296-
sshQuota
297-
fi
298-
fi
299-
fi
300-
;;
285+
areWeRoot $1
286+
confFileExist
287+
# perform backup
288+
rakeBackup
289+
rakeCIBackup
290+
checkSize
291+
# go back to where we came from
292+
cd $PDIR
293+
# if the $remoteModule is set run rsyncDaemo
294+
## here we assume variables are set right and only check when needed.
295+
if [[ $remoteModule != "" ]]
296+
then
297+
rsyncDaemon
298+
# no Daemon so lets see if we are using a special key
299+
else if [ -e $sshKeyPath -a -r $sshKeyPath ] && [[ $sshKeyPath != "" ]]
300+
then
301+
rsyncKey
302+
sshQuotaKey
303+
else if [[ $remoteServer != "" ]]
304+
then
305+
# use the defualt
306+
syncUp
307+
sshQuota
308+
fi
309+
fi
310+
fi
311+
;;
301312
esac
302313

303314
# Print version

0 commit comments

Comments
 (0)