Add severity level to log function
This commit is contained in:
parent
064edc95b9
commit
1d6b20161d
23
replicate.sh
23
replicate.sh
@ -9,7 +9,12 @@
|
|||||||
## Helper functions
|
## Helper functions
|
||||||
log() {
|
log() {
|
||||||
[ -z ${1+x} ] && return 1
|
[ -z ${1+x} ] && return 1
|
||||||
printf "\e[94m${name}\e[0m: $1\n"
|
out=1
|
||||||
|
[ -z ${2+x} ] || out="$2"
|
||||||
|
col_message="\e[39m"
|
||||||
|
[ "$out" -gt "1" ] && col_message="\e[31m"
|
||||||
|
[ "$out" -lt "1" ] && out=1 && col_message="\e[37m"
|
||||||
|
printf "\e[94m${name}\e[0m: $col_message$1\e[0m\n" >&${out}
|
||||||
}
|
}
|
||||||
validatedep() {
|
validatedep() {
|
||||||
if ! which $1 > /dev/null 2>&1; then
|
if ! which $1 > /dev/null 2>&1; then
|
||||||
@ -45,7 +50,7 @@ step_validate_deps() {
|
|||||||
log "Validating dependencies"
|
log "Validating dependencies"
|
||||||
for dep in $deps; do
|
for dep in $deps; do
|
||||||
if ! validatedep "$dep"; then
|
if ! validatedep "$dep"; then
|
||||||
log "Could not find critical dependency \"$dep\""
|
log "Could not find critical dependency \"$dep\"" 2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -54,7 +59,7 @@ step_make_skeleton() {
|
|||||||
# Build Home folder skeleton
|
# Build Home folder skeleton
|
||||||
log "Building skeleton folder layout"
|
log "Building skeleton folder layout"
|
||||||
if ! mkdir Desktop Documents Downloads Games Music Pictures Projects Public ROMs System Templates Videos > /dev/null 2>&1; then
|
if ! mkdir Desktop Documents Downloads Games Music Pictures Projects Public ROMs System Templates Videos > /dev/null 2>&1; then
|
||||||
log "Failed to build skeleton layout"
|
log "Failed to build skeleton layout" 2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
@ -65,7 +70,7 @@ step_repo_clone() {
|
|||||||
git clone --recursive --depth 100 --separate-git-dir="$gitdir" "$repo" "$tmpdir" >> "$logfile" 2>&1
|
git clone --recursive --depth 100 --separate-git-dir="$gitdir" "$repo" "$tmpdir" >> "$logfile" 2>&1
|
||||||
error="$?"
|
error="$?"
|
||||||
if ! [ "$error" -eq "0" ]; then
|
if ! [ "$error" -eq "0" ]; then
|
||||||
log "Failed cloning repository \"$repo\": git returned $error"
|
log "Failed cloning repository \"$repo\": git returned $error" 2
|
||||||
log "See $logfile for details"
|
log "See $logfile for details"
|
||||||
log "Do you have the appropriate permissions? Does the remote host know your key?"
|
log "Do you have the appropriate permissions? Does the remote host know your key?"
|
||||||
return 1
|
return 1
|
||||||
@ -75,7 +80,7 @@ step_repo_move() {
|
|||||||
# Move them to where they should be
|
# Move them to where they should be
|
||||||
log "Moving cloned repo from \"$tmpdir\" into \"$bootstrapdir\""
|
log "Moving cloned repo from \"$tmpdir\" into \"$bootstrapdir\""
|
||||||
if ! rsync -rvl --exclude ".git" "$tmpdir/" "$bootstrapdir/" >> "$logfile"; then
|
if ! rsync -rvl --exclude ".git" "$tmpdir/" "$bootstrapdir/" >> "$logfile"; then
|
||||||
log "Failed to move from temp directory to bootstrap directory"
|
log "Failed to move from temp directory to bootstrap directory" 2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -100,21 +105,21 @@ main() {
|
|||||||
case $opt in
|
case $opt in
|
||||||
d)
|
d)
|
||||||
if [ "$OPTARG" == "" ]; then
|
if [ "$OPTARG" == "" ]; then
|
||||||
log "Option -d requires an argument"
|
log "Option -d requires an argument" 2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
bootstrapdir="$OPTARG"
|
bootstrapdir="$OPTARG"
|
||||||
;;
|
;;
|
||||||
r)
|
r)
|
||||||
if [ "$OPTARG" == "" ]; then
|
if [ "$OPTARG" == "" ]; then
|
||||||
log "Option -r requires an argument"
|
log "Option -r requires an argument" 2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
repo="$OPTARG"
|
repo="$OPTARG"
|
||||||
;;
|
;;
|
||||||
l)
|
l)
|
||||||
if [ "$OPTARG" == "" ]; then
|
if [ "$OPTARG" == "" ]; then
|
||||||
log "Option -l requires an argument"
|
log "Option -l requires an argument" 2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
logfile="$OPTARG"
|
logfile="$OPTARG"
|
||||||
@ -123,7 +128,7 @@ main() {
|
|||||||
help
|
help
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
log "Invalid option: \"$opt\""
|
log "Invalid option: \"$opt\"" 2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user