slitaz-forge view tank/tank @ rev 567

tank: fix new user
author Christophe Lincoln <pankso@slitaz.org>
date Sun Jun 22 11:53:03 2014 +0200 (2014-06-22)
parents 22f4af7fa6f8
children 0f1e69658f38
line source
1 #!/bin/sh
2 #
3 # Tank - Admin Tank, backup, update and give stats.
4 #
5 # (C) 2012-2014 SliTaz - GNU General Public License.
6 # Author: Christophe Lincoln <pankso@slitaz.org>
7 #
8 . /lib/libtaz.sh
10 REPOS="/home/slitaz/repos"
11 WWW="/home/slitaz/www"
12 VHOST="$WWW/tank"
13 WEBSITE="$WWW/website"
14 BACKUPS="/home/backups"
15 LOGFILE="/var/log/tank.log"
17 usage() {
18 cat << EOT
20 Usage: $(basename $0) [command]
21 Commands:
22 backup|-b Backup files and MySQL DB
23 adduser Add user on Tank and create people files
24 up-stats Update Awstats statistics (run by cron)
25 online Show online users
27 up-tank Update http://tank.slitaz.org/
28 up-people Update http://people.slitaz.org/
29 up-pro Update http://pro.slitaz.org/
30 up-boot Update http://boot.slitaz.org/
31 up-cook Update http://cook.slitaz.org/
32 up-roadmap Update http://roadmap.slitaz.org/
33 up-bugs Update http://bugs.slitaz.org/
34 up-irc Update http://irc.slitaz.org/
35 up-arm Update http://arm.slitaz.org/
36 up-piclass Update http://piclass.org/
38 EOT
39 }
41 case "$1" in
42 backup|-b)
43 # Backup config files and SQL db.
44 echo "TODO" ;;
45 up-tank)
46 # Update Tank web interface
47 echo -e "\nUpdating: tank.slitaz.org..."
48 cd $REPOS/slitaz-forge
49 [ "$2" == "--nohg" ] || hg pull -u
50 rm -rf $VHOST/*.* $VHOST/images
51 cp -a tank/web/* $VHOST
52 echo "" ;;
53 up-people)
54 # Update People web interface
55 echo -e "\nUpdating: people.slitaz.org..."
56 cd $REPOS/slitaz-forge
57 [ "$2" == "--nohg" ] || hg pull -u
58 rm -rf $WWW/people/*
59 cp -a people/* $WWW/people
60 echo "" ;;
61 up-pro)
62 # Update Pro website
63 echo -e "\nUpdating: pro.slitaz.org..."
64 cd $REPOS/slitaz-forge
65 [ "$2" == "--nohg" ] || hg pull -u
66 rm -rf $WWW/pro/web/*
67 cp -a pro/* $WWW/pro/web
68 echo "" ;;
69 up-boot)
70 # Update Web Boot interface
71 echo -e "\nUpdating: boot.slitaz.org..."
72 cd $REPOS/slitaz-forge
73 [ "$2" == "--nohg" ] || hg pull -u
74 rm -rf $WWW/boot/*
75 cp -a boot/* $WWW/boot
76 echo "" ;;
77 up-cook)
78 # Update Web Boot interface
79 echo -e "\nUpdating: cook.slitaz.org..."
80 cd $REPOS/cookutils
81 [ "$2" == "--nohg" ] || hg pull -u
82 cd $REPOS/slitaz-forge
83 [ "$2" == "--nohg" ] || hg pull -u
84 cp -a cook/* $WWW/cook
85 # We use symlinks for cooker's
86 cd $WWW/cook && rm -f style.css
87 ln -s $REPOS/cookutils/web/style.css .
88 cd $WWW/cook/cross && rm -f style.css
89 ln -s $REPOS/cookutils/web/style.css .
90 for web in stable undigest backports cross/arm cross/x86_64
91 do
92 echo "Linking: $web CSS/CGI files"
93 cd $WWW/cook/$web
94 for file in style.css cooker.cgi cookiso.cgi
95 do
96 rm -f $file
97 ln -s $REPOS/cookutils/web/$file .
98 done
99 # header.html
100 echo "Linking: $web/header.html"
101 rm -f header.html
102 ln -s ../header.html .
103 done
105 # No ISO's for undigest and ARM.
106 rm -f \
107 $WWW/cook/undigest/cookiso.cgi \
108 $WWW/cook/cross/arm/cookiso.cgi
109 echo "" ;;
110 up-roadmap)
111 # Update Roadmap Web interface
112 echo -e "\nUpdating: roadmap.slitaz.org..."
113 cd $REPOS/slitaz-forge
114 [ "$2" == "--nohg" ] || hg pull -u
115 cp -a roadmap/* $WWW/roadmap
116 echo "" ;;
117 up-bugs)
118 # Update Bugs Web interface
119 bugs="$WWW/bugs"
120 echo -e "\nUpdating: bugs.slitaz.org..."
121 cd $REPOS/tazbug
122 [ "$2" == "--nohg" ] || hg pull -u
123 cp -a web/* ${bugs}
124 cp README ${bugs}
125 chown -R www.www ${bugs}
126 echo "" ;;
127 up-irc)
128 # Update IRC interface
129 echo -e "\nUpdating: irc.slitaz.org..."
130 cd $REPOS/slitaz-forge
131 [ "$2" == "--nohg" ] || hg pull -u
132 rm -rf $WWW/irc/images $WWW/irc/lib
133 cp -a irc/* $WWW/irc
134 echo "" ;;
135 up-arm)
136 # Update ARM Web interface
137 echo -e "\nUpdating: arm.slitaz.org..."
138 cd $REPOS/slitaz-forge && hg pull -u
139 cp -a arm/* $WWW/arm
140 echo "Updating: slitaz-arm Hg repo..."
141 cd $REPOS/slitaz-arm && hg pull -u
142 echo "" ;;
143 up-piclass)
144 # Update piclass.org
145 echo -e "\nUpdating: piclass.org..."
146 cd /home/piclass/website
147 git pull && echo "" ;;
148 up-stats)
149 echo -e "\nUpdating all awstats databases..." | tee -a $LOGFILE
150 date >> $LOGFILE
151 for vh in pro boot cook people tank
152 do
153 /var/www/cgi-bin/awstats.pl \
154 -config=$vh.slitaz.org -update 2>&1 | tee -a $LOGFILE
155 done && echo "" ;;
156 adduser)
157 echo ""
158 if [ -n "$2" ]; then
159 user=$2
160 else
161 echo -n "User name: " && read user
162 fi
163 if [ -d /home/$user ]; then
164 echo -e "User $user already exists...\n" && exit 1
165 fi
166 if [ -n "$3" ]; then
167 gecos="$3"
168 else
169 echo -n "Real name: " && read name
170 fi
171 if [ -n "$4" ]; then
172 pass=$4
173 else
174 echo -n "Password: " && read pass
175 fi
176 echo "Adding user: $user"
177 adduser -D -g "$gecos" $user -G users
178 echo $user:$pass | chpasswd --md5
179 addgroup $user slitaz
180 # HG access
181 #echo "$user:$pass" >> /etc/lighttpd/plain.passwd
182 # Public dir at http://people.slitaz.org/~$user/
183 sed -i s/'%user%'/"$user"/ /home/$user/Public/index.html
184 sed -i s/'%name%'/"$gecos"/ /home/$user/Public/profile.php
185 # Empty Shell profile
186 cat > /home/$user/.profile << EOF
187 # ~/.profile: Executed by Bourne-compatible login SHells.
188 #
189 EOF
190 #chown -R $user.$user /home/$user
191 echo -e "Done\n" ;;
192 online)
193 echo -n "Bugs online users: "
194 colorize 34 "$(ls /tmp/bugs/sessions | wc -l)" ;;
195 *)
196 usage ;;
197 esac
198 exit 0