slitaz-forge view tank/taztank @ rev 43

taztank: add up-www from tazdev and short option for commands
author Christophe Lincoln <pankso@slitaz.org>
date Wed Mar 30 23:07:16 2011 +0200 (2011-03-30)
parents 482a0e54ae16
children f9644aebc4a8
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 Display some Tank stats
18 backup Backup files and MySQL DB
19 chroot Move a user into a new chroot location
20 up-www Update website http://www.slitaz.org/
21 up-tank Update http://tank.slitaz.org/
22 up-people Update http://people.slitaz.org/
23 up-boot Update http://boot.slitaz.org/
24 up-stats Update Awstats statistics (run by cron)\n"
25 }
27 case "$1" in
28 stats|-s)
29 # Report some stats
30 clear
31 cat << EOF
33 Connected user
34 --------------
35 `who`
37 System usage
38 ------------
39 `df -h`
41 `free`
43 EOF
44 ;;
45 chroot|-c)
46 if [ -s $2/bin/sh ] && grep -qs $3: /etc/password ; then
47 grep -q ^chroot /etc/busybox.conf ||
48 echo 'chroot = ssx root.root' >> /etc/busybox.conf
49 [ -s /bin/chrootsh ] || cat > /bin/chrootsh << EOF
50 #!/bin/sh
52 #case " \$@ " in
53 #*rsync*) exec /bin/sh "\$@" ;;
54 #esac
56 case "\$USER" in
57 pankso) exec /bin/sh "\$@" ;;
58 *) exec /usr/sbin/chroot $2 /bin/chrootsh "\$@" ;;
59 esac
60 EOF
61 [ -s $2/bin/chrootsh ] || cat > $2/bin/chrootsh << EOF
62 #!/bin/sh
64 export SHELL='/bin/sh'
65 cd \$HOME
66 . /etc/profile
67 exec /bin/sh "\$@"
68 EOF
69 chmod +x /bin/chrootsh $2/bin/chrootsh
70 base=$(awk -F: "/^$3:/ { print \$6 }" /etc/passwd)
71 target=$base
72 while [ -L $target ]; do
73 target=$(readlink $target)
74 done
75 mv $target $2/$base
76 [ -L $base ] && rm -f $base
77 ln -s $2/$base $base
78 if ! grep -q ^$3: $2/etc/passwd ; then
79 grep ^$3: /etc/passwd >> $2/etc/passwd
80 grep ^$3: /etc/shadow >> $2/etc/shadow fi
81 fi
82 else
83 cat << EOF
84 Usage: $0 $1 newchroot user
85 Move a user in a new chroot location
86 EOF
87 fi
88 ;;
89 backup|-b)
90 # Backup config files and SQL db.
91 echo "Not yet implemented..." ;;
92 update-www|-uw)
93 # Update website from repo.
94 echo ""
95 cd $WEBSITE && hg pull && hg update
96 echo "" ;;
97 up-tank|-ut)
98 # Update Tank web interface: http://tank.slitaz.org/
99 echo -e "\nUpdating: tank.slitaz.org..."
100 cd $REPOS/slitaz-forge
101 hg update
102 rm -rf $VHOST/*.* $VHOST/pics/website $VHOST/images
103 cp -a tank/web/* $VHOST ;;
104 up-people|-up)
105 # Update People web interface: http://people.slitaz.org/
106 echo -e "\nUpdating: people.slitaz.org..."
107 cd $REPOS/slitaz-forge
108 hg update
109 rm -rf $WWW/people/*
110 cp -a people/* $WWW/people ;;
111 up-boot|-ub)
112 # Update Web Boot interface: http://boot.slitaz.org/
113 echo -e "\nUpdating: boot.slitaz.org..."
114 cd $REPOS/slitaz-forge
115 hg update
116 rm -rf $WWW/boot/*
117 cp -a boot/* $WWW/boot ;;
118 up-stats|-us)
119 echo -e "\nUpdating all awstats databases...\n"
120 for vh in www boot pkgs
121 do
122 /var/www/cgi-bin/awstats.pl -config=$vh.slitaz.org
123 done ;;
124 *)
125 usage ;;
126 esac
127 exit 0