slitaz-forge view tank/taztank @ rev 35

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sun Mar 06 17:29:20 2011 +0000 (2011-03-06)
parents 5dbbf86c3bc0
children 482a0e54ae16
line source
1 #!/bin/sh
2 # Taztank - Admin Tank, backup, update and give stats.
3 # (C) 2011 SliTaz - GNU General Public License.
4 # Author: Christophe Lincoln <pankso@slitaz.org>
5 #
7 REPOS="/home/slitaz/repos"
8 WWW="/home/slitaz/www"
9 VHOST="$WWW/tank"
10 BACKUPS="/home/backups"
12 usage() {
13 echo -e "\nUsage: `basename $0` [command]
14 Commands:
15 stats Display some Tank stats
16 backup Backup files and MySQL DB
17 chroot Move a user into a new chroot location
18 up-web Update http://tank.slitaz.org/
19 up-people Update http://people.slitaz.org/
20 up-web-stats Update Awstats statistics (run by cron)
21 clean-labs Clean Redmine Labs (no longer on Tank)\n"
22 }
24 case "$1" in
25 stats)
26 # Report some stats
27 clear
28 cat << EOF
30 Connected user
31 --------------
32 `who`
34 System usage
35 ------------
36 `df -h`
38 `free`
40 EOF
41 ;;
42 chroot)
43 if [ -s $2/bin/sh ] && grep -qs $3: /etc/password ; then
44 grep -q ^chroot /etc/busybox.conf ||
45 echo 'chroot = ssx root.root' >> /etc/busybox.conf
46 [ -s /bin/chrootsh ] || cat > /bin/chrootsh << EOF
47 #!/bin/sh
49 #case " \$@ " in
50 #*rsync*) exec /bin/sh "\$@" ;;
51 #esac
53 case "\$USER" in
54 pankso) exec /bin/sh "\$@" ;;
55 *) exec /usr/sbin/chroot $2 /bin/chrootsh "\$@" ;;
56 esac
57 EOF
58 [ -s $2/bin/chrootsh ] || cat > $2/bin/chrootsh << EOF
59 #!/bin/sh
61 export SHELL='/bin/sh'
62 cd \$HOME
63 . /etc/profile
64 exec /bin/sh "\$@"
65 EOF
66 chmod +x /bin/chrootsh $2/bin/chrootsh
67 base=$(awk -F: "/^$3:/ { print \$6 }" /etc/passwd)
68 target=$base
69 while [ -L $target ]; do
70 target=$(readlink $target)
71 done
72 mv $target $2/$base
73 [ -L $base ] && rm -f $base
74 ln -s $2/$base $base
75 if ! grep -q ^$3: $2/etc/passwd ; then
76 grep ^$3: /etc/passwd >> $2/etc/passwd
77 grep ^$3: /etc/shadow >> $2/etc/shadow fi
78 fi
79 else
80 cat << EOF
81 Usage: $0 $1 newchroot user
82 Move a user in a new chroot location
83 EOF
84 fi
85 ;;
86 backup)
87 # Backup config files and SQL db.
88 echo "Not yet implemented..." ;;
89 up-web)
90 # Update Tank web interface: http://tank.slitaz.org/
91 echo -e "\nUpdating: tank.slitaz.org..."
92 cd $REPOS/tank
93 hg update
94 rm -rf $VHOST/*.* $VHOST/pics/website
95 cp -a web/* $VHOST ;;
96 up-people)
97 # Update People web interface: http://people.slitaz.org/
98 echo -e "\nUpdating: people.slitaz.org..."
99 cd $REPOS/slitaz-forge
100 hg update
101 rm -rf $WWW/people/*
102 cp -a people/* $WWW/people ;;
103 up-web-stats)
104 echo -e "\nUpdating all awstats databases...\n"
105 for vh in www boot pkgs
106 do
107 /var/www/cgi-bin/awstats.pl -config=$vh.slitaz.org
108 done ;;
109 clean-labs)
110 # Redmin needs some time help
111 /etc/init.d/lighttpd stop
112 /etc/init.d/mysql stop
113 killall ruby
114 rm -rf labs/tmp/sessions
115 mkdir -p labs/tmp/sessions
116 chown www.www labs/tmp/sessions
117 /etc/init.d/mysql start
118 /etc/init.d/lighttpd start ;;
119 *)
120 usage ;;
121 esac
122 exit 0