mirror of
https://github.com/DictXiong/dotfiles.git
synced 2024-11-24 06:27:03 +08:00
riot: support zssh and sftp, and set ssh options according to trust settings
This commit is contained in:
parent
8f3b053bbd
commit
00b7a550ab
31
scripts/riot
31
scripts/riot
|
@ -2,16 +2,22 @@
|
||||||
# connect to iot services
|
# connect to iot services
|
||||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
source "$THIS_DIR/../tools/common.sh"
|
source "$THIS_DIR/../tools/common.sh"
|
||||||
|
RIOT_TRUST_CLIENT=${RIOT_TRUST_CLIENT:-${DFS_TRUST:-0}}
|
||||||
|
RIOT_TRUST_SERVER=${RIOT_TRUST_SERVER:-0}
|
||||||
|
|
||||||
# get target settings
|
# get target settings
|
||||||
# provides:
|
# provides:
|
||||||
SERVER=""
|
SERVER=""
|
||||||
PORT="" # optional
|
PORT="" # optional
|
||||||
USERNAME="" # optional
|
USERNAME="" # optional
|
||||||
SSH_OPTIONS="" # optional
|
SSH_OPTIONS=""
|
||||||
|
if [[ "$RIOT_TRUST_CLIENT" == "1" ]]; then
|
||||||
|
SSH_OPTIONS='-o ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes'
|
||||||
|
fi
|
||||||
get_server_meta()
|
get_server_meta()
|
||||||
{
|
{
|
||||||
arg="$1"
|
local trust_server="$RIOT_TRUST_SERVER"
|
||||||
|
local arg="$1"
|
||||||
# overwrite
|
# overwrite
|
||||||
if [[ "$arg" == *@* ]]; then
|
if [[ "$arg" == *@* ]]; then
|
||||||
USERNAME=${arg%%@*}
|
USERNAME=${arg%%@*}
|
||||||
|
@ -35,12 +41,14 @@ get_server_meta()
|
||||||
SERVER=$host.$domain.ink
|
SERVER=$host.$domain.ink
|
||||||
PORT=${PORT:-12022}
|
PORT=${PORT:-12022}
|
||||||
USERNAME=${USERNAME:-root}
|
USERNAME=${USERNAME:-root}
|
||||||
|
trust_server=1
|
||||||
;;
|
;;
|
||||||
nasp )
|
nasp )
|
||||||
SERVER=$host
|
SERVER=$host
|
||||||
PORT=${PORT:-12022}
|
PORT=${PORT:-12022}
|
||||||
USERNAME=${USERNAME:-dictxiong}
|
USERNAME=${USERNAME:-dictxiong}
|
||||||
SSH_OPTIONS='-o ProxyJump="ssh@nasp.ob.ac.cn:36022"'
|
SSH_OPTIONS=$SSH_OPTIONS' -o ProxyJump="ssh@nasp.ob.ac.cn:36022"'
|
||||||
|
trust_server=1
|
||||||
;;
|
;;
|
||||||
proxied )
|
proxied )
|
||||||
SERVER=proxy.beardic.cn
|
SERVER=proxy.beardic.cn
|
||||||
|
@ -48,17 +56,23 @@ get_server_meta()
|
||||||
tmp=${tmp:0:4}
|
tmp=${tmp:0:4}
|
||||||
PORT=$((10#$tmp+36000))
|
PORT=$((10#$tmp+36000))
|
||||||
USERNAME=root
|
USERNAME=root
|
||||||
|
trust_server=1
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
fmt_warning "unknown domain: $domain. will try as server name"
|
fmt_warning "unknown domain: $domain. will try as server name"
|
||||||
SERVER="$arg"
|
SERVER="$arg"
|
||||||
esac
|
esac
|
||||||
|
if [[ "$trust_server" == "1" ]]; then
|
||||||
|
SSH_OPTIONS=$SSH_OPTIONS' -o ForwardX11=yes -o ForwardAgent=yes'
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ssh
|
# ssh
|
||||||
|
SSH_BIN=ssh
|
||||||
|
SSH_PORT_PARAM='-p'
|
||||||
run_ssh()
|
run_ssh()
|
||||||
{
|
{
|
||||||
CMD="ssh ${PORT:+-p} $PORT $SSH_OPTIONS $USERNAME${USERNAME:+@}$SERVER"
|
CMD="$SSH_BIN ${PORT:+$SSH_PORT_PARAM} $PORT $SSH_OPTIONS $USERNAME${USERNAME:+@}$SERVER"
|
||||||
fmt_note "-->" $CMD
|
fmt_note "-->" $CMD
|
||||||
if [[ "$DFS_DRY_RUN" == "1" ]]; then
|
if [[ "$DFS_DRY_RUN" == "1" ]]; then
|
||||||
echo $CMD
|
echo $CMD
|
||||||
|
@ -116,6 +130,15 @@ router()
|
||||||
ssh|"" )
|
ssh|"" )
|
||||||
run_ssh
|
run_ssh
|
||||||
;;
|
;;
|
||||||
|
zssh )
|
||||||
|
SSH_BIN=zssh
|
||||||
|
run_ssh
|
||||||
|
;;
|
||||||
|
sftp )
|
||||||
|
SSH_BIN=sftp
|
||||||
|
SSH_PORT_PARAM='-P'
|
||||||
|
run_ssh
|
||||||
|
;;
|
||||||
sshl )
|
sshl )
|
||||||
run_sshl "$3"
|
run_sshl "$3"
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user