ssfs view ssfs @ rev 108

Add Japanese translations (thanks Keiichi Shiga)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Jan 10 13:01:53 2017 +0200 (2017-01-10)
parents 4937afb8ea05
children
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
14 key=$HOME/.ssh/id_rsa
16 # Internationalization
17 . /usr/bin/gettext.sh
18 TEXTDOMAIN='ssfs'
19 export TEXTDOMAIN
21 # Parse cmdline options.
22 for opt in $@
23 do
24 case "$opt" in
25 --login=*)
26 login=${opt#--login=} ;;
27 --host=*)
28 host=${opt#--host=} ;;
29 *)
30 continue ;;
31 esac
32 done
34 #
35 # Functions
36 #
38 # Built-in usage.
39 help() {
40 cat << EOT
42 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") $app [command] [--option=]
44 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
45 help $(gettext "Display this short help usage.")
46 info $(gettext "Display configuration settings.")
47 setup $(gettext "Setup client configuration and RSA key.")
48 sync $(gettext "Sync from server and start daemon.")
49 stop $(gettext "Stop monitoring ~/Sync folder.")
50 login $(gettext "Connect to remote host via SSH.")
52 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
53 --login= $(gettext "Login name on remote host.")
54 --host= $(gettext "Server host name or IP.")
56 EOT
57 }
59 # Display config settings.
60 config_info() {
61 [ ! -f "$config" ] && exit 0
62 fgrep '=' $config | sed s'/^ //'
63 }
65 # Create a Lua configuration file for lsyncd.
66 gen_config() {
67 mkdir -p $(dirname $config)
68 cat > $config << EOT
69 -- Configuration file for SliTaz Secure File Storage lsyncd daemon.
71 sync {
72 default.rsyncssh,
73 source = "$HOME/Sync",
74 host = "$login@$host",
75 targetdir = "Sync/"
76 }
77 EOT
78 }
80 get_config() {
81 at=$(fgrep host $config | cut -d '"' -f 2)
82 login=${at%@*}
83 host=${at#*@}
84 }
86 #
87 # Commands
88 #
90 case "$1" in
91 info)
92 size=$(du -sh $HOME/Sync | awk '{print $1}')
93 echo "" && config_info && echo ""
94 gettext "RSA key :"; echo " $key"
95 gettext "Sync size :"; echo " $size"
96 echo "" ;;
97 setup)
98 # We need a login and host name or IP.
99 if [ -z "$login" ] || [ -z "$host" ]; then
100 gettext "Usage:"; echo -e \
101 " $(basename $0) setup --login=user --host=server\n" && exit 0
102 fi
103 gen_config
104 mkdir -p $logdir $(dirname $pid)
106 # Configure passwordless login via RSA key.
107 if [ ! -f "$key" ]; then
108 mkdir -p $(dirname $key)
109 ssh-keygen -b 2048 -f $key -P ''
110 fi
111 echo ""
113 # Upload key to the server.
114 gettext "Sending RSA secure key to:"; echo " $host"
115 gettext "Please enter your Ssfs password."
116 echo -e "\n"
117 cat $key.pub | \
118 ssh $login@$host 'cat - >> ~/.ssh/authorized_keys' || exit 1
119 gettext "Client is setup you can now sync"; echo ;;
120 sync)
121 # Sync can be called at session startup or from cmdline to retrieve
122 # files from the server.
123 [ ! -f "$config" ] && gettext "Missing config file" && \
124 echo "" && exit 1
125 at=$(fgrep host $config | cut -d '"' -f 2)
126 login=${at%@*}
127 host=${at#*@}
128 echo "" && gettext "Syncing from:"; echo " $login@$host"
130 # Clean logs.
131 echo "" > $logdir/lsyncd.log
132 echo "" > $logdir/rsync.log
134 # First sync client with server.
135 rsync -r -a -v -h -z -u --delete \
136 --log-file=$logdir/rsync.log \
137 -e "ssh -l $login" $host:~/Sync/ ~/Sync/ | \
138 sed -e "/^$/"d -e "/^.\/$/"d
140 # Monitor local folder.
141 killall lsyncd 2>/dev/null
142 gettext "Starting lsyncd daemon..."
143 lsyncd -pidfile $pid -log scarce -logfile $logdir/lsyncd.log $config
144 echo -e "\n" ;;
145 stop)
146 # Kill daemon and remove pidfile.
147 [ ! -s "$pid" ] && gettext "Daemon is not running" && \
148 echo "" && exit 0
149 kill=$(cat $pid)
150 gettext "Stopping"; echo " $app PID: $kill"
151 kill $kill 2>/dev/null
152 rm -f $pid ;;
153 login)
154 # Connect user to Ssfs server via SSH.
155 get_config
156 ssh $login@$host ;;
157 *)
158 help ;;
159 esac
160 exit 0