upload.sh: Code beautification

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2016-12-20 14:11:36 +00:00
commit 424430c35a

View file

@ -106,6 +106,22 @@ EOT
[ -n "$1" ] && exit $1 [ -n "$1" ] && exit $1
} }
log()
{
echo $@
}
err()
{
log $@
}
fatal()
{
err $@
exit 1
}
is_dir() is_dir()
{ {
isdir="`echo $1 | sed 's/.*\/$/yes/'`" isdir="`echo $1 | sed 's/.*\/$/yes/'`"
@ -185,8 +201,7 @@ cat << EOT |
test -n "$4" && chmod "$4" \$path || continue test -n "$4" && chmod "$4" \$path || continue
fi fi
if [ ! -d \$path ]; then if [ ! -d \$path ]; then
echo "failed to create directory \$path, owner=\$file_owner, group=\$file_group, mode=\$dir_mode" fatal "failed to create directory \$path, owner=\$file_owner, group=\$file_group, mode=\$dir_mode"
exit 2
fi fi
done done
EOT EOT
@ -254,8 +269,7 @@ source="`echo $* | cut -d' ' -f1-$n_targets`"
# -- check run # -- check run
for s in $source; do for s in $source; do
if [ ! -d "$s" -a ! -f "$s" -a ! -L "$s" ]; then if [ ! -d "$s" -a ! -f "$s" -a ! -L "$s" ]; then
echo \"$s\" is neither a regular file, nor a directory, nor a link. Exiting. >&2 fatal \"$s\" is neither a regular file, nor a directory, nor a link. Exiting. >&2
exit 1
fi fi
done done
@ -269,13 +283,13 @@ case $method in
rsync_ssh) rsync_ssh)
if [ "$login" != root ]; then if [ "$login" != root ]; then
if [ "$file_owner" -a "$file_owner" != "$login" ]; then if [ "$file_owner" -a "$file_owner" != "$login" ]; then
echo "File owner \"$file_owner\" is only legal, if you log in as \"$login\" or as \"root\"." fatal "File owner \"$file_owner\" is only legal, if you log in as \"$login\" or as \"root\"."
exit 1
fi fi
fi;; fi
;;
*) *)
echo "Support for method \"$method\" is not implemented." >&2 fatal "Support for method \"$method\" is not implemented." >&2
exit 1;; ;;
esac esac
# -- real run # -- real run
@ -295,9 +309,7 @@ if [ -n "$VARIABLE" ]; then
dir_mode) echo $dir_mode;; dir_mode) echo $dir_mode;;
source) echo $source;; source) echo $source;;
target_file) echo $target_file;; target_file) echo $target_file;;
*) *) fatal Unknown variable \"$VARIABLE\". Exiting. >&2;;
echo Unknown variable \"$VARIABLE\". Exiting. >&2
exit 1;
esac esac
test "$EXIT" = 1 && exit 0 test "$EXIT" = 1 && exit 0
fi fi
@ -317,13 +329,13 @@ eval `parse_target $target`
case $method in case $method in
rsync_ssh) rsync_ssh)
tmp_dir=/tmp/$login/rsync-ssh tmp_dir=/tmp/$login/rsync-ssh
ssh_mkdir $target_file $file_owner $file_group $dir_mode || break ssh_mkdir $target_file $file_owner $file_group $dir_mode || fatal "failed to create directory for $target_file"
/usr/bin/rsync -az --links -e "$SSH -l $login $IDENTITY" $source $login@$host:$target_file /usr/bin/rsync -az --links -e "$SSH -l $login $IDENTITY" $source $login@$host:$target_file
ssh_chown $target_path $file_owner $file_group ssh_chown $target_path $file_owner $file_group
ssh_chmod $target_path $file_mode $dir_mode ssh_chmod $target_path $file_mode $dir_mode
;; ;;
*) *)
echo "Internal error: \"$method\" is not implemented." >&2 fatal "Internal error: \"$method\" is not implemented." >&2
exit 1;; ;;
esac esac