#!/bin/sh # if [ "$1" = "prereqs" ]; then exit 0 fi quiet=n . /scripts/functions . /conf/tcos.conf . /conf/tcos-run-functions # if break=sqmount STOP here maybe_break network # file to save progress % echo 5 > /tmp/progress update_progress # localhost log_begin_msg "Bring up Local loopback device" ifconfig lo up log_end_msg $? touch /etc/resolv.conf if [ -d /var/lib/dhcp3 ]; then # link to work with dhcp-client or dhcp3-client ln -s /var/lib/dhcp3 /var/lib/dhcp chown root:dhcp /lib/dhcp3-client 2>/dev/null chown 775 /lib/dhcp3-client chmod 4744 /lib/dhcp3-client/call-dhclient-script chown root:dhcp /etc/resolv.conf 2>/dev/null chmod 644 /etc/resolv.conf fi # wireless TCOS minihowto # # start thin client with something like this: # # boot: tcos wifi=1 essid="ESSID" server=xx.xx.xx.xx # * server is tftpd and XMDCP host # * ESSID is wireless network if [ $(read_cmdline_var 'wifi' '0') = "1" ]; then # load kernel modules log_begin_msg "Loading wireless kernel modules" modprobe -q arc4 modprobe -q ecb modprobe -q mac80211 modprobe -q ieee80211_crypt modprobe -q ieee80211 modprobe -q ieee80211softmac #modprobe -q rc80211_simple for kmod in $TCOS_WIRELESS_MODS; do if [ "$kmod" = "madwifi" ]; then #ath-pci ath-hal wlan_tkip wlan_scan_sta ath-hal modprobe -q ath-pci 2>/dev/null modprobe -q ath-hal 2>/dev/null modprobe -q wlan_tkip 2>/dev/null modprobe -q wlan_scan_sta 2>/dev/null elif [ "$kmod" = "zd1211" -o "$kmod" = "zd1211rw" ]; then modprobe -q zd1211rw 2>/dev/null elif [ "$kmod" = "rt2400" -o "$kmod" = "rt2400pci" ]; then modprobe -q rt2400pci 2>/dev/null elif [ "$kmod" = "rt2500" -o "$kmod" = "rt2500pci" ]; then modprobe -q rt2500pci 2>/dev/null elif [ "$kmod" = "rt61" -o "$kmod" = "rt2561" -o "$kmod" = "rt61pci" ]; then modprobe -q rt61pci 2>/dev/null elif [ "$kmod" = "rt73" -o "$kmod" = "rt73usb" ]; then modprobe -q rt73usb 2>/dev/null elif [ "$kmod" = "bcm43xx" -o "$kmod" = "broadcom" ]; then modprobe -q bcm43xx 2>/dev/null else modprobe -q $kmod 2>/dev/null fi done log_end_msg 0 fi # get list of network interfaces TCOS_NET_ACTIVE="eth0" TCOS_NET_WIFI=0 TCOS_NET_WIFI_ESSID="" TCOS_NET_WIFI_KEYMODE="" TCOS_NET_DEVS=$(ls /sys/class/net/ |grep -v -e lo -e sit0 -e wmaster -e pan) TCOS_NET_LINK="" TCOS_NET_LINK_NUMBER=0 # search for network interfaces with link ok status for dev in $TCOS_NET_DEVS; do # need to up iface ifconfig $dev up >> /tmp/initramfs.debug 2>&1 # have link ??? if [ -e /sys/class/net/$dev/carrier ]; then if [ "$(cat /sys/class/net/$dev/carrier 2>/dev/null)" != "1" ]; then # some gigabit cards take some time to negotiate network link log_begin_msg "Waiting for netlink in $dev" sleep 10 log_end_msg fi if [ "$(cat /sys/class/net/$dev/carrier 2>/dev/null)" = "1" ]; then _log "05NETWORK found carrier link in $dev iface" TCOS_NET_LINK="$TCOS_NET_LINK $dev" TCOS_NET_LINK_NUMBER=$(($TCOS_NET_LINK_NUMBER+1)) fi fi done if [ $(read_cmdline_var 'wifi' '0') = "1" ]; then #force wireless, read some vars TCOS_NET_WIFI_ESSID=$(read_cmdline_var "essid" "") for dev in $TCOS_NET_DEVS; do # is wireless???? if [ -d /sys/class/net/$dev/wireless ]; then TCOS_NET_WIFI=1 TCOS_NET_LINK=$dev # stop searching break fi done fi if [ $TCOS_NET_WIFI = 1 ]; then # one iface wireless TCOS_NET_ACTIVE=$TCOS_NET_LINK elif [ $TCOS_NET_LINK_NUMBER -gt 1 ]; then # we have some ifaces with link _log "05NETWORK various net ifaces have link" elif [ $TCOS_NET_LINK_NUMBER = 1 ]; then # one iface TCOS_NET_ACTIVE=$TCOS_NET_LINK else # not link !!! panic "ERROR: No link network detected, check cable." fi # break for wireless maybe_break wireless if [ $TCOS_NET_WIFI = 1 ]; then #ifconfig $TCOS_NET_ACTIVE down #ifconfig $TCOS_NET_ACTIVE up [ -z $TCOS_NET_WIFI_KEYMODE ] && TCOS_NET_WIFI_KEYMODE="restricted" # scan wireless log_begin_msg "Scanning wireless networks" iwlist $TCOS_NET_ACTIVE scan | grep ESSID | awk -F ":" '{print $2}' | sed s/\"//g >> /tmp/initramfs.debug 2>&1 log_end_msg $? log_begin_msg "Wireless associating with $TCOS_NET_WIFI_ESSID" iwconfig $TCOS_NET_ACTIVE essid "$TCOS_NET_WIFI_ESSID" log_end_msg $? # associate if ap cmdline var is set if [ "$TCOS_NET_WIFI_ESSID" != "" ]; then if [ "$TCOS_WIRELESS_ENC" = "WPA" ]; then modprobe -q michael_mic modprobe -q blkcipher modprobe -q aes modprobe -q ieee80211_crypt_tkip modprobe -q ieee80211_crypt_ccmp log_begin_msg "Wireless WPA mode" /sbin/start-wpa.sh "${TCOS_NET_ACTIVE}" log_end_msg $? fi if [ "$TCOS_WIRELESS_ENC" = "WEP" ]; then modprobe -q ieee80211_crypt_wep log_begin_msg "Wireless WEP mode setting key" if [ ! -z $TCOS_WIRELESS_KEY ];then iwconfig $TCOS_NET_ACTIVE key $TCOS_NET_WIFI_KEYMODE $TCOS_WIRELESS_KEY fi log_end_msg $? fi else log_begin_msg "Wireless associating with any" iwconfig $TCOS_NET_ACTIVE essid any log_end_msg $? fi #else # # wired network # ifconfig $TCOS_NET_ACTIVE down # ifconfig $TCOS_NET_ACTIVE up fi log_begin_msg "Sending DHCP request on $TCOS_NET_LINK" _log "DHCLIENT $TCOS_NET_LINK" dhclient $TCOS_NET_LINK >> /tmp/initramfs.debug 2>&1 myip=$(grep 'fixed-address' /var/lib/dhcp/dhclient.leases | head -1| awk '{print $2}' | sed s/";"//g) if grep -q "server-name" /var/lib/dhcp/dhclient.leases; then dhcpserver=$(grep 'server-name' /var/lib/dhcp/dhclient.leases | awk -F'"' '{print $2}') else dhcpserver=$(grep 'dhcp-server' /var/lib/dhcp/dhclient.leases | awk '{print $3}' | awk -F ";" '{print $1}') fi hostname=$(grep 'host-name' /var/lib/dhcp/dhclient.leases | awk '{print $3}' | awk -F ";" '{print $1}' | sed s/\"//g) TCOS_NET_ACTIVE=$(grep 'interface' /var/lib/dhcp/dhclient.leases | head -1| awk '{print $2}' | sed s/";"//g | sed s/\"//g) log_end_msg 0 # hack for dhcp3-client if [ "$(route -n 2>&1| grep -c $TCOS_NET_ACTIVE)" = "0" ]; then log_begin_msg "Forcing net for dhcp3-client" myip=$(grep 'fixed-address' /var/lib/dhcp/dhclient.leases | head -1| awk '{print $2}' | sed s/";"//g) if grep -q "server-name" /var/lib/dhcp/dhclient.leases; then dhcpserver=$(grep 'server-name' /var/lib/dhcp/dhclient.leases | awk -F'"' '{print $2}') else dhcpserver=$(grep 'dhcp-server' /var/lib/dhcp/dhclient.leases | awk '{print $3}' | awk -F ";" '{print $1}') fi netmask=$(grep 'subnet-mask' /var/lib/dhcp/dhclient.leases | head -1| awk '{print $3}' | sed s/";"//g) gateway=$(grep 'routers' /var/lib/dhcp/dhclient.leases | head -1| awk '{print $3}' | sed s/";"//g) #ifconfig $TCOS_NET_ACTIVE down ifconfig $TCOS_NET_ACTIVE $myip netmask $netmask up route add default dev $TCOS_NET_ACTIVE gw $gateway log_end_msg $? fi if [ -n ${TCOS_DEBUG} ]; then _log "NETWORK data: ip=${myip} server=${dhcpserver} hostname=${hostname}" fi # count number of ":" in hostname string if [ $(echo $hostname | awk '{print split($1, A, ":")}') -gt 1 ]; then if [ -x /bin/hex2ascii ]; then # got an hexadecimal hostname hostname2=$(hex2ascii $hostname) _log "NETWORK HEX hostname \"$hostname\"=\"$hostname2\"" hostname=$hostname2 fi fi if [ -z $hostname ] || [ "x{$hostname}" = "x " ]; then panic "ERROR: DHCP server don't give me a hostname !!! Edit /etc/hosts in dhcp server" fi # search for other hosts TCOS_TFTP_SERVER=$(read_cmdline_var 'tftpserver' "${dhcpserver}") if grep -q "x-display-manager" /var/lib/dhcp/dhclient.leases; then PA_AUTH="$(grep "x-display-manager" /var/lib/dhcp/dhclient.leases | tail -1| awk '{print $3}'| sed -e 's/;//g' | sed -e 's/,/;/g')" #TMP_XDMCP="" #for gdmserver in $TCOS_XDMCP_SERVER; do # if [ $(ping -c 1 -W 2 -q $gdmserver | tail -1 | awk -F"," '{print $3}' | sed -e 's/[[:blank:]]//g' | grep -c "100%packetloss") -eq 0 ]; then # TMP_XDMCP="$gdmserver" # break # fi #done echo "PA_AUTH=\"$PA_AUTH\"" >> /conf/tcos.conf else echo "PA_AUTH=" >> /conf/tcos.conf fi TCOS_XDMCP_SERVER=$(read_cmdline_var 'xserver' "${dhcpserver}") TCOS_RDESKTOP_SERVER=$(read_cmdline_var 'rdesktop' "${dhcpserver}") TCOS_NFS_SERVER=$(read_cmdline_var 'nfsserver' "${dhcpserver}") if grep -q "font-servers" /var/lib/dhcp/dhclient.leases; then TCOS_FONT_SERVER=$(grep font-servers /var/lib/dhcp/dhclient.leases | tail -1| awk '{print $3}'| sed -e 's/;//g') else TCOS_FONT_SERVER=$(read_cmdline_var 'fontserver' "${dhcpserver}") fi # Setup the hostname log_begin_msg "Setting hostname to ${hostname}" echo $hostname > /etc/hostname echo $hostname > /proc/sys/kernel/hostname cat < /etc/hosts 127.0.0.1 localhost.localdomain localhost 127.0.0.1 localhost ${myip} ${hostname} ${dhcpserver} tcos-server ${TCOS_TFTP_SERVER} tftp-server ${TCOS_XDMCP_SERVER} xdmcp-server ${TCOS_RDESKTOP_SERVER} rdesktop-server ${TCOS_NFS_SERVER} nfs-server ${TCOS_FONT_SERVER} font-server EOF # set dns echo "nameserver $TCOS_DNS_SERVER" > /etc/resolv.conf hostname $hostname export HOSTNAME=$hostname export hostname log_end_msg $? # start portmap [ -x /sbin/portmap ] && /sbin/portmap >/tmp/portmap.log 2>&1 & echo 18 > /tmp/progress update_progress exit 0