mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-21 05:47:38 +01:00
upload.sh: Make permissions work for uploading of single files with rsync
This commit is contained in:
parent
32924899b6
commit
fa41ecc8c4
1 changed files with 73 additions and 18 deletions
|
|
@ -54,7 +54,8 @@ cat << EOT
|
||||||
Version '$Revision$' - '$Date$'
|
Version '$Revision$' - '$Date$'
|
||||||
(c) 2002 Jannet IT Services http://www.jannet.de
|
(c) 2002 Jannet IT Services http://www.jannet.de
|
||||||
|
|
||||||
usage: $MYNAME source [method://][[password:]login@]host[:target[:mode[:dirmode[:owner[.group]]]]] ...
|
usage: $MYNAME -h
|
||||||
|
$MYNAME [-v] [-c variable] source [method://][[password:]login@]host[:target[:mode[:dirmode[:owner[.group]]]]] ...
|
||||||
|
|
||||||
where "method" is one of "ftp", "scp", "rsync", "rsync_ssh".
|
where "method" is one of "ftp", "scp", "rsync", "rsync_ssh".
|
||||||
|
|
||||||
|
|
@ -86,16 +87,29 @@ cat << EOT
|
||||||
file_owner="$file_owner"
|
file_owner="$file_owner"
|
||||||
file_group="$file_group"
|
file_group="$file_group"
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
-h : show this help screen
|
||||||
|
-c variable : show contents of variable
|
||||||
|
valid variables are login, method, passwd, file_owner, file_group, file_mode, dir_mode,
|
||||||
|
source, target_file
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
[ -n "$1" ] && exit $1
|
[ -n "$1" ] && exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_dir()
|
||||||
|
{
|
||||||
|
isdir="`echo $1 | sed 's/.*\/$/yes/'`"
|
||||||
|
test "$isdir" = yes
|
||||||
|
}
|
||||||
|
|
||||||
parse_target()
|
parse_target()
|
||||||
{
|
{
|
||||||
target=$1
|
target=$1
|
||||||
USER=`echo $target | sed -e 's/^.*:\/\///; /@/ !d; s/@.*//; s/.*://'`
|
LOGIN=`echo $target | sed -e 's/^.*:\/\///; /@/ !d; s/@.*//; s/.*://'`
|
||||||
test -n "$USER" && echo login="\"$USER\";"
|
test -n "$LOGIN" && echo login="\"$LOGIN\";"
|
||||||
METHOD=`echo $target | sed -e 's/:\/\/.*//'`
|
METHOD=`echo $target | sed -e '/:\/\// !d; s/:\/\/.*//'`
|
||||||
test -n "$METHOD" && echo method="\"$METHOD\";"
|
test -n "$METHOD" && echo method="\"$METHOD\";"
|
||||||
PASSWD=`echo $target | sed -e '/@/ !d; /@/ !d; s/^.*:\/\///; s/@.*//' | rev | cut -d: -f2 | rev`
|
PASSWD=`echo $target | sed -e '/@/ !d; /@/ !d; s/^.*:\/\///; s/@.*//' | rev | cut -d: -f2 | rev`
|
||||||
if [ -n "$PASSWD" ]; then
|
if [ -n "$PASSWD" ]; then
|
||||||
|
|
@ -131,6 +145,12 @@ parse_target()
|
||||||
FILE_GROUP=`echo $target | sed -e 's/^.*:\/\///; s/.*@//; /:/ !d' | cut -d: -f5 | cut -d. -f2`
|
FILE_GROUP=`echo $target | sed -e 's/^.*:\/\///; s/.*@//; /:/ !d' | cut -d: -f5 | cut -d. -f2`
|
||||||
test -n "$FILE_GROUP" && echo file_group="\"$FILE_GROUP\";"
|
test -n "$FILE_GROUP" && echo file_group="\"$FILE_GROUP\";"
|
||||||
|
|
||||||
|
if is_dir "$target_file" ; then
|
||||||
|
echo target_path=\"$TARGET_FILE\"
|
||||||
|
else
|
||||||
|
echo target_path=\"$TARGET_FILE/`basename $source`\"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "PARSE_TARGET=\"OK\";"
|
echo "PARSE_TARGET=\"OK\";"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +163,7 @@ ssh_mkdir()
|
||||||
{
|
{
|
||||||
set -e
|
set -e
|
||||||
dir=`echo $1 | sed -e 's/\/[^\/]*$//; s/\/*$//'`
|
dir=`echo $1 | sed -e 's/\/[^\/]*$//; s/\/*$//'`
|
||||||
parts="`echo $dir | sed -e 's/\// /g'`"
|
parts="/ `echo $dir | sed -e 's/\// /g'`"
|
||||||
test -n "$dir_mode" && MODE="-m $dir_mode"
|
test -n "$dir_mode" && MODE="-m $dir_mode"
|
||||||
cat << EOT |
|
cat << EOT |
|
||||||
for part in $parts; do
|
for part in $parts; do
|
||||||
|
|
@ -168,9 +188,10 @@ ssh_chown()
|
||||||
set -e
|
set -e
|
||||||
dir=`echo $1 | sed -e 's/\/[^\/]*$//; s/\/*$//'`
|
dir=`echo $1 | sed -e 's/\/[^\/]*$//; s/\/*$//'`
|
||||||
cat << EOT |
|
cat << EOT |
|
||||||
cd $1
|
if [ -f "$1" -a -n "$file_owner" ]; then chown $file_owner $1; chgrp $file_group $1; fi
|
||||||
if [ -n "$2" ]; then chown -R $2 . ; fi
|
#cd $1
|
||||||
if [ -n "$3" ]; then chown -R $3 . ; fi
|
#if [ -n "$2" ]; then chown -R $2 . ; fi
|
||||||
|
#if [ -n "$3" ]; then chown -R $3 . ; fi
|
||||||
EOT
|
EOT
|
||||||
ssh_exec_stdin
|
ssh_exec_stdin
|
||||||
}
|
}
|
||||||
|
|
@ -180,16 +201,33 @@ ssh_chmod()
|
||||||
set -e
|
set -e
|
||||||
dir=`echo $1 | sed -e 's/\/[^\/]*$//; s/\/*$//'`
|
dir=`echo $1 | sed -e 's/\/[^\/]*$//; s/\/*$//'`
|
||||||
cat << EOT |
|
cat << EOT |
|
||||||
if [ -f "$1" ]; then
|
if [ -f "$1" -a -n "$file_mode" ]; then chmod $file_mode $1; fi
|
||||||
chmod $
|
#if [ -n "$2" ]; then find . -type f | xargs --no-run-if-empty chmod $2 ; fi
|
||||||
if [ -n "$2" ]; then find . -type f | xargs --no-run-if-empty chmod $2 ; fi
|
#if [ -n "$3" ]; then find . -type d | xargs --no-run-if-empty chmod $3 ; fi
|
||||||
if [ -n "$3" ]; then find . -type d | xargs --no-run-if-empty chmod $3 ; fi
|
|
||||||
EOT
|
EOT
|
||||||
ssh_exec_stdin
|
ssh_exec_stdin
|
||||||
}
|
}
|
||||||
|
|
||||||
# -- here we go
|
# -- here we go
|
||||||
test $# -lt 2 && usage 1
|
# -- command line arguments
|
||||||
|
set -- `getopt 'hvc:' $*`
|
||||||
|
while [ "$1" != -- ]; do
|
||||||
|
case $1 in
|
||||||
|
h)
|
||||||
|
usage 0;;
|
||||||
|
v)
|
||||||
|
VERBOSE=1;;
|
||||||
|
c)
|
||||||
|
VARIABLE=$2
|
||||||
|
shift;;
|
||||||
|
*)
|
||||||
|
usage 1;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
|
||||||
|
test -z "$VARIABLE" && test $# -lt 2 && usage 1
|
||||||
|
|
||||||
# -- get parameters from command line
|
# -- get parameters from command line
|
||||||
source=$1
|
source=$1
|
||||||
|
|
@ -197,14 +235,13 @@ shift
|
||||||
|
|
||||||
# -- check run
|
# -- check run
|
||||||
for t in $*; do
|
for t in $*; do
|
||||||
parse_target $t
|
# parse_target $t
|
||||||
eval `parse_target $t`
|
eval `parse_target $t`
|
||||||
if [ "$PARSE_TARGET" != OK ]; then
|
if [ "$PARSE_TARGET" != OK ]; then
|
||||||
echo "Failed to parse target \"$t\"; exiting."
|
echo "Failed to parse target \"$t\"; exiting."
|
||||||
parse_target $t
|
parse_target $t
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
test "$METHOD" && method=$METHOD
|
|
||||||
case $method in
|
case $method in
|
||||||
rsync_ssh)
|
rsync_ssh)
|
||||||
if [ "$login" != root ]; then
|
if [ "$login" != root ]; then
|
||||||
|
|
@ -224,15 +261,33 @@ for t in $*; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# -- real run
|
# -- real run
|
||||||
|
if [ -n "$VARIABLE" ]; then
|
||||||
|
eval `parse_target`
|
||||||
|
case "$VARABLE" in
|
||||||
|
login) echo $login;;
|
||||||
|
method) echo $method;;
|
||||||
|
passwd) echo $passwd;;
|
||||||
|
file_owner) echo $file_owner;;
|
||||||
|
file_group) echo $file_group;;
|
||||||
|
file_mode) echo $file_mode;;
|
||||||
|
dir_mode) echo $dir_mode;;
|
||||||
|
source) echo $source;;
|
||||||
|
target_file) echo $target_file;;
|
||||||
|
*)
|
||||||
|
echo Unknown variable \"$VARIABLE\". Exiting. >&2
|
||||||
|
exit 1;
|
||||||
|
esac
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
for t in $*; do
|
for t in $*; do
|
||||||
eval `parse_target $t`
|
eval `parse_target $t`
|
||||||
test "$METHOD" && method=$METHOD
|
|
||||||
case $method in
|
case $method in
|
||||||
rsync_ssh)
|
rsync_ssh)
|
||||||
ssh_mkdir $target_file $file_owner $file_group $dir_mode || break
|
ssh_mkdir $target_file $file_owner $file_group $dir_mode || break
|
||||||
/usr/bin/rsync -az --links -e "/usr/bin/ssh -l $login $IDENTITY" $source $login@$host:$target_file
|
/usr/bin/rsync -az --links -e "/usr/bin/ssh -l $login $IDENTITY" $source $login@$host:$target_file
|
||||||
ssh_chown $target_file $file_owner $file_group
|
ssh_chown $target_path $file_owner $file_group
|
||||||
ssh_chmod $target_file $file_mode $dir_mode
|
ssh_chmod $target_path $file_mode $dir_mode
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Internal error: \"$method\" is not implemented." >&2
|
echo "Internal error: \"$method\" is not implemented." >&2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue