fix bug in remove script
parent
d45198b025
commit
b2efa57439
|
@ -1,13 +0,0 @@
|
||||||
/usr/NX/etc/server.cfg
|
|
||||||
|
|
||||||
sed
|
|
||||||
|
|
||||||
#AcceptedAuthenticationMethods all
|
|
||||||
to
|
|
||||||
AcceptedAuthenticationMethods NX-private-key
|
|
||||||
|
|
||||||
restrat the server
|
|
||||||
|
|
||||||
sdr nxserver
|
|
||||||
|
|
||||||
copy a public key to ~/.nx/config/authorized.crt
|
|
|
@ -2,9 +2,9 @@
|
||||||
module_load remote
|
module_load remote
|
||||||
# remote_install_shell_base <script options> script command <sudo pass if host not root> <user to install, default is $USER>
|
# remote_install_shell_base <script options> script command <sudo pass if host not root> <user to install, default is $USER>
|
||||||
|
|
||||||
remote_install_uci_shell () {
|
remote_uci_shell_install () {
|
||||||
|
|
||||||
local supass;local user; local host
|
local supass;local user; local host; local upass
|
||||||
|
|
||||||
declare OPTION; declare OPTARG; declare OPTIND
|
declare OPTION; declare OPTARG; declare OPTIND
|
||||||
while getopts 'u: s:p:cf:x:' OPTION; do
|
while getopts 'u: s:p:cf:x:' OPTION; do
|
||||||
|
@ -25,6 +25,9 @@ remote_install_uci_shell () {
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
git="-e BASH_SHELL_GIT_URL=$BASH_SHELL_GIT_URL"
|
||||||
|
echo $git
|
||||||
|
|
||||||
shift $(( OPTIND - 1 ))
|
shift $(( OPTIND - 1 ))
|
||||||
|
|
||||||
host=$1
|
host=$1
|
||||||
|
@ -34,7 +37,10 @@ remote_install_uci_shell () {
|
||||||
[[ $user == "root" ]] && user="" && >&2 echo warning, will not set up any user than root for UCI shell
|
[[ $user == "root" ]] && user="" && >&2 echo warning, will not set up any user than root for UCI shell
|
||||||
[[ ! $user ]] && >&2 echo unable to determin remote user for host $host, aborting && return 1
|
[[ ! $user ]] && >&2 echo unable to determin remote user for host $host, aborting && return 1
|
||||||
if [[ $supass ]] && [[ $upass ]]; then >&2 echo specify either -s or -p or neither but not both; return 1; fi
|
if [[ $supass ]] && [[ $upass ]]; then >&2 echo specify either -s or -p or neither but not both; return 1; fi
|
||||||
[[ $upass ]] && remote_script -s -f install_shell_base $host uci-shell-install $user -- $upass "$@" && return $?
|
# remote user needs password login
|
||||||
[[ $supass ]] && remote_script $supass -f install_shell_base $host uci-shell-install $user -- $upass "$@" && return $?
|
if [[ $upass ]]; then remote_script -s $git -f install_shell_base $host uci-shell-install $user -- $upass "$@"; return $?; fi
|
||||||
remote_script -f install_shell_base $host uci-shell-install $user -- "$@"
|
# remote user has key but needs sudo
|
||||||
|
if [[ $supass ]]; then remote_script $supass $git -f install_shell_base $host uci-shell-install $user -- "$@"; return $?; fi
|
||||||
|
# remote host is already root
|
||||||
|
remote_script $git -f install_shell_base $host uci-shell-install $user -- "$@"
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ remote_script () {
|
||||||
|
|
||||||
local sshargs;local user;local supass;local cfn; local rfn; local args;
|
local sshargs;local user;local supass;local cfn; local rfn; local args;
|
||||||
local script; local host; local dr; local supass; local env_vars;
|
local script; local host; local dr; local supass; local env_vars;
|
||||||
local login; local slogin; local shell=bash
|
local login; local slogin; local shell=bash; local sargs
|
||||||
local hostname; local bscript; local ruser; local usesudo; local save
|
local hostname; local bscript; local ruser; local usesudo; local save
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
|
@ -39,7 +39,7 @@ host and script are required, script can be either path to a file containing a s
|
||||||
-u, <ruser> remote user to run script as. default is ssh host user or root if using sudo.
|
-u, <ruser> remote user to run script as. default is ssh host user or root if using sudo.
|
||||||
| if -u is other than ssh login user then -s or -p must be set
|
| if -u is other than ssh login user then -s or -p must be set
|
||||||
-s, execute remote script using sudo
|
-s, execute remote script using sudo
|
||||||
-p, <suppass> sudo password. If set teh remote command will be run as root or the user of -u <user>
|
-p, <supass> sudo password. If set the remote command will be run as root or the user of -u <user>
|
||||||
| if command has 'ssh script option' of '-- -p <upasswd>' and -s is set this will set -p <upasswd> automatically
|
| if command has 'ssh script option' of '-- -p <upasswd>' and -s is set this will set -p <upasswd> automatically
|
||||||
-l, use login shell on remote
|
-l, use login shell on remote
|
||||||
-e, <SOME_VAR="some value"> set some environment variables to run. Can be used more than once for multiple values
|
-e, <SOME_VAR="some value"> set some environment variables to run. Can be used more than once for multiple values
|
||||||
|
@ -48,22 +48,23 @@ EOF
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# parse ssh arguments from the rest
|
|
||||||
debug $( ( IFS=$','; echo all arguments: "$*" ) )
|
debug $( ( IFS=$','; echo all arguments: "$*" ) )
|
||||||
for ((d=1; d<$#; ++d)); do
|
for ((d=1; d<$#+1; ++d)); do
|
||||||
[[ ${!d} == "--" ]] && break
|
# echo in loop $d, ${!d}
|
||||||
|
[[ ${!d} == "--" ]] && sargs=true && break
|
||||||
done
|
done
|
||||||
|
if [[ $sargs ]]; then # if there are extra ssh arguments
|
||||||
if [[ $d -lt $# ]]; then # if there are extra ssh arguments
|
|
||||||
debug found -- at $d
|
|
||||||
sshargs=("${@:$d+1:$#}")
|
sshargs=("${@:$d+1:$#}")
|
||||||
debug $( ( IFS=$','; echo "ssh arguments: ${sshargs[*]}" ) )
|
debug $( ( IFS=$','; echo "ssh arguments: ${sshargs[*]}" ) )
|
||||||
# [[ ! ${sshargs[0]} ]] && { echo missing remote machine, must provide at least a hostname, -- hostname; return 3; }
|
set -- "${@:1:$d-1}"
|
||||||
args=("${@:1:$d-1}")
|
# args=("${@:1:$d-1}")
|
||||||
# reset script arguments to just those before --
|
|
||||||
set -- "${args[@]}"
|
|
||||||
debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
|
debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
|
||||||
|
else
|
||||||
|
set -- "${@:1}"
|
||||||
|
# args=("${@:1}")
|
||||||
fi
|
fi
|
||||||
|
# echo pre ssh args: "$@"
|
||||||
|
# echo args "${args[@]}"
|
||||||
|
|
||||||
# parse remote_script options
|
# parse remote_script options
|
||||||
local OPTION
|
local OPTION
|
||||||
|
@ -173,10 +174,11 @@ EOF
|
||||||
debug ssh arguments $(escape_args "${sshargs[@]}")
|
debug ssh arguments $(escape_args "${sshargs[@]}")
|
||||||
|
|
||||||
rscript=${save:-$(mkrfilename REMOTE_SCRIPT)}
|
rscript=${save:-$(mkrfilename REMOTE_SCRIPT)}
|
||||||
|
# sshcp -y -d $host $bscript $rscript -- "${sshargs[@]}"
|
||||||
|
# return
|
||||||
if sshcp -d $host $bscript $rscript -- "${sshargs[@]}"; then
|
if sshcp -d $host $bscript $rscript -- "${sshargs[@]}"; then
|
||||||
# make remote script excuteable
|
# make remote script excuteable
|
||||||
ssh "${sshargs[@]}" "$host" "chmod +x $rscript"
|
ssh "${sshargs[@]}" "$host" "chmod +x $rscript"
|
||||||
# run the script
|
|
||||||
ssh "${sshargs[@]}" "$host" "$usesudo" "$env_vars" "$shell" $login "$rscript" "$(escape_args "$@")"
|
ssh "${sshargs[@]}" "$host" "$usesudo" "$env_vars" "$shell" $login "$rscript" "$(escape_args "$@")"
|
||||||
# now delete it, save script if passed an explicit name
|
# now delete it, save script if passed an explicit name
|
||||||
if ! ssh "${sshargs[@]}" $host rm -f $rscript; then echo unable to delete temporary remote file at $host:$rscript; fi
|
if ! ssh "${sshargs[@]}" $host rm -f $rscript; then echo unable to delete temporary remote file at $host:$rscript; fi
|
||||||
|
|
|
@ -7,7 +7,7 @@ sshcp () {
|
||||||
|
|
||||||
local SHOST; local DHOST; local dr; local sshargs; local args
|
local SHOST; local DHOST; local dr; local sshargs; local args
|
||||||
local OPTS; local SOPTS; local SRC; local DEST;
|
local OPTS; local SOPTS; local SRC; local DEST;
|
||||||
local SPATH; local SPATH
|
local SPATH; local SPATH; local cmd; local sargs
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
|
|
||||||
|
@ -84,22 +84,17 @@ EOF
|
||||||
|
|
||||||
[[ $DHOST && $SHOST && (! $DHOST = "$SHOST") ]] && { echo full remote copy must be same hosts; return 2; }
|
[[ $DHOST && $SHOST && (! $DHOST = "$SHOST") ]] && { echo full remote copy must be same hosts; return 2; }
|
||||||
|
|
||||||
# parse ssh arguments from the rest
|
|
||||||
debug $( ( IFS=$','; echo all arguments: "$*" ) )
|
debug $( ( IFS=$','; echo all arguments: "$*" ) )
|
||||||
for ((d=1; d<$#; ++d)); do
|
for ((d=1; d<$#+1; ++d)); do
|
||||||
[[ ${!d} == "--" ]] && break
|
# echo in loop $d, ${!d}
|
||||||
|
[[ ${!d} == "--" ]] && sargs=true && break
|
||||||
done
|
done
|
||||||
|
if [[ $sargs ]]; then # if there are extra ssh arguments
|
||||||
if [[ $d -lt $# ]]; then # if there are extra ssh arguments
|
|
||||||
debug found -- at $d
|
|
||||||
sshargs=("${@:$d+1:$#}")
|
sshargs=("${@:$d+1:$#}")
|
||||||
debug $( ( IFS=$','; echo "ssh arguments: ${sshargs[*]}" ) )
|
debug $( ( IFS=$','; echo "ssh arguments: ${sshargs[*]}" ) )
|
||||||
# [[ ! ${sshargs[0]} ]] && { echo missing remote machine, must provide at least a hostname, -- hostname; return 3; }
|
|
||||||
args=("${@:1:$d-1}")
|
args=("${@:1:$d-1}")
|
||||||
# reset script arguments to just those before --
|
|
||||||
# set -- "${args[@]}"
|
|
||||||
debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
|
debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
|
||||||
else
|
else
|
||||||
args=("${@:1}")
|
args=("${@:1}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -125,9 +120,11 @@ EOF
|
||||||
|
|
||||||
[[ -d $SPATH && ! $SHOST ]] && args+=(" -r")
|
[[ -d $SPATH && ! $SHOST ]] && args+=(" -r")
|
||||||
|
|
||||||
|
echo "${args[*]}"
|
||||||
|
|
||||||
# todo test remote to local copy
|
# todo test remote to local copy
|
||||||
|
|
||||||
local cmd=""$sshpass" scp "${args[*]}" "$sshopts" $([[ $SHOST ]] && echo "${host}:")"$SPATH" $([[ $DHOST ]] && echo "${host}:")"$DPATH""
|
cmd=""$sshpass" scp "${args[*]}" "$sshopts" $([[ $SHOST ]] && echo "${host}:")"$SPATH" $([[ $DHOST ]] && echo "${host}:")"$DPATH""
|
||||||
# echo $cmd
|
# echo $cmd
|
||||||
if $([[ $dr ]] && echo "echo ") $cmd; then
|
if $([[ $dr ]] && echo "echo ") $cmd; then
|
||||||
debug copy success
|
debug copy success
|
||||||
|
|
Loading…
Reference in New Issue