slitaz-forge view tank/taztank @ rev 45

taztank: add command adduser to create new users on tank
author Christophe Lincoln <pankso@slitaz.org>
date Thu Mar 31 00:05:06 2011 +0200 (2011-03-31)
parents f9644aebc4a8
children 444d36a84ce8
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 # Move a user into a new chroot location
47 if [ -s $2/bin/sh ] && grep -qs $3: /etc/password ; then
48 grep -q ^chroot /etc/busybox.conf ||
49 echo 'chroot = ssx root.root' >> /etc/busybox.conf
50 [ -s /bin/chrootsh ] || cat > /bin/chrootsh << EOF
51 #!/bin/sh
53 #case " \$@ " in
54 #*rsync*) exec /bin/sh "\$@" ;;
55 #esac
57 case "\$USER" in
58 pankso) exec /bin/sh "\$@" ;;
59 *) exec /usr/sbin/chroot $2 /bin/chrootsh "\$@" ;;
60 esac
61 EOF
62 [ -s $2/bin/chrootsh ] || cat > $2/bin/chrootsh << EOF
63 #!/bin/sh
65 export SHELL='/bin/sh'
66 cd \$HOME
67 . /etc/profile
68 exec /bin/sh "\$@"
69 EOF
70 chmod +x /bin/chrootsh $2/bin/chrootsh
71 base=$(awk -F: "/^$3:/ { print \$6 }" /etc/passwd)
72 target=$base
73 while [ -L $target ]; do
74 target=$(readlink $target)
75 done
76 mv $target $2/$base
77 [ -L $base ] && rm -f $base
78 ln -s $2/$base $base
79 if ! grep -q ^$3: $2/etc/passwd ; then
80 grep ^$3: /etc/passwd >> $2/etc/passwd
81 grep ^$3: /etc/shadow >> $2/etc/shadow fi
82 fi
83 else
84 cat << EOF
85 Usage: $0 $1 newchroot user
86 Move a user in a new chroot location
87 EOF
88 fi
89 ;;
90 backup|-b)
91 # Backup config files and SQL db.
92 echo "Not yet implemented..." ;;
93 update-www|-uw)
94 # Update website from repo.
95 echo -e "\nUpdating: www.slitaz.org..."
96 cd $WEBSITE && hg pull && hg update
97 echo "" ;;
98 up-tank|-ut)
99 # Update Tank web interface: http://tank.slitaz.org/
100 echo -e "\nUpdating: tank.slitaz.org..."
101 cd $REPOS/slitaz-forge
102 hg update
103 rm -rf $VHOST/*.* $VHOST/pics/website $VHOST/images
104 cp -a tank/web/* $VHOST
105 echo "" ;;
106 up-people|-up)
107 # Update People web interface: http://people.slitaz.org/
108 echo -e "\nUpdating: people.slitaz.org..."
109 cd $REPOS/slitaz-forge
110 hg update
111 rm -rf $WWW/people/*
112 cp -a people/* $WWW/people
113 echo "" ;;
114 up-boot|-ub)
115 # Update Web Boot interface: http://boot.slitaz.org/
116 echo -e "\nUpdating: boot.slitaz.org..."
117 cd $REPOS/slitaz-forge
118 hg update
119 rm -rf $WWW/boot/*
120 cp -a boot/* $WWW/boot
121 echo "" ;;
122 up-stats|-us)
123 echo -e "\nUpdating all awstats databases..."
124 for vh in www boot pkgs
125 do
126 /var/www/cgi-bin/awstats.pl -config=$vh.slitaz.org
127 done
128 echo "" ;;
129 adduser|-au)
130 # On Tank /etc/skel is empty to let taktank handle default user
131 # files.
132 echo ""
133 if [ -n "$2" ]; then
134 user=$2
135 else
136 echo -n "User name: " && read user
137 fi
138 if [ -d /home/$user ]; then
139 echo -e "User $user already exist...\n" && exit 1
140 fi
141 echo "Adding user: $user"
142 adduser $user
143 # HG access
144 echo -n "Hg password: " && read passwd
145 echo "$user:$passwd" >> /etc/lighttpd/plain.passwd
146 # README
147 echo -n "Creating default user files... "
148 cat > /home/$user/README << EOF
149 Welcome to Tank!
150 ================================================================================
152 Your Public directory URL is: http://people.slitaz.org/~$USER/
154 Please complet your public profile in ~/Public/profile.php and feel free
155 to use the service for your needs, if any thing goes wrong or is missing
156 please express your self :-)
158 EOF
159 # Public profile
160 mkdir -p /home/$user/Public
161 cat > /home/$user/Public/profile.php << EOF
162 <?php
164 // Your custom SliTaz profile at http://people.slitaz.org/. This file must
165 // be located at ~/Public/profile.php. You must at least provide your real
166 // name and you can use the $wall variable for a personnal message.
168 $name = "Real Name";
169 $location = "";
170 $scn_user = "";
171 $skills = "";
172 $wall = "";
174 ?>
175 EOF
176 # Shell profile
177 cat > /home/$user/.profile << EOF
178 # ~/.profile: Executed by Bourne-compatible login SHells.
179 #
180 EOF
181 echo -e "Done\n" ;;
182 *)
183 usage ;;
184 esac
185 exit 0