slitaz-forge view tank/tank @ rev 73

Tiny edits
author Paul Issott <paul@slitaz.org>
date Thu Apr 14 20:59:10 2011 +0100 (2011-04-14)
parents ed64984a8f9a
children 893e0399ab12
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"
13 PYTHON_LIB="/usr/lib/python2.5"
14 DOC_LIB="$WWW/doc/lib"
16 usage() {
17 echo -e "\nUsage: `basename $0` [command]
18 Commands:
19 stats|-s Display some Tank stats
20 backup|-b Backup files and MySQL DB
21 chroot|-c Move a user into a new chroot location
22 up-www|-uw Update website http://www.slitaz.org/
23 up-tank|-ut Update http://tank.slitaz.org/
24 up-people|-up Update http://people.slitaz.org/
25 up-boot|-ub Update http://boot.slitaz.org/
26 up-hg|-uh Update template for http://hg.slitaz.org/
27 up-doc|-ud Update template for http://doc.slitaz.org/
28 up-stats|-us Update Awstats statistics (run by cron)
29 adduser|-au Add user on tank\n"
30 }
32 case "$1" in
33 stats|-s)
34 # Report some stats
35 clear
36 cat << EOF
38 Connected user
39 --------------
40 `who`
42 System usage
43 ------------
44 `df -h`
46 `free`
48 EOF
49 ;;
50 chroot|-c)
51 # Move a user into a new chroot location
52 if [ -s $2/bin/sh ] && grep -qs $3: /etc/password ; then
53 grep -q ^chroot /etc/busybox.conf ||
54 echo 'chroot = ssx root.root' >> /etc/busybox.conf
55 [ -s /bin/chrootsh ] || cat > /bin/chrootsh << EOF
56 #!/bin/sh
58 #case " \$@ " in
59 #*rsync*) exec /bin/sh "\$@" ;;
60 #esac
62 case "\$USER" in
63 pankso) exec /bin/sh "\$@" ;;
64 *) exec /usr/sbin/chroot $2 /bin/chrootsh "\$@" ;;
65 esac
66 EOF
67 [ -s $2/bin/chrootsh ] || cat > $2/bin/chrootsh << EOF
68 #!/bin/sh
70 export SHELL='/bin/sh'
71 cd \$HOME
72 . /etc/profile
73 exec /bin/sh "\$@"
74 EOF
75 chmod +x /bin/chrootsh $2/bin/chrootsh
76 base=$(awk -F: "/^$3:/ { print \$6 }" /etc/passwd)
77 target=$base
78 while [ -L $target ]; do
79 target=$(readlink $target)
80 done
81 mv $target $2/$base
82 [ -L $base ] && rm -f $base
83 ln -s $2/$base $base
84 if ! grep -q ^$3: $2/etc/passwd ; then
85 grep ^$3: /etc/passwd >> $2/etc/passwd
86 grep ^$3: /etc/shadow >> $2/etc/shadow fi
87 fi
88 else
89 cat << EOF
90 Usage: $0 $1 newchroot user
91 Move a user in a new chroot location
92 EOF
93 fi ;;
94 backup|-b)
95 # Backup config files and SQL db.
96 echo "TODO" ;;
97 up-www|-uw)
98 # Update website from repo.
99 echo -e "\nUpdating: www.slitaz.org..."
100 cd $WEBSITE && hg pull && hg update
101 echo "" ;;
102 up-tank|-ut)
103 # Update Tank web interface: http://tank.slitaz.org/
104 echo -e "\nUpdating: tank.slitaz.org..."
105 cd $REPOS/slitaz-forge
106 hg update
107 rm -rf $VHOST/*.* $VHOST/pics/website $VHOST/images
108 cp -a tank/web/* $VHOST
109 echo "" ;;
110 up-people|-up)
111 # Update People web interface: http://people.slitaz.org/
112 echo -e "\nUpdating: people.slitaz.org..."
113 cd $REPOS/slitaz-forge
114 hg update
115 rm -rf $WWW/people/*
116 cp -a people/* $WWW/people
117 echo "" ;;
118 up-boot|-ub)
119 # Update Web Boot interface: http://boot.slitaz.org/
120 echo -e "\nUpdating: boot.slitaz.org..."
121 cd $REPOS/slitaz-forge
122 hg update
123 rm -rf $WWW/boot/*
124 cp -a boot/* $WWW/boot
125 echo "" ;;
126 up-hg|-uh)
127 # Since Tank runs stable and we update the style in slitaz-dev-tools
128 # the cooking package is unbuildable because it uses the new Tazwok function
129 # with mercurial|*
130 echo -e "\nUpdating Mercurial template..."
131 cd $REPOS/slitaz-dev-tools && hg up
132 cp -a slitaz-mercurial-style/* $PYTHON_LIB/site-packages/mercurial
133 chown -R root.root $PYTHON_LIB/site-packages/mercurial/templates
134 echo "" ;;
135 up-doc|-ud)
136 # Update Wiki doc template from Hg: http://doc.slitaz.org/
137 echo -e "\nUpdating Wiki documentation template..."
138 cd $REPOS/slitaz-forge && hg up
139 cp -a doc/lib/tpl/* $DOC_LIB/tpl
140 echo "" ;;
141 up-stats|-us)
142 echo -e "\nUpdating all awstats databases..."
143 for vh in www boot pkgs
144 do
145 /var/www/cgi-bin/awstats.pl -config=$vh.slitaz.org
146 done
147 echo "" ;;
148 adduser|-au)
149 # On Tank /etc/skel is empty to let tank handle default user
150 # files.
151 echo ""
152 if [ -n "$2" ]; then
153 user=$2
154 else
155 echo -n "User name: " && read user
156 fi
157 if [ -d /home/$user ]; then
158 echo -e "User $user already exists...\n" && exit 1
159 fi
160 echo "Adding user: $user"
161 # adduser -s /bin/sh -g "SliTaz User" -G users -h /home/$user $user # for cooking
162 adduser $user
163 # HG access
164 echo -n "Hg password: " && read passwd
165 echo "$user:$passwd" >> /etc/lighttpd/plain.passwd
166 # Public dir at http://people.slitaz.org/~$user/
167 cp -a /usr/share/tank/Public /home/$user/Public
168 sed -i s/'%user%'/"$user"/ /home/$user/Public/index.html
169 # README and empty Shell profile
170 cp -a /usr/share/tank/README /home/$user/
171 cat > /home/$user/.profile << EOF
172 # ~/.profile: Executed by Bourne-compatible login SHells.
173 #
174 EOF
175 chown -R $user.$user /home/$user
176 echo -e "Done\n" ;;
177 *)
178 usage ;;
179 esac
180 exit 0