slitaz-vz view base-scripts/setup @ rev 5

Tiny edits
author Paul Issott <paul@slitaz.org>
date Mon Mar 26 21:42:12 2012 +0100 (2012-03-26)
parents 53a1af07cb88
children
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 "$BACKTITLE" \
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 --title " IP configuration " \
97 --form "Here is a possible piece of a configuration program." \
98 20 55 0 \
99 "Interface : " 1 1 "$INTERFACE" 1 21 20 0 \
100 "IP Address : " 2 1 "$IP" 2 21 20 0 \
101 "Network mask : " 3 1 "$NETMASK" 3 21 20 0 \
102 "Default gateway : " 4 1 "$GATEWAY" 4 21 20 0 \
103 "DNS server(s) : " 5 1 "$DNS_SERVER" 5 21 20 0 \
104 2>&1 1>&3`
105 ret=$?
106 exec 3>&-
108 case "$ret" in
109 0)
110 if [[ "`get_argc $IPCONFIG`" -gt "1" ]]; then
111 set_static_ip $IPCONFIG
112 else
113 msg "${ERR_BED_IP:-Invalid values.}"
114 fi
115 ;;
116 3)
117 get_dhcp_lease ;;
118 esac
119 }
121 get_dhcp_lease()
122 {
123 sed -i 's/DHCP=.*/DHCP="yes"/' /etc/network.conf
124 sed -i 's/STATIC=.*/STATIC="no"/' /etc/network.conf
125 /sbin/udhcpc -b -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid &
126 }
128 set_static_ip()
129 {
130 sed -i 's/DHCP=.*/DHCP="no"/' /etc/network.conf
131 sed -i 's/STATIC=.*/STATIC="yes"/' /etc/network.conf
132 sed -i -e "s/INTERFACE=".*"/INTERFACE=\"$1\"/" /etc/network.conf
133 sed -i -e "s/IP=".*"/IP=\"$2\"/" /etc/network.conf
134 sed -i -e "s/NETMASK=".*"/NETMASK=\"$3\"/" /etc/network.conf
135 sed -i -e "s/GATEWAY=".*"/GATEWAY=\"$4\"/" /etc/network.conf
136 sed -i -e "s/DNS_SERVER=".*"/DNS_SERVER=\"$5\"/" /etc/network.conf
137 }
139 network_menu()
140 {
141 ret=0
142 until [ $ret -eq 1 ];do
143 $DIALOG --title "$MENU_TITLE" \
144 --backtitle "$BACKTITLE" --clear \
145 --cancel-label "Quit" \
146 --colors \
147 --menu "$TAZ_CMD_MSG" 15 50 40\
148 "address" " Network settings" \
149 "hostname" " Set your hostname" \
150 2> $OUT
151 ret=$?
152 case `cat $OUT` in
153 hostname)
154 get_hostname ;;
155 adress)
156 set_ip_adress ;;
157 esac
158 done
159 }
161 set_password()
162 {
163 SEP='
164 '
165 exec 3>&1
166 PASSWORD=`$DIALOG --backtitle "$BACKTITLE" --title "Set password" --clear \
167 --separate-widget "$SEP" \
168 --insecure --passwordbox "Enter new password for user below: \n\n" 10 50 \
169 --title "Confirm password" \
170 --insecure --passwordbox "Confirm new password for user below: \n\n" 10 50 2>&1 1>&3`
171 ret=$?
172 exec 3>&-
173 if [ -z "${PASSWORD}" ]; then
174 msg "Password not set"
175 else
176 PASS1="$(echo $PASSWORD | cut -d ' ' -f1)"
177 PASS2="$(echo $PASSWORD | cut -d ' ' -f2)"
178 if [ "$PASS1" != "$PASS2" ]; then
179 msg "Passwords don't match.\nNothing changed."
180 else
181 echo "root:$PASS1" | chpasswd -m
182 fi
183 fi
184 }
186 ##
187 # Program sequence
188 #
189 set_locale
190 check_root
192 until [ $retval -eq 1 ];do
193 $DIALOG --title "$MENU_TITLE" \
194 --backtitle "$BACKTITLE" --clear \
195 --cancel-label "Quit" \
196 --colors \
197 --menu "$TAZ_CMD_MSG" 15 50 40\
198 "keymap" " Keyboard mapping" \
199 "locale" " Language setting" \
200 "network" " Network configuration" \
201 "password" " Change root password" \
202 2> $OUT
204 retval=$?
206 # Execute commands
207 #
208 case `cat $OUT` in
209 keymap)
210 if [ -x /sbin/tazkeymap ]; then
211 tazkeymap
212 else
213 msg "Unable to find tazkeymap !"
214 fi
215 ;;
216 locale)
217 if [ -x /sbin/tazlocale ]; then
218 tazlocale
219 else
220 msg "Unable to find tazlocale !"
221 fi
222 ;;
223 network)
224 network_menu;;
225 password)
226 set_password ;;
227 esac
228 done
230 clear
232 exit 0