lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

pppossh.sh (1713B)


      1 #!/bin/sh
      2 
      3 SSH=/usr/bin/ssh
      4 [ -x "$SSH" ] || {
      5 	echo "Cannot find executable $SSH." >&2
      6 	exit 1
      7 }
      8 
      9 . /lib/functions.sh
     10 . ../netifd-proto.sh
     11 init_proto "$@"
     12 
     13 INCLUDE_ONLY=1
     14 
     15 . ./ppp.sh
     16 
     17 proto_pppossh_init_config() {
     18 	ppp_generic_init_config
     19 	config_add_string server sshuser ipaddr peeraddr ssh_options
     20 	config_add_array 'identity:list(string)'
     21 	config_add_int port use_hostdep
     22 	available=1
     23 	no_device=1
     24 }
     25 
     26 proto_pppossh_setup() {
     27 	local config="$1"
     28 	local iface="$2"
     29 	local user="$(id -nu)"
     30 	local home=$(sh -c "echo ~$user")
     31 	local server port sshuser ipaddr peeraddr ssh_options identity use_hostdep
     32 	local ip fn errmsg opts pty
     33 
     34 	json_get_vars port sshuser ipaddr peeraddr ssh_options use_hostdep
     35 	json_get_var server server && {
     36 		[ -z "$use_hostdep" ] && use_hostdep=1
     37 		for ip in $(resolveip -t 5 "$server"); do
     38 			if [ "$use_hostdep" -gt 0 ]; then
     39 				( proto_add_host_dependency "$config" "$ip" )
     40 			else
     41 				break
     42 			fi
     43 		done
     44 	}
     45 	[ -n "$ip" ] || errmsg="${errmsg}Could not resolve $server\n"
     46 	[ -n "$sshuser" ] || errmsg="${errmsg}Missing sshuser option\n"
     47 
     48 	json_get_values identity identity
     49 	[ -z "$identity" ] && identity="$home/.ssh/id_rsa $home/.ssh/id_dsa"
     50 	for fn in $identity; do
     51 		[ -f "$fn" ] && opts="$opts -i $fn"
     52 	done
     53 	[ -n "$opts" ] || errmsg="${errmsg}Cannot find valid identity file\n"
     54 
     55 	[ -n "$errmsg" ] && {
     56 		echo -ne "$errmsg" >&2
     57 		proto_setup_failed "$config"
     58 		exit 1
     59 	}
     60 	opts="$opts ${port:+-p $port}"
     61 	opts="$opts ${ssh_options}"
     62 	opts="$opts $sshuser@$server"
     63 	pty="exec env 'HOME=$home' $SSH $opts pppd nodetach notty noauth"
     64 
     65 	ppp_generic_setup "$config" noauth pty "$pty" "$ipaddr:$peeraddr"
     66 }
     67 
     68 proto_pppossh_teardown() {
     69 	ppp_generic_teardown "$@"
     70 }
     71 
     72 add_protocol pppossh