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