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