flavors view proxy/rootfs/usr/bin/tazctl @ rev 158

Add Proxy (squid + sqduidclamav + SquidGuard + sarg)
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Thu Mar 15 00:56:34 2012 +0100 (2012-03-15)
parents
children b15932f93d49
line source
1 #!/bin/sh
2 # Tazadmin - SliTaz System Configuration
3 #
4 #
5 # Author : Eric Joseph-Alexandre (Erjo) <erjo@slitaz.org>
6 #
8 #export DIALOGRC=$PWD/rc/slackware.rc
10 VERSION=1.0
12 : ${DIALOG=dialog}
14 BACKTITLE="SliTaz Configuration Tools v.${VERSION}"
15 COMMAND=$1
16 LOG=/tmp/$(basename $0).log
17 OUT=/tmp/_retval_
18 DATADIR=/usr/share/slitaz-tools/tazadmin/
19 #DATADIR=./
21 BS="15 50"
23 # Messages language setting
24 # Switch to default English if $LANG.msg doesn't exist.
25 set_locale()
26 {
27 if [ -f ${LANG%%_*}.msg ]; then
28 . ${DATADIR}${LANG%%_*}.msg
29 fi
30 }
32 # use --msgbox.
33 # syntax: msg ["Title"] "Message text"
34 msg()
35 {
36 if [ $# -gt 1 ]; then
37 TITLE=$1
38 shift
39 MSG="$@"
40 else
41 MSG="$@"
42 fi
43 $DIALOG --title " ${TITLE:-Message} " \
44 --colors --backtitle "$BACKLIST" \
45 --clear --msgbox "\n$MSG" 0 0
46 }
48 # Exit install if user is not root.
49 check_root()
50 {
51 if test $(id -u) != 0 ; then
52 error_message "$ERR_CHK_ROOT"
53 exit 0
54 fi
55 }
57 # functions
58 #
59 trim(){
60 read LINE
61 echo $LINE
62 }
64 get_argc()
65 {
66 echo $#
67 }
72 get_hostname()
73 {
74 # Set hostname
75 HOSTNAME=$(cat /etc/hostname)
76 exec 3>&1
77 HOSTNAME=`$DIALOG --backtitle "$BACKTITLE" --title "Hostname" --clear \
78 --inputbox "Enter your computer hostname" $BS "${HOSTNAME}" 2>&1 1>&3`
79 ret=$?
80 exec 3>&-
81 # if $HOSTNAME is set we update /etc/hostname
82 # and change current hostname.
83 if [ ! -z ${HOSTNAME} ]; then
84 echo ${HOSTNAME} > /etc/hostname
85 hostname $(cat /etc/hostname)
86 fi
87 }
89 set_ip_adress()
90 {
91 # Set static configuration for Network.
92 . /etc/network.conf
93 exec 3>&1
94 IPCONFIG=`$DIALOG --ok-label "Submit" \
95 --backtitle "$backtitle" --extra-button --extra-label "${BTN_DHCP:-Use DHCP server}"\
96 --form "Here is a possible piece of a configuration program." \
97 15 55 0 \
98 "IP Adress:" 1 1 "$IP" 1 20 20 0 \
99 "Network mask:" 2 1 "$NETMASK" 2 20 20 0 \
100 "Default gateway:" 3 1 "$GATEWAY" 3 20 20 0 \
101 "DNS server(s):" 4 1 "$DNS_SERVER" 4 20 20 0 \
102 2>&1 1>&3`
103 ret=$?
104 exec 3>&-
106 case "$ret" in
107 0)
108 if [[ "`get_argc $IPCONFIG`" -gt "1" ]]; then
109 set_static_ip $IPCONFIG
110 else
111 msg "${ERR_BED_IP:-Invalid values.}"
112 fi
113 ;;
114 3)
115 get_dhcp_lease ;;
116 esac
117 }
119 get_dhcp_lease()
120 {
121 sed -i 's/DHCP=.*/DHCP="yes"/' /etc/network.conf
122 sed -i 's/STATIC=.*/STATIC="no"/' /etc/network.conf
123 /sbin/udhcpc -b -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid &
124 }
126 set_static_ip()
127 {
128 sed -i 's/DHCP=.*/DHCP="no"/' /etc/network.conf
129 sed -i 's/STATIC=.*/STATIC="yes"/' /etc/network.conf
130 sed -i -e "s/IP=".*"/IP=\"$1\"/" /etc/network.conf
131 sed -i -e "s/NETMASK=".*"/NETMASK=\"$2\"/" /etc/network.conf
132 sed -i -e "s/GATEWAY=".*"/GATEWAY=\"$3\"/" /etc/network.conf
133 sed -i -e "s/DNS_SERVER=".*"/DNS_SERVER=\"$4\"/" /etc/network.conf
134 }
136 network_menu()
137 {
138 ret=0
139 until [ $ret -eq 1 ];do
140 $DIALOG --title "$MENU_TITLE" \
141 --backtitle "$BACKTITLE" --clear \
142 --cancel-label "Quitter" \
143 --colors \
144 --menu "$TAZ_CMD_MSG" 15 50 40\
145 "adress" " Network settings" \
146 "hostname" " Set your hostname" \
147 2> $OUT
148 ret=$?
149 case `cat $OUT` in
150 hostname)
151 get_hostname ;;
152 adress)
153 set_ip_adress ;;
154 esac
155 done
156 }
158 set_password()
159 {
160 SEP='
161 '
162 exec 3>&1
163 PASSWORD=`$DIALOG --backtitle "$BACKTITLE" --title "Set password" --clear \
164 --separate-widget "$SEP" \
165 --insecure --passwordbox "Enter new password for user below: \n\n" 10 50 \
166 --title "Confirme password" \
167 --insecure --passwordbox "Confirme new password for user below: \n\n" 10 50 2>&1 1>&3`
168 ret=$?
169 exec 3>&-
170 if [ -z "${PASSWORD}" ]; then
171 msg "Password not set"
172 else
173 PASS1="$(echo $PASSWORD | cut -d ' ' -f1)"
174 PASS2="$(echo $PASSWORD | cut -d ' ' -f2)"
175 if [ "$PASS1" != "$PASS2" ]; then
176 msg "Passwords don't match.\nNothing change."
177 else
178 echo "root:$PASS1" | chpasswd
179 fi
180 fi
181 }
183 ##
184 # Program sequence
185 #
186 set_locale
187 check_root
189 until [ $retval -eq 1 ];do
190 $DIALOG --title "$MENU_TITLE" \
191 --backtitle "$BACKTITLE" --clear \
192 --cancel-label "Quitter" \
193 --colors \
194 --menu "$TAZ_CMD_MSG" 15 50 40\
195 "keymap" " Keyboard mapping" \
196 "locale" " Language setting" \
197 "network" " Netwok configuration" \
198 "password" " Change root password" \
199 2> $OUT
201 retval=$?
203 # Execute commands
204 #
205 case `cat $OUT` in
206 keymap)
207 if [ -x /sbin/tazkeymap ]; then
208 tazkeymap
209 else
210 msg "Unable to find tazkeymap !"
211 fi
212 ;;
213 locale)
214 if [ -x /sbin/tazlocale ]; then
215 tazlocale
216 else
217 msg "Unable to find tazlocale !"
218 fi
219 ;;
220 network)
221 network_menu;;
222 password)
223 set_password ;;
224 esac
225 done
227 exit 0