diff --git a/modules/install-shell-base.lib b/modules/install-shell-base.lib deleted file mode 100644 index 3bf631f..0000000 --- a/modules/install-shell-base.lib +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# assumes that bash is installed -#!/bin/bash - -# must! be run as sudo -install_shell_base () { - # TODO have a cross distro package install - [[ ! $(which git) ]] && echo git must be installed first && return 1 - [[ ! $EUID -eq 0 ]] && { echo ERROR script must be run as root; return 2; } - mkdir -p /shell/base - git clone https://git.kebler.net/bash/shell-base.git /shell/base - chown -R ${1:-$1000}:${1:-1000} /shell - chmod -R +r /shell - /bin/bash /shell/base/install/install.sh ${1:-$1000} -} - -# remote_install_shell_base -r -# module_load install-shell-base && remote_install_shell_base -r newboxr -remote_install_shell_base () { - module_load remote - local supass;local user - if [[ $1 == "-r" ]]; then - shift 1; - user=$2; - else - [[ ! $2 ]] && { echo sudo password for remote user required; return 2; } - supass="-p $2" - user=$3 - fi - remote_script $supass install-shell-base $user -- $1 -} - -# # if script was executed then call the function -(return 0 2>/dev/null) || install_shell_base $@ - -# example -# $ module_load install-shell-base -# $ remote_install_shell_base -r portabler david - diff --git a/modules/install-shell-base.sh b/modules/install-shell-base.sh new file mode 100644 index 0000000..400e440 --- /dev/null +++ b/modules/install-shell-base.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# assumes that bash is installed +#!/bin/bash +# must! be run as sudo + +install_shell_base () { + # TODO have a cross distro package install + module_load distro + set_distro + + [[ ! $(command -v git) ]] && echo git must be installed first && $INSTALL_PKGS git + # TODO, avoid which in all scripts. or put which in environment if not on machine + [[ ! $(command -v which) ]] && echo 'which' must be installed first && $INSTALL_PKGS which + echo $USER, $EUID + [[ ! $EUID -eq 0 ]] && { echo ERROR script must be run as root; return 2; } + echo I am ROOT, now running script + echo UCI user: $1 + # TODO make the repo and clone values dynamic or bundle current base on sending machine a archive + mkdir -p /shell/base + git clone https://git.kebler.net/bash/shell-base.git /shell/base + chown -R ${1:-$1000}:${1:-1000} /shell + chmod -R +r /shell + + /bin/bash /shell/base/install/install.sh ${1:-1000} +} + +# # if script was executed then call the function + ( return 0 2>/dev/null ) || install_shell_base $@ + + diff --git a/modules/net-utils.mod b/modules/net-utils.mod index 8718556..4077a97 100644 --- a/modules/net-utils.mod +++ b/modules/net-utils.mod @@ -37,26 +37,36 @@ lookup_host () { # usage: lookup_host hostname < configfile > local config; local host; local lhost config=$([[ $2 ]] && echo $2 || echo ${SSH_CONFIG:-$HOME/.ssh/config}) -host=$(parse_host $1) +host=$(get_hostname_host $1)return lhost=$(ssh -F $config -G $host | grep -w hostname | cut -d' ' -f2) [[ $lhost ]] && echo $lhost || echo $host } -parse_host () { - # usage: parse_host +get_hostname_host () { + # usage: get_hostname_host # returns extracted host if passed user@host # otherwise return value passed - [[ $1 =~ "@" ]] && { echo $(sed 's/.*@\(.*\)/\1/' <<< "$1");return 0; } - echo $1 - return 1 + # [[ $1 =~ "@" ]] && { echo $(sed 's/.*@\(.*\)/\1/' <<< "$1");return 0; } + local hostname + hostname=$(cut -s -d@ -f2 <<< "$1") + if [[ ! $hostname ]] && type ssh_config_get &>/dev/null ; then + hostname=$(ssh_config_get -h $1) + fi + [[ $hostname ]] && echo $hostname || return 1 } -parse_user () { - # usage: parse_user +get_user_host () { + # [[ $1 =~ "@" ]] && { echo $(sed 's/\(.*\)@.*/\1/' <<< "$1"); return 0; } || return 1 + # usage: get_user_host # returns extracted user if passed user@host # otherwise returns nothing # return 1 no user in string - [[ $1 =~ "@" ]] && { echo $(sed 's/\(.*\)@.*/\1/' <<< "$1"); return 0; } || return 1 + local user + user=$(cut -s -d@ -f1 <<< "$1") + if [[ ! $user ]] && type ssh_config_get &>/dev/null ; then + user=$(ssh_config_get -u $1) + fi + [[ $user ]] && echo $user || return 1 } diff --git a/modules/nomachine.lib b/modules/nomachine.lib new file mode 100644 index 0000000..fe13e2e --- /dev/null +++ b/modules/nomachine.lib @@ -0,0 +1,13 @@ +/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 \ No newline at end of file diff --git a/modules/remote.mod b/modules/remote.mod index 146ac22..0f42587 100644 --- a/modules/remote.mod +++ b/modules/remote.mod @@ -1,97 +1,172 @@ #!/bin/bash module_load ssh +module_load bundle +module_load helpers +module_load ssh-copy + + +remote_function () { + [[ $2 ]] && module_load $2 + if declare -f $1; then + local file + file=$(mkrfilename function) + $(declare -f $1) > $file + echo $file + else + >&2 echo fatal: unable to source funtion $1, aborting + return 1 + fi +} + + remote_script () { - # usage: remote_script script -- host - # see ssh function - # -local sshargs;local user;local supass;local fn;local args;local file -[[ "$*" =~ "--" ]] && sshargs=$(sed 's/.*--\(.*\)/\1/' <<< "$@") -[[ ! $sshargs ]] && { echo missing remote machine, must provide at least a hostname, -- hostname; return 3; } -# reset arguments to just those before -- -set -- $(sed 's/\(.*\)--.*/\1/' <<< "$@") + local sshargs;local user;local supass;local cfn; local rfn; local args; + local script; local host; local dr; local supass + local hostname; local bscript; local ruser; local usesudo -local OPTION - local OPTARG - local OPTIND - while getopts 'u:s:f:p:' OPTION; do - # echo OPTION $OPTION ARG $OPTARG INDX $OPTIND - case "$OPTION" in - s) - # script filename to run - file=$OPTARG - ;; + help() { + + cat < host script