# HG changeset patch # User Aleksej Bobylev # Date 1427068881 -7200 # Node ID 6c2d6362887de109da4c23e84f6d06fb35c7254d # Parent 017e46ba678bddc81c1dbc7a006ee09ac367514a network.sh: better handle WEP connections, handle EAP, store Wi-Fi neworks by default; network.conf: migrate to extended format to support EAP arguments, and few more. diff -r 017e46ba678b -r 6c2d6362887d applications/bootlog.desktop --- a/applications/bootlog.desktop Sun Mar 22 19:30:39 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -[Desktop Entry] -Type=Application -Name=Boot Log Viewer -Name[fr]=Log de démarrage -Name[pt]=Visualizar log de boot -Name[pt_BR]=Visualizar log de boot -Name[ru]=Журнал загрузки -Exec=bootlog box -Icon=text-plain -Categories=System;Monitor; diff -r 017e46ba678b -r 6c2d6362887d bin/bootlog --- a/bin/bootlog Sun Mar 22 19:30:39 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#!/bin/sh -# -# Display SliTaz boot log messages -# - -catlog() { - cat /var/log/dmesg.log /var/log/boot.log | sed "s/.\[3g.*\]R//" -} - -case "$1" in - box) catlog | sed -e s'///'g -e s'/\[1;3[0-9]m//'g \ - -e s'/\[*.0G\[/ /'g -e s'/\[0;39m.*//'g | yad \ - --text-info --title="Boot Log" --window-icon=text-plain \ - --width=600 --height=400 --button=gtk-close:0 ;; - *) catlog ;; -esac diff -r 017e46ba678b -r 6c2d6362887d bin/rcSconf --- a/bin/rcSconf Sun Mar 22 19:30:39 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -#!/bin/sh -# -# Update and clean-up /etc/rcS.conf -# - -# X is now started earlier by system.sh -up_daemons() { - echo $RUN_DAEMONS | sed \ - -e s/dbus// -e s/hald// -e s/slim// -e s'/ //' -e s'/ //' -} - -case "$1" in - up) - [ $(id -u) != 0 ] && exit 0 - #check_root: broken gettext in libtaz.sh - . /etc/rcS.conf - cp -f /etc/rcS.conf /etc/slitaz/rcS.conf.bak - echo "Updating: /etc/rcS.conf" - cat > /etc/rcS.conf << EOT -# /etc/rcS.conf : Initial boot script configuration for SliTaz GNU/Linux -# Sourced by : /etc/init.d/rcS -# - -# Use udev to populate /dev and handle hotplug events -UDEV="$UDEV" - -# Clean up the system removing all tmp and pid files -CLEAN_UP_SYSTEM="$CLEAN_UP_SYSTEM" - -# Filesystems to check integrity of at boot time. You should check the -# rootfs (where SliTaz is installed) and all partitions listed in fstab. -# Example: CHECK_FS="/dev/hda5 /dev/hdb1" -CHECK_FS="$CHECK_FS" - -# Syslogd: Max size (KB) before rotation -SYSLOGD_ROTATED_SIZE="$SYSLOGD_ROTATED_SIZE" - -# Kernel modules to load at boot time -LOAD_MODULES="$LOAD_MODULES" - -# X Login manager: slim or lxdm, empty to disable X -LOGIN_MANAGER="slim" - -# Initialization scripts to run at boot time. The local.sh script -# let you quickly add some local startup commands. -RUN_SCRIPTS="bootopts.sh system.sh network.sh local.sh" - -# Daemons to start at boot time. DBUS daemon is started before the -# login manager and from: /etc/init.d/system.sh -RUN_DAEMONS="$(up_daemons)" - -# Pre login message -MESSAGE="Welcome to your box" -EOT - diff /etc/slitaz/rcS.conf.bak /etc/rcS.conf > \ - /etc/slitaz/rcS.conf.diff ;; - show) less -E /etc/rcS.conf ;; - show-diff) less -E /etc/slitaz/rcS.conf.diff ;; - clean) rm -f /etc/slitaz/rcS.conf* ;; - *) echo "Usage: $(basename $0) [up|show|show-diff|clean]" ;; -esac -exit 0 diff -r 017e46ba678b -r 6c2d6362887d etc/init.d/bootopts.sh --- a/etc/init.d/bootopts.sh Sun Mar 22 19:30:39 2015 +0100 +++ b/etc/init.d/bootopts.sh Mon Mar 23 02:01:21 2015 +0200 @@ -16,15 +16,15 @@ } # Parse /proc/cmdline for boot options. -echo "Checking for SliTaz cmdline options..." +echo 'Checking for SliTaz cmdline options...' # Default user account without password (uid=1000). In live mode the option # user=name can be used, but user must be added before home= to have home dir. # This option is not handled by a loop and case like others and has no # effect on an installed system. -if ! grep -q "100[0-9]:100" /etc/passwd; then +if ! grep -q '100[0-9]:100' /etc/passwd; then - if fgrep -q "user=" /proc/cmdline; then + if fgrep -q 'user=' /proc/cmdline; then USER=$(cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/') # Avoid usage of an existing system user or root. if grep -q ^$USER /etc/passwd; then @@ -33,38 +33,37 @@ else USER=tux fi - + # Make sure we have users applications.conf - if [ ! -f "/etc/skel/.config/slitaz/applications.conf" -a \ - -f "/etc/slitaz/applications.conf" ]; then + if [ ! -f '/etc/skel/.config/slitaz/applications.conf' -a \ + -f '/etc/slitaz/applications.conf' ]; then mkdir -p /etc/skel/.config/slitaz cp /etc/slitaz/applications.conf /etc/skel/.config/slitaz fi - + echo -n "Configuring user and group: $USER..." - adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$USER $USER + adduser -D -s /bin/sh -g 'SliTaz User' -G users -h /home/$USER $USER passwd -d $USER >/dev/null - for group in audio cdrom video tty plugdev disk - do - addgroup $USER ${group} + for group in audio cdrom video tty plugdev disk; do + addgroup $USER $group done status - + # Slim default user if [ -f /etc/slim.conf ]; then - sed -i s/"default_user .*"/"default_user $USER"/ /etc/slim.conf + sed -i "s|default_user .*|default_user $USER|" /etc/slim.conf fi fi -for opt in $(cat /proc/cmdline) -do +for opt in $(cat /proc/cmdline); do case $opt in eject) # Eject cdrom. eject /dev/cdrom ;; autologin) # Autologin option to skip first graphic login prompt. - echo "auto_login yes" >> /etc/slim.conf ;; + sed -i '/auto_login .*/d' /etc/slim.conf + echo 'auto_login yes' >> /etc/slim.conf ;; lang=*) # Check for a specified locale (lang=*). LANG=${opt#lang=} @@ -79,7 +78,9 @@ # Check for a specified console font (font=*). FONT=${opt#font=} echo -n "Setting console font to: $FONT..." - for con in 1 2 3 4 5 6; do setfont $FONT -C /dev/tty$con; done + for con in 1 2 3 4 5 6; do + setfont $FONT -C /dev/tty$con + done status ;; home=*) # Check for a specified home partition (home=*) and check for @@ -88,32 +89,37 @@ DEVICE=${opt#home=} [ "$DEVICE" = "usb" ] && DEVICE="$(usb_device)1" echo "Home has been specified to $DEVICE..." - DEVID=`/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q'` + + DEVID=$(/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q') if [ -z "$DEVID" ]; then - USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use` + USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use) USBDELAY=$((2+$USBDELAY)) echo "Sleeping $USBDELAY s to let the kernel detect the device... " sleep $USBDELAY fi - USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'` + + USER=$(cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q') DEVID=$DEVICE if [ -x /sbin/blkid ]; then # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name. - DEVID=`/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q'` + DEVID=$(/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q') fi DEVID=${DEVID##*/} + if [ -n "$DEVID" ] && fgrep -q "$DEVID" /proc/partitions ; then echo "Mounting /home on /dev/$DEVID... " [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files mount /dev/$DEVID /home && case "$(/sbin/blkid | grep /dev/$DEVID:)" in - *\"ntfs\"*|*\"vfat\"*) mount.posixovl -F /home -- -oallow_other -odefault_permissions -osuid ;; + *\"ntfs\"*|*\"vfat\"*) + mount.posixovl -F /home -- -oallow_other -odefault_permissions -osuid ;; esac mount /home -o remount,uid=1000,gid=100 2>/dev/null + # Check if swap file must be generated in /home: swap=size (Mb). # This option is only used within home=device. - if grep -q "swap=[1-9]*" /proc/cmdline; then - SWAP_SIZE=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline` + if grep -q 'swap=[1-9]*' /proc/cmdline; then + SWAP_SIZE=$(sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline) # DD to gen a virtual disk. echo "Generating swap file: /home/swap ($SWAP_SIZE)..." dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE @@ -124,6 +130,7 @@ else echo "Unable to find $DEVICE... " fi + # Move all user dir if needed. if [ ! -d "/home/$USER" ] ; then mv /tmp/$USER-files /home/$USER @@ -131,35 +138,37 @@ else rm -rf /tmp/$USER-files fi + # Install all packages in /home/boot/packages. In live CD and # USB mode the option home= mounts the device on /home, so we # already have a boot directory with the Kernel and rootfs. - if [ -d "/home/boot/packages" ]; then - for pkg in /home/boot/packages/*.tazpkg - do + if [ -d '/home/boot/packages' ]; then + for pkg in /home/boot/packages/*.tazpkg; do tazpkg install $pkg done fi + # We can have custom files in /home/boot/rootfs to overwrite # the one packed into the Live system. - if [ -d "/home/boot/rootfs" ]; then + if [ -d '/home/boot/rootfs' ]; then cp -a /home/boot/rootfs/* / fi ;; laptop) # Enable Kernel Laptop mode. - echo "5" > /proc/sys/vm/laptop_mode ;; + echo '5' > /proc/sys/vm/laptop_mode ;; mount) # Mount all ext3 partitions found (opt: mount). + # Get the list of partitions. - DEVICES_LIST=`fdisk -l | sed '/83 Linux/!d;s/ .*//'` + DEVICES_LIST=$(fdisk -l | sed '/83 Linux/!d;s/ .*//') + # Mount filesystems rw. - for device in $DEVICES_LIST - do + for device in $DEVICES_LIST; do name=${device#/dev/} # Device can be already used by home=usb. if ! mount | grep ^$device >/dev/null; then echo "Mounting partition: $name on /mnt/$name" - mkdir /mnt/$name + mkdir -p /mnt/$name mount $device /mnt/$name fi done ;; @@ -172,7 +181,7 @@ PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1) if [ -n "$PKGDEV" ]; then echo -n "Mounting packages archive from $PKGDEV..." - mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages + mkdir -p /packages; mount -t iso9660 -o ro $PKGDEV /packages status /packages/install.sh fi ;; diff -r 017e46ba678b -r 6c2d6362887d etc/init.d/network.sh --- a/etc/init.d/network.sh Sun Mar 22 19:30:39 2015 +0100 +++ b/etc/init.d/network.sh Mon Mar 23 02:01:21 2015 +0200 @@ -1,24 +1,33 @@ #!/bin/sh # # /etc/init.d/network.sh : Network initialization boot script -# Configuration file : /etc/network.conf -# +# /etc/network.conf : Main SliTaz network configuration file +# /etc/wpa/wpa.conf : Wi-Fi networks configuration file + . /etc/init.d/rc.functions -if [ -z "$2" ]; then - . /etc/network.conf -else - . $2 -fi +CONF="${2:-/etc/network.conf}" +echo "Loading network settings from $CONF" +. "$CONF" + +WPA_CONF='/etc/wpa/wpa.conf' + + +# Migrate existing settings to a new format file + +. /usr/share/slitaz/network.conf_migration + + +# Actions executing on boot time (running network.sh without parameters) boot() { - # Set hostname. + # Set hostname echo -n "Setting hostname to: $(cat /etc/hostname)" /bin/hostname -F /etc/hostname status - # Configure loopback interface. - echo -n "Configuring loopback..." + # Configure loopback interface + echo -n 'Configuring loopback...' /sbin/ifconfig lo 127.0.0.1 up /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 dev lo status @@ -26,225 +35,288 @@ [ -s /etc/sysctl.conf ] && sysctl -p /etc/sysctl.conf } + # Use ethernet + eth() { - ifconfig $INTERFACE up + [ "$WIFI" != 'yes' ] && ifconfig $INTERFACE up } -# For wifi. Users just have to enable it through yes and usually -# essid any will work and the interface is autodetected. + +# Start wpa_supplicant with prepared settings in wpa.conf + +start_wpa_supplicant() { + echo "Starting wpa_supplicant for $1..." + wpa_supplicant -B -W -c$WPA_CONF -D$WIFI_WPA_DRIVER -i$WIFI_INTERFACE +} + + +# Reconnect to the given network + +reconnect_wifi_network() { + if [ "$WIFI" == 'yes' ]; then + # Wpa_supplicant will auto-connect to the first network + # notwithstanding to priority when scan_ssid=1 + current_ssid="$(wpa_cli list_networks 2>/dev/null | fgrep '[CURRENT]' | cut -f2)" + if [ "$current_ssid" != "$WIFI_ESSID" ]; then + echo "Connecting to $WIFI_ESSID..." + for i in $(seq 20); do + index=$(wpa_cli list_networks 2>/dev/null | \ + grep -m1 -F $'\t'$WIFI_ESSID$'\t' | head -n1 | cut -f1) + [ -z "$index" ] && echo -n '.' && sleep 1 + done + wpa_cli select_network $index >/dev/null; status + fi + fi +} + + +# For Wi-Fi. Users just have to enable it through WIFI="yes" and usually +# ESSID="any" will work and the interface is autodetected. + wifi() { - if [ "$WIFI" == "yes" ]; then + if [ "$WIFI" == 'yes' ]; then ifconfig $INTERFACE down - # Confirm if $WIFI_INTERFACE is the wifi interface + # Confirm if $WIFI_INTERFACE is the Wi-Fi interface if [ ! -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then - echo "$WIFI_INTERFACE is not a wifi interface, changing it." - WIFI_INTERFACE=$(fgrep : /proc/net/dev | cut -d: -f1 | \ - while read dev; do iwconfig $dev 2>&1 | \ - fgrep -iq "essid" && { echo $dev ; break; }; \ - done) + echo "$WIFI_INTERFACE is not a Wi-Fi interface, changing it." + WIFI_INTERFACE=$(iwconfig 2>/dev/null | awk 'NR==1{print $1}') [ -n "$WIFI_INTERFACE" ] && sed -i \ - "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" \ + "s|^WIFI_INTERFACE=.*|WIFI_INTERFACE=\"$WIFI_INTERFACE\"|" \ /etc/network.conf fi - echo -n "Configuring $WIFI_INTERFACE..." + echo -n "Configuring Wi-Fi interface $WIFI_INTERFACE..." ifconfig $WIFI_INTERFACE up 2>/dev/null - if iwconfig $WIFI_INTERFACE | fgrep -q "Tx-Power"; then + if iwconfig $WIFI_INTERFACE | fgrep -q 'Tx-Power'; then iwconfig $WIFI_INTERFACE txpower on fi status - IWCONFIG_ARGS="" - [ -n "$WPA_DRIVER" ] || WPA_DRIVER="wext" - [ -n "$WIFI_MODE" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS mode $WIFI_MODE" + IWCONFIG_ARGS='' + [ -n "$WIFI_WPA_DRIVER" ] || WIFI_WPA_DRIVER='wext' + [ -n "$WIFI_MODE" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS mode $WIFI_MODE" [ -n "$WIFI_CHANNEL" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS channel $WIFI_CHANNEL" - [ -n "$WIFI_AP" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS ap $WIFI_AP" - - # Unencrypted network - if [ "$WIFI_KEY" == "" -o "$WIFI_KEY_TYPE" == "" ]; then - iwconfig $WIFI_INTERFACE essid "$WIFI_ESSID" $IWCONFIG_ARGS + [ -n "$WIFI_AP" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS ap $WIFI_AP" + + # Clean all / add / change stored networks settings + if [ "$WIFI_BLANK_NETWORKS" == 'yes' ]; then + echo "Creating new $WPA_CONF" + cat /etc/wpa/wpa_empty.conf > $WPA_CONF + else + if fgrep -q ssid=\"$WIFI_ESSID\" $WPA_CONF; then + echo "Change network settings in $WPA_CONF" + # Remove given existing network (it to be appended later) + mv -f $WPA_CONF $WPA_CONF.old + cat $WPA_CONF.old | tr '\n' '\a' | sed 's|[^#]\(network={\)|\n\1|g' | \ + fgrep -v "ssid=\"$WIFI_ESSID\"" | tr '\a' '\n' > $WPA_CONF + else + echo "Append existing $WPA_CONF" + fi fi - - # Encrypted network - [ -n "$WIFI_KEY" ] && case "$WIFI_KEY_TYPE" in - wep|WEP) - # wpa_supplicant can also deal with wep encryption - # Tip: Use unquoted strings for hexadecimal key in wep_key0 - echo "Creating: /etc/wpa/wpa.conf" - cat /etc/wpa/wpa_empty.conf > /etc/wpa/wpa.conf - cat >> /etc/wpa/wpa.conf << EOT + + # Each new network has a higher priority than the existing + MAX_PRIORITY=$(sed -n 's|[\t ]*priority=\([0-9]*\)|\1|p' $WPA_CONF | sort -g | tail -n1) + PRIORITY=$(( ${MAX_PRIORITY:-0} + 1 )) + + # Begin network description + cat >> $WPA_CONF <