slitaz-forge view tank/tank @ rev 68

tank: Add up-hg to update mercurial style from repo
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 14 21:14:28 2011 +0200 (2011-04-14)
parents 0c67d68f4c81
children f6540bc2b336
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-hg|-uh Update template for http://hg.slitaz.org/
25 up-stats|-us Update Awstats statistics (run by cron)
26 adduser|-au Add user on tank\n"
27 }
29 case "$1" in
30 stats|-s)
31 # Report some stats
32 clear
33 cat << EOF
35 Connected user
36 --------------
37 `who`
39 System usage
40 ------------
41 `df -h`
43 `free`
45 EOF
46 ;;
47 chroot|-c)
48 # Move a user into a new chroot location
49 if [ -s $2/bin/sh ] && grep -qs $3: /etc/password ; then
50 grep -q ^chroot /etc/busybox.conf ||
51 echo 'chroot = ssx root.root' >> /etc/busybox.conf
52 [ -s /bin/chrootsh ] || cat > /bin/chrootsh << EOF
53 #!/bin/sh
55 #case " \$@ " in
56 #*rsync*) exec /bin/sh "\$@" ;;
57 #esac
59 case "\$USER" in
60 pankso) exec /bin/sh "\$@" ;;
61 *) exec /usr/sbin/chroot $2 /bin/chrootsh "\$@" ;;
62 esac
63 EOF
64 [ -s $2/bin/chrootsh ] || cat > $2/bin/chrootsh << EOF
65 #!/bin/sh
67 export SHELL='/bin/sh'
68 cd \$HOME
69 . /etc/profile
70 exec /bin/sh "\$@"
71 EOF
72 chmod +x /bin/chrootsh $2/bin/chrootsh
73 base=$(awk -F: "/^$3:/ { print \$6 }" /etc/passwd)
74 target=$base
75 while [ -L $target ]; do
76 target=$(readlink $target)
77 done
78 mv $target $2/$base
79 [ -L $base ] && rm -f $base
80 ln -s $2/$base $base
81 if ! grep -q ^$3: $2/etc/passwd ; then
82 grep ^$3: /etc/passwd >> $2/etc/passwd
83 grep ^$3: /etc/shadow >> $2/etc/shadow fi
84 fi
85 else
86 cat << EOF
87 Usage: $0 $1 newchroot user
88 Move a user in a new chroot location
89 EOF
90 fi ;;
91 backup|-b)
92 # Backup config files and SQL db.
93 echo "TODO" ;;
94 up-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-hg|-uh)
124 # Since Tank run stable and we update the style in slitaz-dev-tools
125 # the cooking package is unbuildable because it use new Tazwok function
126 # with mercurial|*
127 PYTHON_LIB="/usr/lib/python2.5"
128 echo -e "\nUpdating Mercurial style..."
129 cd $REPOS/slitaz-dev-tools && hg up
130 cp -a slitaz-mercurial-style/* $PYTHON_LIB/site-packages/mercurial
131 chown -R root.root $PYTHON_LIB/site-packages/mercurial/templates
132 echo "" ;;
133 up-stats|-us)
134 echo -e "\nUpdating all awstats databases..."
135 for vh in www boot pkgs
136 do
137 /var/www/cgi-bin/awstats.pl -config=$vh.slitaz.org
138 done
139 echo "" ;;
140 adduser|-au)
141 # On Tank /etc/skel is empty to let taktank handle default user
142 # files.
143 echo ""
144 if [ -n "$2" ]; then
145 user=$2
146 else
147 echo -n "User name: " && read user
148 fi
149 if [ -d /home/$user ]; then
150 echo -e "User $user already exists...\n" && exit 1
151 fi
152 echo "Adding user: $user"
153 #adduser -s /bin/sh -g "SliTaz User" -G users -h /home/$user $user # for cooking
154 adduser $user
155 # HG access
156 echo -n "Hg password: " && read passwd
157 echo "$user:$passwd" >> /etc/lighttpd/plain.passwd
158 # Public dir at http://people.slitaz.org/~$user/
159 cp -a /usr/share/tank/Public /home/$user/Public
160 sed -i s/'%user%'/"$user"/ /home/$user/Public/index.html
161 # README and empty Shell profile
162 cp -a /usr/share/tank/README /home/$user/
163 cat > /home/$user/.profile << EOF
164 # ~/.profile: Executed by Bourne-compatible login SHells.
165 #
166 EOF
167 chown -R $user.$user /home/$user
168 echo -e "Done\n" ;;
169 *)
170 usage ;;
171 esac
172 exit 0