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

tazlocale: remove burnbox doc reference (it was moved to oldstuff after 4.0 release)
author Claudinei Pereira <claudinei@slitaz.org>
date Sun Sep 02 13:42:48 2012 -0300 (2012-09-02)
parents 8e6a203e0881
children e232f0e1413a
line source
1 #!/bin/sh
2 #
3 # SCP Box - Small front end to the secure file copy utility.
4 #
5 # Copyright (C) 2008-2012 SliTaz GNU/Linux - BSD License
6 #
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /lib/libtaz.sh
11 [ "$file" ] || file="$HOME"
12 [ "$dir" ] || dir="$HOME"
14 # Internal variables (we need a space before options).
15 config=$HOME/.config/scpbox
16 icon=/usr/share/pixmaps/slitaz-icon.png
17 term="xterm -geometry 80x16"
18 scpopts=" -r -P 22"
20 # Make sure we have config files.
21 if [ ! -d "$config" ] || [ -f "$config/hosts" ]; then
22 mkdir -p $config
23 touch $config/hosts && chmod 0600 $config/hosts
24 fi
26 #
27 # Functions
28 #
30 # Help and usage
31 usage() {
32 cat << EOT
34 $(gettext "Usage:") $(basename $0) [command|option]
36 $(gettext "Commands:")
37 list-hosts $(gettext "List all known hosts")
39 $(gettext "Options:")
40 --file=/path/to/file
41 --dir=/path/to/directory
43 $(gettext "Examples:")
44 $(basename $0) --file=/path/to/file
46 EOT
47 }
49 # List last used hosts.
50 list_hosts() {
51 for h in $(cat $config/hosts)
52 do
53 echo -n "!$h"
54 done
55 }
57 # Main GUI box function with pure Yad spec
58 scpbox_main() {
59 text=$(gettext "<b>Secure copy</b> - Copy files remotely with scp")
60 yad --form --title="SCP Box" --window-icon=$icon \
61 --image=folder-remote --image-on-top \
62 --height=320 --width=500 --text="$text" \
63 --field="$(gettext "User name:")" \
64 --field="$(gettext "Hostname:")" \
65 --field="$(gettext "Known hosts:")":CB \
66 --field="$(gettext "Options:")" \
67 --field="$(gettext "Local file:")":FL \
68 --field="$(gettext "Local directory:")":DIR \
69 --field="$(gettext "Remote path:")" \
70 --button="$(gettext "Download")":2 \
71 --button="$(gettext "Upload")":0 \
72 --button="gtk-close":1 \
73 "$USER" "" "$(list_hosts)" "$scpopts" "$file" "$dir" ""
74 }
76 # Main function
77 scpbox() {
78 # Store box results
79 main=$(scpbox_main)
80 ret=$?
81 [ "$debug" ] && echo "DEBUG: main=$main"
83 user=$(echo $main | cut -d "|" -f 1)
84 hostname=$(echo $main | cut -d "|" -f 2)
85 options=$(echo $main | cut -d "|" -f 4)
86 remote=$(echo $main | cut -d "|" -f 7)
88 # Use and store new hostname.
89 if [ "$hostname" ]; then
90 echo "$hostname" >> $config/hosts
91 host="$hostname"
92 else
93 host=$(echo $main | cut -d "|" -f 3)
94 fi
95 if [ "$host" == "(null)" ] || [ ! "$host" ]; then
96 echo "No host: exit" && exit 0
97 fi
99 # Deal with --button values
100 case $ret in
101 0)
102 # Upload: do we have a single file or a directory (skip $HOME)
103 file=$(echo $main | cut -d "|" -f 5)
104 dir=$(echo $main | cut -d "|" -f 6)
105 if [ -f "$file" ]; then
106 local="$file"
107 elif [ "$dir" != "$HOME" ]; then
108 local="$dir"
109 else
110 echo "No file: exit" && exit 0
111 fi
112 cmd="scp $options $local $user@$host:$remote"
113 [ "$debug" ] && echo "DEBUG: $cmd"
114 $term -e "$cmd" ;;
115 2)
116 # Download: we need a remote file.
117 local=$(echo $main | cut -d "|" -f 6)
118 if [ ! "$remote" ]; then
119 echo "No remote file: exit" && exit 0
120 fi
121 cmd="scp $options $user@$host:$remote $local"
122 [ "$debug" ] && echo "DEBUG: $cmd"
123 $term -e "$cmd" ;;
124 *)
125 exit 0 ;;
126 esac
127 }
129 #
130 # Commands
131 #
133 case "$1" in
134 list-hosts)
135 list_hosts ;;
136 ""|--*)
137 scpbox ;;
138 *)
139 usage ;;
140 esac
142 exit 0