ssfs view ssfs @ rev 74

Add POT files for client side tools
author Christophe Lincoln <pankso@slitaz.org>
date Mon Jun 13 22:38:23 2011 +0200 (2011-06-13)
parents 3a2f682ce267
children 80448ddb1333
line source
1 #!/bin/sh
2 #
3 # SliTaz Secure File Storage. Fast live sync using: SSH, Rsync, Lsyncd.
4 # Configuration file is a LUA script in user space.
5 #
6 # Copyright (C) SliTaz GNU/Linux - BSD License
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
10 app=$(basename $0)
11 pid=$HOME/.local/var/run/$app.pid
12 logdir=$HOME/.local/var/log/$app
13 config=$HOME/.config/$app/client.lua
15 # Internationalization
16 . /usr/bin/gettext.sh
17 TEXTDOMAIN='ssfs'
18 export TEXTDOMAIN
20 # Parse cmdline options.
21 for opt in $@
22 do
23 case "$opt" in
24 --login=*)
25 login=${opt#--login=} ;;
26 --host=*)
27 host=${opt#--host=} ;;
28 *)
29 continue ;;
30 esac
31 done
33 #
34 # Functions
35 #
37 # Built-in usage.
38 help() {
39 cat << EOT
41 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") $app [command] [--option=]
43 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
44 help $(gettext "Display this short help usage.")
45 info $(gettext "Display configuration settings.")
46 setup $(gettext "Setup client configuration and RSA key.")
47 sync $(gettext "Sync from server and start daemon.")
48 stop $(gettext "Stop monitoring ~/Sync folder.")
49 login $(gettext "Connect to remote host via SSH.")
51 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
52 --login= $(gettext "Login name on remote host.")
53 --host= $(gettext "Server host name or IP.")
55 EOT
56 }
58 # Display config settings.
59 config_info() {
60 [ ! -f "$config" ] && exit 0
61 fgrep '=' $config | sed s'/^ //'
62 }
64 # Create a Lua configuration file for lsyncd.
65 gen_config() {
66 mkdir -p $(dirname $config)
67 cat > $config << EOT
68 -- Configuration file for SliTaz Secure File Storage lsyncd daemon.
70 sync {
71 default.rsyncssh,
72 source = "$HOME/Sync",
73 host = "$login@$host",
74 targetdir = "Sync/"
75 }
76 EOT
77 }
79 get_config() {
80 at=$(fgrep host $config | cut -d '"' -f 2)
81 login=${at%@*}
82 host=${at#*@}
83 }
85 #
86 # Commands
87 #
89 case "$1" in
90 info)
91 size=$(du -sh $HOME/Sync | awk '{print $1}')
92 echo "" && config_info && echo ""
93 gettext "RSA key :"; echo " $HOME/.ssh/id_rsa"
94 gettext "Sync size :"; echo " $size"
95 echo "" ;;
96 setup)
97 # We need a login and host name or IP.
98 if [ -z "$login" ] || [ -z "$host" ]; then
99 gettext "Usage:"; echo -e \
100 " $(basename $0) setup --login=user --host=server\n" && exit 0
101 fi
102 gen_config
103 mkdir -p $logdir $(dirname $pid)
105 # Configure passwordless login via RSA key.
106 if [ ! -f "$HOME/.ssh/id_rsa" ]; then
107 mkdir -p $HOME/.ssh
108 ssh-keygen -b 2048 -f $HOME/.ssh/id_rsa -P ''
109 fi
110 echo ""
112 # Upload key to the server.
113 gettext "Sending RSA secure key to:"; echo " $host"
114 gettext "Please enter your Ssfs password."
115 echo -e "\n"
116 cat $HOME/.ssh/id_rsa.pub | \
117 ssh $login@$host 'cat - >> ~/.ssh/authorized_keys' || exit 1
118 gettext "Client is setup you can now sync"; echo ;;
119 sync)
120 # Sync can be called at session startup or from cmdline to retrive
121 # files from the server.
122 [ ! -f "$config" ] && gettext "Missing config file" && \
123 echo "" && exit 1
124 at=$(fgrep host $config | cut -d '"' -f 2)
125 login=${at%@*}
126 host=${at#*@}
127 echo "" && gettext "Syncing from:"; echo " $login@$host"
129 # First sync host with server.
130 rsync -r -a -v -h -z -u --delete \
131 --log-file=$logdir/rsync.log \
132 -e "ssh -l $login" $host:~/Sync/ ~/Sync/ | \
133 sed -e "/^$/"d -e "/^.\/$/"d
135 # Monitor local folder if not yet running.
136 killall lsyncd 2>/dev/null
137 gettext "Starting lsyncd daemon..."
138 lsyncd -pidfile $pid -log all -logfile $logdir/lsyncd.log $config
139 echo "" ;;
140 stop)
141 # Kill daemon and remove pidfile.
142 [ ! -s "$pid" ] && gettext "Daemon is not running\n" && \
143 echo "" && exit 0
144 kill=$(cat $pid)
145 gettext "Stopping"; echo " $app PID: $kill"
146 kill $kill 2>/dev/null
147 rm -f $pid ;;
148 login)
149 # Connect user to Ssfs server via SSH.
150 get_config
151 ssh $login@$host ;;
152 *)
153 help ;;
154 esac
155 exit 0