Merge pull request #16 from wushan/master
[PR] Specify port for each host.
This commit is contained in:
@@ -18,7 +18,8 @@ Execute from the working directory (assuming you have an SSH server running on 1
|
|||||||
```bash
|
```bash
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
-e PLUGIN_KEY=$(cat some-private-key) \
|
-e PLUGIN_KEY=$(cat some-private-key) \
|
||||||
-e PLUGIN_HOSTS="127.0.0.1" \
|
-e PLUGIN_HOSTS="127.0.0.1, 127.0.0.2, 127.0.0.3" \
|
||||||
|
-e PLUGIN_PORTS="22, 23, 24" \
|
||||||
-e PLUGIN_TARGET="./" \
|
-e PLUGIN_TARGET="./" \
|
||||||
-e PLUGIN_SCRIPT="echo \"Done!\"" \
|
-e PLUGIN_SCRIPT="echo \"Done!\"" \
|
||||||
-e PLUGIN_ARGS="--blocking-io" \
|
-e PLUGIN_ARGS="--blocking-io" \
|
||||||
|
|||||||
30
upload.sh
30
upload.sh
@@ -1,5 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [ -z "$PLUGIN_HOSTS" ]; then
|
if [ -z "$PLUGIN_HOSTS" ]; then
|
||||||
echo "Specify at least one host!"
|
echo "Specify at least one host!"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -9,11 +8,10 @@ if [ -z "$PLUGIN_TARGET" ]; then
|
|||||||
echo "Specify a target!"
|
echo "Specify a target!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
DEFAULT_PORT=$PLUGIN_PORT
|
||||||
PORT=$PLUGIN_PORT
|
|
||||||
if [ -z "$PLUGIN_PORT" ]; then
|
if [ -z "$PLUGIN_PORT" ]; then
|
||||||
echo "Port not specified, using default port 22!"
|
echo "Port not specified, using default port 22!"
|
||||||
PORT=22
|
DEFAULT_PORT="22"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SOURCE=$PLUGIN_SOURCE
|
SOURCE=$PLUGIN_SOURCE
|
||||||
@@ -58,7 +56,7 @@ if [[ -n "$PLUGIN_DELETE" && "$PLUGIN_DELETE" == "true" ]]; then
|
|||||||
expr="$expr --del"
|
expr="$expr --del"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
expr="$expr -e 'ssh -p $PORT -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o StrictHostKeyChecking=no'"
|
expr="$expr -e 'ssh -p %s -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o StrictHostKeyChecking=no'"
|
||||||
|
|
||||||
# Include
|
# Include
|
||||||
IFS=','; read -ra INCLUDE <<< "$PLUGIN_INCLUDE"
|
IFS=','; read -ra INCLUDE <<< "$PLUGIN_INCLUDE"
|
||||||
@@ -109,20 +107,28 @@ script=$(join_with ' && ' "${COMMANDS[@]}")
|
|||||||
|
|
||||||
# Run rsync
|
# Run rsync
|
||||||
IFS=','; read -ra HOSTS <<< "$PLUGIN_HOSTS"
|
IFS=','; read -ra HOSTS <<< "$PLUGIN_HOSTS"
|
||||||
|
IFS=','; read -ra PORTS <<< "$PLUGIN_PORTS"
|
||||||
result=0
|
result=0
|
||||||
for host in "${HOSTS[@]}"; do
|
for ((i=0; i < ${#HOSTS[@]}; i++))
|
||||||
echo $(printf "%s" "$ $expr $USER@$host:$PLUGIN_TARGET ...")
|
do
|
||||||
eval "$expr $USER@$host:$PLUGIN_TARGET"
|
HOST=${HOSTS[$i]}
|
||||||
|
PORT=${PORTS[$i]}
|
||||||
|
if [ -z $PORT ]
|
||||||
|
then
|
||||||
|
# Default Port 22
|
||||||
|
PORT=$DEFAULT_PORT
|
||||||
|
fi
|
||||||
|
echo $(printf "%s" "$ $(printf "$expr" "$PORT") $USER@$HOST:$PLUGIN_TARGET ...")
|
||||||
|
eval "$(printf "$expr" "$PORT") $USER@$HOST:$PLUGIN_TARGET"
|
||||||
result=$(($result+$?))
|
result=$(($result+$?))
|
||||||
if [ "$result" -gt "0" ]; then exit $result; fi
|
if [ "$result" -gt "0" ]; then exit $result; fi
|
||||||
if [ -n "$PLUGIN_SCRIPT" ]; then
|
if [ -n "$PLUGIN_SCRIPT" ]; then
|
||||||
echo $(printf "%s" "$ ssh -p $PORT $USER@$host ...")
|
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST ...")
|
||||||
echo $(printf "%s" " > $script ...")
|
echo $(printf "%s" " > $script ...")
|
||||||
eval "ssh -p $PORT $USER@$host '$script'"
|
eval "ssh -p $PORT $USER@$HOST '$script'"
|
||||||
result=$(($result+$?))
|
result=$(($result+$?))
|
||||||
echo $(printf "%s" "$ ssh -p $PORT $USER@$host result: $?")
|
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST result: $?")
|
||||||
if [ "$result" -gt "0" ]; then exit $result; fi
|
if [ "$result" -gt "0" ]; then exit $result; fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
exit $result
|
exit $result
|
||||||
|
|||||||
Reference in New Issue
Block a user