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
|
||||
# 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
|
||||
while getopts 'u: s:p:cf:x:' OPTION; do
|
||||
|
@ -25,6 +25,9 @@ remote_install_uci_shell () {
|
|||
esac
|
||||
done
|
||||
|
||||
git="-e BASH_SHELL_GIT_URL=$BASH_SHELL_GIT_URL"
|
||||
echo $git
|
||||
|
||||
shift $(( OPTIND - 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 ]] && >&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
|
||||
[[ $upass ]] && remote_script -s -f install_shell_base $host uci-shell-install $user -- $upass "$@" && return $?
|
||||
[[ $supass ]] && remote_script $supass -f install_shell_base $host uci-shell-install $user -- $upass "$@" && return $?
|
||||
remote_script -f install_shell_base $host uci-shell-install $user -- "$@"
|
||||
# remote user needs password login
|
||||
if [[ $upass ]]; then remote_script -s $git -f install_shell_base $host uci-shell-install $user -- $upass "$@"; return $?; fi
|
||||
# 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 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
|
||||
|
||||
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.
|
||||
| if -u is other than ssh login user then -s or -p must be set
|
||||
-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
|
||||
-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
|
||||
|
@ -48,22 +48,23 @@ EOF
|
|||
|
||||
}
|
||||
|
||||
# parse ssh arguments from the rest
|
||||
debug $( ( IFS=$','; echo all arguments: "$*" ) )
|
||||
for ((d=1; d<$#; ++d)); do
|
||||
[[ ${!d} == "--" ]] && break
|
||||
for ((d=1; d<$#+1; ++d)); do
|
||||
# echo in loop $d, ${!d}
|
||||
[[ ${!d} == "--" ]] && sargs=true && break
|
||||
done
|
||||
|
||||
if [[ $d -lt $# ]]; then # if there are extra ssh arguments
|
||||
debug found -- at $d
|
||||
if [[ $sargs ]]; then # if there are extra ssh arguments
|
||||
sshargs=("${@:$d+1:$#}")
|
||||
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}")
|
||||
# reset script arguments to just those before --
|
||||
set -- "${args[@]}"
|
||||
set -- "${@:1:$d-1}"
|
||||
# args=("${@:1:$d-1}")
|
||||
debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
|
||||
else
|
||||
set -- "${@:1}"
|
||||
# args=("${@:1}")
|
||||
fi
|
||||
# echo pre ssh args: "$@"
|
||||
# echo args "${args[@]}"
|
||||
|
||||
# parse remote_script options
|
||||
local OPTION
|
||||
|
@ -173,10 +174,11 @@ EOF
|
|||
debug ssh arguments $(escape_args "${sshargs[@]}")
|
||||
|
||||
rscript=${save:-$(mkrfilename REMOTE_SCRIPT)}
|
||||
# sshcp -y -d $host $bscript $rscript -- "${sshargs[@]}"
|
||||
# return
|
||||
if sshcp -d $host $bscript $rscript -- "${sshargs[@]}"; then
|
||||
# make remote script excuteable
|
||||
ssh "${sshargs[@]}" "$host" "chmod +x $rscript"
|
||||
# run the script
|
||||
ssh "${sshargs[@]}" "$host" "$usesudo" "$env_vars" "$shell" $login "$rscript" "$(escape_args "$@")"
|
||||
# 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
|
||||
|
|
|
@ -7,7 +7,7 @@ sshcp () {
|
|||
|
||||
local SHOST; local DHOST; local dr; local sshargs; local args
|
||||
local OPTS; local SOPTS; local SRC; local DEST;
|
||||
local SPATH; local SPATH
|
||||
local SPATH; local SPATH; local cmd; local sargs
|
||||
|
||||
help() {
|
||||
|
||||
|
@ -84,20 +84,15 @@ EOF
|
|||
|
||||
[[ $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: "$*" ) )
|
||||
for ((d=1; d<$#; ++d)); do
|
||||
[[ ${!d} == "--" ]] && break
|
||||
for ((d=1; d<$#+1; ++d)); do
|
||||
# echo in loop $d, ${!d}
|
||||
[[ ${!d} == "--" ]] && sargs=true && break
|
||||
done
|
||||
|
||||
if [[ $d -lt $# ]]; then # if there are extra ssh arguments
|
||||
debug found -- at $d
|
||||
if [[ $sargs ]]; then # if there are extra ssh arguments
|
||||
sshargs=("${@:$d+1:$#}")
|
||||
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}")
|
||||
# reset script arguments to just those before --
|
||||
# set -- "${args[@]}"
|
||||
debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
|
||||
else
|
||||
args=("${@:1}")
|
||||
|
@ -125,9 +120,11 @@ EOF
|
|||
|
||||
[[ -d $SPATH && ! $SHOST ]] && args+=(" -r")
|
||||
|
||||
echo "${args[*]}"
|
||||
|
||||
# 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
|
||||
if $([[ $dr ]] && echo "echo ") $cmd; then
|
||||
debug copy success
|
||||
|
|
Loading…
Reference in New Issue