slitaz-forge view tank/taztank @ rev 46

Update usage in taztank script.
author Christopher Rogers <slaxemulator@gmail.com>
date Sun Apr 03 00:01:32 2011 +0000 (2011-04-03)
parents 1e164894a3ed
children f80f311578f7
line source
1 #!/bin/sh
2 # Taztank - Admin Tank, backup, update and give stats.
3 #
4 # (C) 2011 SliTaz - GNU General Public License.
5 # Author: Christophe Lincoln <pankso@slitaz.org>
6 #
8 REPOS="/home/slitaz/repos"
9 WWW="/home/slitaz/www"
10 VHOST="$WWW/tank"
11 WEBSITE="$WWW/website"
12 BACKUPS="/home/backups"
14 usage() {
15 echo -e "\nUsage: `basename $0` [command]
16 Commands:
17 stats|-s Display some Tank stats
18 backup|-b Backup files and MySQL DB
19 chroot|-c Move a user into a new chroot location
20 up-www|-uw Update website http://www.slitaz.org/
21 up-tank|-ut Update http://tank.slitaz.org/
22 up-people|-up Update http://people.slitaz.org/
23 up-boot|-ub Update http://boot.slitaz.org/
24 up-stats|-us Update Awstats statistics (run by cron)
25 adduser|-au Add user on tank\n"
26 }
28 case "$1" in
29 stats|-s)
30 # Report some stats
31 clear
32 cat << EOF
34 Connected user
35 --------------
36 `who`
38 System usage
39 ------------
40 `df -h`
42 `free`
44 EOF
45 ;;
46 chroot|-c)
47 # Move a user into a new chroot location
48 if [ -s $2/bin/sh ] && grep -qs $3: /etc/password ; then
49 grep -q ^chroot /etc/busybox.conf ||
50 echo 'chroot = ssx root.root' >> /etc/busybox.conf
51 [ -s /bin/chrootsh ] || cat > /bin/chrootsh << EOF
52 #!/bin/sh
54 #case " \$@ " in
55 #*rsync*) exec /bin/sh "\$@" ;;
56 #esac
58 case "\$USER" in
59 pankso) exec /bin/sh "\$@" ;;
60 *) exec /usr/sbin/chroot $2 /bin/chrootsh "\$@" ;;
61 esac
62 EOF
63 [ -s $2/bin/chrootsh ] || cat > $2/bin/chrootsh << EOF
64 #!/bin/sh
66 export SHELL='/bin/sh'
67 cd \$HOME
68 . /etc/profile
69 exec /bin/sh "\$@"
70 EOF
71 chmod +x /bin/chrootsh $2/bin/chrootsh
72 base=$(awk -F: "/^$3:/ { print \$6 }" /etc/passwd)
73 target=$base
74 while [ -L $target ]; do
75 target=$(readlink $target)
76 done
77 mv $target $2/$base
78 [ -L $base ] && rm -f $base
79 ln -s $2/$base $base
80 if ! grep -q ^$3: $2/etc/passwd ; then
81 grep ^$3: /etc/passwd >> $2/etc/passwd
82 grep ^$3: /etc/shadow >> $2/etc/shadow fi
83 fi
84 else
85 cat << EOF
86 Usage: $0 $1 newchroot user
87 Move a user in a new chroot location
88 EOF
89 fi
90 ;;
91 backup|-b)
92 # Backup config files and SQL db.
93 echo "Not yet implemented..." ;;
94 update-www|-uw)
95 # Update website from repo.
96 echo -e "\nUpdating: www.slitaz.org..."
97 cd $WEBSITE && hg pull && hg update
98 echo "" ;;
99 up-tank|-ut)
100 # Update Tank web interface: http://tank.slitaz.org/
101 echo -e "\nUpdating: tank.slitaz.org..."
102 cd $REPOS/slitaz-forge
103 hg update
104 rm -rf $VHOST/*.* $VHOST/pics/website $VHOST/images
105 cp -a tank/web/* $VHOST
106 echo "" ;;
107 up-people|-up)
108 # Update People web interface: http://people.slitaz.org/
109 echo -e "\nUpdating: people.slitaz.org..."
110 cd $REPOS/slitaz-forge
111 hg update
112 rm -rf $WWW/people/*
113 cp -a people/* $WWW/people
114 echo "" ;;
115 up-boot|-ub)
116 # Update Web Boot interface: http://boot.slitaz.org/
117 echo -e "\nUpdating: boot.slitaz.org..."
118 cd $REPOS/slitaz-forge
119 hg update
120 rm -rf $WWW/boot/*
121 cp -a boot/* $WWW/boot
122 echo "" ;;
123 up-stats|-us)
124 echo -e "\nUpdating all awstats databases..."
125 for vh in www boot pkgs
126 do
127 /var/www/cgi-bin/awstats.pl -config=$vh.slitaz.org
128 done
129 echo "" ;;
130 adduser|-au)
131 # On Tank /etc/skel is empty to let taktank handle default user
132 # files.
133 echo ""
134 if [ -n "$2" ]; then
135 user=$2
136 else
137 echo -n "User name: " && read user
138 fi
139 if [ -d /home/$user ]; then
140 echo -e "User $user already exist...\n" && exit 1
141 fi
142 echo "Adding user: $user"
143 adduser $user
144 # HG access
145 echo -n "Hg password: " && read passwd
146 echo "$user:$passwd" >> /etc/lighttpd/plain.passwd
147 # README
148 echo -n "Creating default user files... "
149 cat > /home/$user/README << EOF
150 Welcome to Tank!
151 ================================================================================
153 Your Public directory URL is: http://people.slitaz.org/~$USER/
155 Please complet your public profile in ~/Public/profile.php and feel free
156 to use the service for your needs, if any thing goes wrong or is missing
157 please express your self :-)
159 EOF
160 # Public profile
161 mkdir -p /home/$user/Public
162 cat > /home/$user/Public/profile.php << EOF
163 <?php
165 // Your custom SliTaz profile at http://people.slitaz.org/. This file must
166 // be located at ~/Public/profile.php. You must at least provide your real
167 // name and you can use the $wall variable for a personnal message.
169 $name = "Real Name";
170 $location = "";
171 $scn_user = "";
172 $skills = "";
173 $wall = "";
175 ?>
176 EOF
177 # Shell profile
178 cat > /home/$user/.profile << EOF
179 # ~/.profile: Executed by Bourne-compatible login SHells.
180 #
181 EOF
182 echo -e "Done\n" ;;
183 *)
184 usage ;;
185 esac
186 exit 0