slitaz-tools view boxes/scp-box @ rev 1029

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:26:53 2019 +0100 (2019-02-26)
parents bffe37afb546
children
line source
1 #!/bin/sh
2 #
3 # SCP Box - Small front end to the secure file copy utility.
4 #
5 # Copyright (C) 2008-2015 SliTaz GNU/Linux - BSD License
6 #
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
10 . /lib/libtaz.sh
11 export TEXTDOMAIN='slitaz-boxes' # i18n
13 [ "$file" ] || file="$HOME"
14 [ "$dir" ] || dir="$HOME"
17 # Internal variables (we need a space before options).
19 config=$HOME/.config/scpbox
20 term="terminal -geometry 80x16"
21 scpopts=" -r -P 22"
24 # Make sure we have config files.
26 if [ ! -d "$config" ] || [ -f "$config/hosts" ]; then
27 mkdir -p $config
28 touch $config/hosts && chmod 0600 $config/hosts
29 fi
32 #
33 # Functions
34 #
37 # Help and usage
39 usage() {
40 cat << EOT
42 $(_ 'SCP Box - Small front end to the secure file copy utility.')
44 $(boldify "$(_ 'Usage:')")
45 $(basename $0) [$(_n 'command')|$(_n 'option')]
47 $(boldify "$(_ 'Commands:')")
48 list-hosts $(_n 'List all known hosts')
50 $(boldify "$(_ 'Options:')")
51 --file=$(_n '/path/to/file')
52 --dir=$(_n '/path/to/directory')
54 $(boldify "$(_ 'Examples:')")
55 $(basename $0) --file=$(_n '/path/to/file')
57 EOT
58 }
61 # List last used hosts.
63 list_hosts() {
64 for h in $(cat $config/hosts); do
65 echo -n "!$h"
66 done
67 }
70 # Main GUI box function with pure Yad spec
72 scpbox_main() {
73 icon='folder-remote'
74 yad --title="$(_n 'SCP Box')" --window-icon=$icon \
75 --width=400 \
76 --image=$icon --image-on-top \
77 --text="$(_n '<b>Secure copy</b> - Copy files remotely with scp')" \
78 --form \
79 --field="$(_n 'User name:')" "$USER" \
80 --field="$(_n 'Hostname:')" "" \
81 --field="$(_n 'Known hosts:'):CB" "$(list_hosts)" \
82 --field="$(_n 'Options:')" "$scpopts" \
83 --field="$(_n 'Local file:'):FL" "$file" \
84 --field="$(_n 'Local directory:'):DIR" "$dir" \
85 --field="$(_n 'Remote path:')" "" \
86 --button="$(_n 'Download')!go-down:2" \
87 --button="$(_n 'Upload')!go-up:0" \
88 --button="gtk-close:1"
89 }
92 # Main function
94 scpbox() {
95 # Store box results
96 main=$(scpbox_main)
97 ret=$?
98 [ "$debug" ] && echo "DEBUG: main=$main"
100 user=$(echo $main | cut -d "|" -f 1)
101 hostname=$(echo $main | cut -d "|" -f 2)
102 options=$(echo $main | cut -d "|" -f 4)
103 remote=$(echo $main | cut -d "|" -f 7)
105 # Use and store new hostname.
106 if [ "$hostname" ]; then
107 echo "$hostname" >> $config/hosts
108 host="$hostname"
109 else
110 host=$(echo $main | cut -d "|" -f 3)
111 fi
112 if [ "$host" = "(null)" ] || [ ! "$host" ]; then
113 echo "No host, exit"; exit 0
114 fi
116 # Deal with --button values
117 case $ret in
118 0)
119 # Upload: do we have a single file or a directory (skip $HOME)
120 file=$(echo $main | cut -d "|" -f 5)
121 dir=$(echo $main | cut -d "|" -f 6)
122 if [ -f "$file" ]; then
123 local="$file"
124 elif [ "$dir" != "$HOME" ]; then
125 local="$dir"
126 else
127 echo "No file, exit"; exit 0
128 fi
129 cmd="scp $options $local $user@$host:$remote"
130 [ "$debug" ] && echo "DEBUG: $cmd"
131 $term -e "$cmd" ;;
132 2)
133 # Download: we need a remote file.
134 local=$(echo $main | cut -d "|" -f 6)
135 if [ ! "$remote" ]; then
136 echo "No remote file, exit"; exit 0
137 fi
138 cmd="scp $options $user@$host:$remote $local"
139 [ "$debug" ] && echo "DEBUG: $cmd"
140 $term -e "$cmd" ;;
141 *)
142 exit 0 ;;
143 esac
144 }
147 #
148 # Commands
149 #
151 case "$1" in
152 -h|--help) usage ;;
153 list-hosts) list_hosts ;;
154 ""|--*) scpbox ;;
155 *) usage ;;
156 esac
158 exit 0