ssfs view ssfs-server @ rev 10

We can detect a Public in Sync if user wants public files
author Christophe Lincoln <pankso@slitaz.org>
date Sat Jun 11 18:08:22 2011 +0200 (2011-06-11)
parents 0de2fba271a3
children adba1713f615
line source
1 #!/bin/sh
2 #
3 # SliTaz Secure File Storage server side tool.
4 #
5 # Copyright (C) SliTaz GNU/Linux - BSD License
6 # Author: Christophe Lincoln <pankso@slitaz.org>
7 #
9 app=$(basename $0)
10 [ -f "/etc/ssfs/$app.conf" ] && . /etc/ssfs/$app.conf
11 [ -f "./data/$app.conf" ] && . ./data/$app.conf
13 # Be sure we're root.
14 [ $(id -u) != 0 ] && gettext "You must be root to run:" && \
15 echo " $app" && exit 0
17 # Parse cmdline options.
18 for opt in $@
19 do
20 case "$opt" in
21 --login=*)
22 login=${opt#--login=} ;;
23 --id=*)
24 id=${opt#--id=} ;;
25 --pass=*)
26 pass=${opt#--pass=} ;;
27 --root=*)
28 root=${opt#--root=} ;;
29 *)
30 continue ;;
31 esac
32 done
34 [ "$root" ] || root=${SSFS_CHROOT}
36 #
37 # Functions
38 #
40 # Built-in help usage.
41 help() {
42 cat << EOT
44 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") $app [command] [--option=]
46 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
47 help $(gettext "Display this short usage.")
48 users $(gettext "List users account and stats.")
49 adduser $(gettext "Add a user to the system with \$HOME in chroot.")
50 deluser $(gettext "Delete a user and remove \$HOME files.")
51 chroot $(gettext "Chroot to Ssfs storage root.")
52 gen-chroot $(gettext "Create a chroot for users files storage.")
53 clean-chroot $(gettext "Clean the chroot but skip home/ and root/.")
55 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
56 --login= $(gettext "Login name for add or del an user.")
57 --id= $(gettext "User id for adduser command.")
58 --pass= $(gettext "User password for adduser.")
59 --root= $(gettext "The path to the Ssfs chroot.")
61 EOT
62 }
64 status() {
65 [ $? = 0 ] && echo " OK"
66 [ $? = 1 ] && echo -e " ERROR\n" && exit 1
67 }
69 user_paths() {
70 config=$SSFS_USERS/$login.conf
71 home=$root/./home/$login
72 }
74 user_info() {
75 cat << EOT
77 $(gettext "User login :") $login
78 $(gettext "User quota :") $QUOTA
79 $(gettext "Home usage :") $usage
81 EOT
82 }
84 # Create a custom config when adding user to handle quota and user info.
85 user_config() {
86 gettext "Creating Ssfs user configuration file..."
87 cat > $config << EOT
88 # Ssfs user configuration file.
90 LOGIN="$login"
91 QUOTA="$DEFAULT_QUOTA"
92 EOT
93 chmod 0600 $config && status
94 echo ""
95 }
97 #
98 # Commands
99 #
101 case "$1" in
102 users)
103 gettext -e "\nChecking:"; echo " /etc/passwd"
104 fgrep "Ssfs User" /etc/passwd | while read line
105 do
106 login=$(echo $line | cut -d ":" -f 1)
107 home="$root/home/$login"
108 usage=$(du -sm $home | awk '{print $1}')
109 config=$SSFS_USERS/$login.conf
110 . $config || gettext -e "WARNING: No config file\n"
111 user_info
112 done
113 users=$(ls $SSFS_USERS | wc -l)
114 gettext "Users:"; echo -e " $users\n" ;;
115 adduser)
116 # Add a Ssfs user to the system with $HOME in chroot.
117 [ -z "$login" ] && gettext -e "Missing user login name.\n" && exit 0
118 [ -z "$id" ] && gettext -e "Missing user id.\n" && exit 0
119 [ -z "$pass" ] && gettext -e "Missing user password.\n" && exit 0
120 user_paths
122 gettext -e "\nChecking:"; echo " /etc/passwd"
123 if grep ^$login: /etc/passwd; then
124 gettext -e "Exiting user already exist:"
125 echo -e " $login\n" && exit 0
126 fi
127 gettext "Creating user: $login..."
128 echo -e "$pass\n$pass" | \
129 adduser -h "$home" -g "Ssfs User" -u $id $login >/dev/null
130 status
132 # We dont want any files from /etc/skel.
133 gettext "Cleaning home and creating: Sync/..."
134 rm -rf $home && mkdir -p $home/Sync && status
135 gettext "Changing mode on user home: 0700..."
136 chown -R $login.$login $home
137 chmod 0700 $home && status
139 # Create a custom config peer user in SSFS_USERS.
140 [ ! -d "$SSFS_USERS" ] && mkdir -p $SSFS_USERS
141 user_config ;;
142 deluser)
143 [ -z "$login" ] && gettext -e "Missing user login name.\n" && exit 0
144 user_paths
145 gettext -e "\nDeleting user:"; echo -n " $login..."
146 deluser $login || status && status
147 gettext "Removing all files in:"; echo -n " $home..."
148 rm -rf $home && status
149 gettext "Removing user config:"; echo -n " $login.conf..."
150 rm -rf $config && status
151 echo "" ;;
152 chroot)
153 gettext -e "\nChanging root to:"; echo -e " $root\n"
154 chroot $root
155 gettext -e "\nBack to the host system:"
156 echo -e " $(hostname)\n" ;;
157 gen-chroot)
158 # Generated a minimal chroot for Ssfs users home.
159 if [ -d "$root/bin" ]; then
160 gettext -e "A chroot already exist in:"; echo " $root"
161 exit 0
162 fi
163 gettext -e "\nCreating chroot in:"; echo " $root"
164 gettext "Installing SliTaz base files..."
165 yes | tazpkg get-install slitaz-base-files --root=$root >/dev/null
166 status
167 gettext "Installing Busybox..."
168 yes | tazpkg get-install busybox --root=$root >/dev/null
169 status
170 gettext "Cleaning Ssfs chroot..."
171 rm -f $root/init
172 status && echo "" ;;
173 clean-chroot)
174 # clean up the storage chroot.
175 if [ ! -d "$root/bin" ] || [ ! -d "$root/usr" ]; then
176 gettext -e "No chroot found in:"; echo " $root"
177 exit 0
178 fi
179 gettext -e "\nChanging directory to:"; echo " $root"
180 cd $root
181 for dir in *
182 do
183 size=$(du -sh $dir | awk '{print $1}')
184 case "$dir" in
185 home|root)
186 gettext "Skipping:"; echo " $dir $size *" ;;
187 *)
188 gettext "Removing:"; echo " $dir $size"
189 rm -rf $dir ;;
190 esac
191 done && echo "" ;;
192 *)
193 help ;;
194 esac
195 exit 0