--- alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/10/09 21:38:14 348 +++ alx-src/branches/alxconf-060/init.d/alxsettings 2011/06/14 13:51:37 2382 @@ -1,8 +1,8 @@ #!/bin/bash - +# $Id$ # -#%rlevels: 7:s 0:k 6:k +#%rlevels: 7:s 0:k #%start: 41 #%stop: 01 @@ -11,8 +11,6 @@ #%before: #%after: -# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.23 2005-10-09 21:38:14 niro Exp $ - # checks first if the client was already configured and if it has an valid serial # if not it runs the autoconfiguration script # these settings will be used for client setup @@ -21,13 +19,14 @@ # if no changes are at server side they will be kept, if yes the get updated. # the server settings has higher priority. -source /etc/sysconfig/rc +source /etc/conf.d/rc source $rc_functions # mysql settings source /etc/alxconfig-ng/config.rc # helper functions +source /usr/lib/alxconfig-ng/functions/common source /usr/lib/alxconfig-ng/functions/mysqlfunctions source /usr/lib/alxconfig-ng/functions/serial_functions source /usr/lib/alxconfig-ng/functions/config_modules @@ -37,9 +36,7 @@ source /usr/lib/alxconfig-ng/functions/config_x11 source /usr/lib/alxconfig-ng/functions/config_auth source /usr/lib/alxconfig-ng/functions/config_ssh_auth - -# check if mysql is available -[ -x /usr/bin/mysql ] && MYSQL_ALX=true +source /usr/lib/alxconfig-ng/functions/config_versions # other needed vars ALX_HW_DETECT=false @@ -70,7 +67,7 @@ update_system_settings() { - echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT} + rc_mecho Checking system setup ... # get the modules settings # ! is the first thing that must be configured ! @@ -93,11 +90,21 @@ # exchange ssh rsa keys HOME=/root config_ssh_auth + + # import version info + config_version } get_system_serial() { - local CUR_IP CUR_MAC CUR_MTIME + local CUR_IP CUR_MAC CUR_MTIME ALX_IFACE + + if [[ ${ALX_CONFD_NETWORKING} = true ]] + then + ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)" + else + ALX_IFACE="eth0" + fi # check if serial file exists if [ -f /etc/alxconfig-ng/serial ] && [[ ${ALX_FORCED_RECHECK} = false ]] @@ -115,11 +122,11 @@ exit 1 fi - CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp') - CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) + CUR_IP=$(ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp') + CUR_MAC=$(ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) CUR_MTIME=$(date +%s) - echo -e ${COLOREDSTAR} "Trying to validate my serial ..." + rc_print "Trying to validate my serial ..." # nice serial output $CURS_UP @@ -132,7 +139,7 @@ else # abort on non valid serial ALX_STATE="invalid serial" - echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state + echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state show_invalid_serial_msg exit 1 fi @@ -142,12 +149,14 @@ echo if [[ ${ALX_FORCED_RECHECK} = true ]] then - echo -e ${COLMAGENTA}"Hardware autodetection forced by system-administrator"${COLDEFAULT} + rc_mecho "Hardware autodetection forced by system-administrator" + # always disable CONFD_NETWORKING here + export ALX_CONFD_NETWORKING="false" else - echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT} + rc_mecho "Preparing system for first boot" fi ALX_HW_DETECT=true - /etc/init.d/hwdetect start + hwsetup # set hostname to alx_default_hostname # use old hostname if this is a forced re-check @@ -169,6 +178,7 @@ exit 1 fi + CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) CUR_MTIME=$(date +%s) @@ -179,7 +189,7 @@ # but first check the serial source /etc/alxconfig-ng/serial - echo -e ${COLOREDSTAR} "Trying to validate my serial ..." + rc_print "Trying to validate my serial ..." # nice serial output $CURS_UP @@ -198,7 +208,7 @@ fi # write current state to temp file - echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state + echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state [ -f /hardware-auto-detection ] && rm /hardware-auto-detection # now export ALX_FORCED_RECHECK=true @@ -207,7 +217,7 @@ return 0 fi - echo -e ${COLOREDSTAR} "Trying to get new serial ..." + rc_print "Trying to get new serial ..." # request a new serial; one command now (cause must be done in the same session) ALX_SERIAL=$(mysqldo "insert into client_serials (mtime, mac) values('${CUR_MTIME}','${CUR_MAC}'); @@ -223,8 +233,8 @@ # set ALX_STATE to ok so everybody knows that everything was ok ALX_STATE=ok - echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial - echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial + echo "ALX_SERIAL=\"${ALX_SERIAL}\"" > /etc/alxconfig-ng/serial + echo "ALX_REG_DATE=\"${CUR_MTIME}\"" >> /etc/alxconfig-ng/serial evaluate_retval else @@ -243,8 +253,8 @@ fi # write current state to temp file - echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state - echo "ALX_IFACE=${ALX_IFACE}" >> /etc/alxconfig-ng/state/state + echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state + echo "ALX_IFACE=\"${ALX_IFACE}\"" >> /etc/alxconfig-ng/state/state } @@ -269,30 +279,29 @@ [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx - # vars used by hwdetect + # vars used by hwsetup local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER local MOUSETYPE XMOUSETYPE FULLNAME DEVICE - # get setting from hwdetect - source /etc/sysconfig/hwsetup/knoppix - source /etc/sysconfig/hwsetup/mouse + # get setting from hwsetup + source /etc/conf.d/hwsetup/knoppix + source /etc/conf.d/hwsetup/mouse echo - echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT} + rc_mecho "Importing detected settings to database" # network - echo -e " Network settings ..." + rc_mecho " Network settings ..." if [[ ${ALX_CONFD_NETWORKING} = true ]] then # get settings - #source ${rc_base}/init.d/network &> /dev/null for iface in $(onboot_interface_list ${network_settings}/net.*) do [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue - echo "WARNING: only importing settings for interface [ ${iface} ] !" - source ${network_settings}/net.${iface} || exit 1 - NETCARD_DRIVER="$(cat /etc/modules.d/net.${iface} | cut -d' ' -f3)" + rc_echo "WARNING: only importing settings for interface [ ${iface} ] !" + source ${network_settings}/net.${iface} || echo "Error: could not read '${network_settings}/net.${iface}'" + NETCARD_DRIVER="$(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f3)" mysqldo "insert into cfg_network( hostname, @@ -363,31 +372,31 @@ evaluate_retval # xserver - echo -e " Graphic settings ..." + rc_mecho " Graphic settings ..." # xserver general ( mysqldo "insert into cfg_graphic( serial, module, resolution, depth, - monitorid + refresh_rate ) values( '${ALX_SERIAL}', '${XMODULE}', '1024x768', '16', - '0' + '60' );"; ) evaluate_retval # input - echo -e " Input settings ..." + rc_mecho " Input settings ..." mysqldo "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');" evaluate_retval # auth - echo -e " Authentification settings ..." + rc_mecho " Authentification settings ..." mysqldo "insert into client_auth( serial, username, @@ -408,18 +417,27 @@ # exchange ssh rsa keys - the first boot needs this ! # or no reboot will work via the webadmin - echo -e " SSH authentification settings ..." + rc_mecho " SSH authentification settings ..." HOME=/root config_ssh_auth evaluate_retval # autostart - echo -e " Autostart settings ..." + rc_mecho " Autostart settings ..." mysqldo "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');" # screensaver - echo -e " Screensaver settings ..." + rc_mecho " Screensaver settings ..." mysqldo "insert into cfg_screensaver(serial,screensaver) values('${ALX_SERIAL}','')" + # version info + rc_mecho " OS version info ..." + local alx_os + local alx_utils + alx_os="$(< /etc/mageversion)" + alx_utils="$(magequery -n alxconfig-ng-alx | sed 's:.*\[\ \(.*\)\ \].*:\1:')" + alx_utils="${alx_utils/alxconfig-ng-alx-}" + mysqldo "insert into client_version(serial,os,utils) values('${ALX_SERIAL}','${alx_os}','${alx_utils}')" + evaluate_retval } @@ -434,20 +452,20 @@ [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx - # vars used by hwdetect + # vars used by hwsetup local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER local MOUSETYPE XMOUSETYPE FULLNAME DEVICE - # get setting from hwdetect - source /etc/sysconfig/hwsetup/knoppix - source /etc/sysconfig/hwsetup/mouse + # get setting from hwsetup + source /etc/conf.d/hwsetup/knoppix + source /etc/conf.d/hwsetup/mouse echo - echo -e ${COLMAGENTA}"Updating detected settings in database"${COLDEFAULT} + rc_mecho "Updating detected settings in database" # network - echo -e " Network settings ..." + rc_mecho " Network settings ..." if [[ ${ALX_CONFD_NETWORKING} = true ]] then # get settings @@ -455,9 +473,9 @@ for iface in $(onboot_interface_list ${network_settings}/net.*) do [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue - echo "WARNING: only importing settings for interface [ ${iface} ] !" + rc_echo "WARNING: only importing settings for interface [ ${iface} ] !" source ${network_settings}/net.${iface} || exit 1 - NETCARD_DRIVER="$(cat /etc/modules.d/net.${iface} | cut -d' ' -f3)" + NETCARD_DRIVER="$(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f3)" mysqldo "update cfg_network set hostname='${ALX_DEFAULT_HOSTNAME}', @@ -496,20 +514,29 @@ evaluate_retval # xserver - echo -e " Graphic settings ..." + rc_mecho " Graphic settings ..." # xserver general mysqldo "update cfg_graphic set module='${XMODULE}', resolution='1024x768', depth='16', - monitorid='0' + refresh_rate='60' where serial=${ALX_SERIAL};" evaluate_retval # input - echo -e " Input settings ..." + rc_mecho " Input settings ..." mysqldo "update cfg_input set mouse='${XMOUSETYPE}' where serial=${ALX_SERIAL};" evaluate_retval + + # version info + rc_mecho " OS version info ..." + local alx_os + local alx_utils + alx_os="$(< /etc/mageversion)" + alx_utils="$(magequery -n alxconfig-ng-alx | sed 's:.*\[\ \(.*\)\ \].*:\1:')" + alx_utils="${alx_utils/alxconfig-ng-alx-}" + mysqldo "update client_version set os='${alx_os}', utils='${alx_utils}' where serial=${ALX_SERIAL};" } # imports current settings to the local system resolved by the hardware detection @@ -523,34 +550,34 @@ [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx - # vars used by hwdetect + # vars used by hwsetup local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER local MOUSETYPE XMOUSETYPE FULLNAME DEVICE - # get setting from hwdetect - source /etc/sysconfig/hwsetup/knoppix + # get setting from hwsetup + source /etc/conf.d/hwsetup/knoppix echo - echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT} + rc_mecho "Importing detected settings to local system" if [[ ${ALX_CONFD_NETWORKING} = false ]] then - #[ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} - #echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules - # set an device alias for modprobe.conf - [ ! -d /etc/modules.d ] && install -d /etc/modules.d - echo "alias eth0 ${NETCARD_DRIVER}" > /etc/modules.d/net.eth0 + [ ! -d /etc/modprobe.d ] && install -d /etc/modprobe.d + echo "alias eth0 ${NETCARD_DRIVER}" > /etc/modprobe.d/net.eth0.conf # regenerate modprobe.conf - [ -x $(which modules-update) ] && modules-update || echo "cannot regen modprobe.conf" + [ -x $(which modules-update) ] && modules-update || rc_echo "modules-update not found!" evaluate_retval fi # set system state to 'already configured' touch /etc/alxconfig-ng/state/configured + # install slim desktopmanager configuration + config_display_manager + # if only an recheck was forced than abort now [[ ${ALX_FORCED_RECHECK} = true ]] && return 0 @@ -561,41 +588,35 @@ # now generate fluxbox config files # fluxbox main config - cat ${ALX_SKELETONS}/fluxbox/init \ - > ${ALX_UNPRIV_HOME}/.fluxbox/init + cat ${ALX_SKELETONS}/fluxbox/init > ${ALX_UNPRIV_HOME}/.fluxbox/init # fluxbox autostart - cat ${ALX_SKELETONS}/fluxbox/apps \ - > ${ALX_UNPRIV_HOME}/.fluxbox/apps + cat ${ALX_SKELETONS}/fluxbox/apps > ${ALX_UNPRIV_HOME}/.fluxbox/apps # fluxbox menu header - cat ${ALX_SKELETONS}/fluxbox/menu.header \ - > ${ALX_UNPRIV_HOME}/.fluxbox/menu + cat ${ALX_SKELETONS}/fluxbox/menu.header > ${ALX_UNPRIV_HOME}/.fluxbox/menu # now fix it with proper messages :P local ver="$(< /etc/mageversion)" - sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" \ - ${ALX_UNPRIV_HOME}/.fluxbox/menu + sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" ${ALX_UNPRIV_HOME}/.fluxbox/menu # add a newline (maybe there is no crlf in the header) echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu # fluxbox menu footer - cat ${ALX_SKELETONS}/fluxbox/menu.footer \ - >> ${ALX_UNPRIV_HOME}/.fluxbox/menu + cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${ALX_UNPRIV_HOME}/.fluxbox/menu # add a newline (maybe there is no crlf in the footer) echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu - # setup some standart icons (sysinfo.lnk) - # basic config - cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc - # clean desktop icon location [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop install -d ${ALX_UNPRIV_HOME}/.xtdesktop + # basic config + cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdesktop/xtdeskrc + # last but not least gen a icon with some sys informations local sysinfo local osversion @@ -622,12 +643,16 @@ --icon-width "1" \ --icon-height "1" + # create a xinitrc + echo "exec startfluxbox" > ${ALX_UNPRIV_HOME}/.xinitrc + # set correct permissions chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME} chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc + chmod 0644 ${ALX_UNPRIV_HOME}/.xinitrc } # start|stop @@ -644,13 +669,14 @@ module=$(cat ${SETTINGSPATH}/modules) modprobe ${module} fi + else - # vars used by hwdetect + # vars used by hwsetup local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER - # get setting from hwdetect - source /etc/sysconfig/hwsetup/knoppix + # get setting from hwsetup + source /etc/conf.d/hwsetup/knoppix modprobe ${NETCARD_DRIVER} fi @@ -659,43 +685,40 @@ # keeping like always safe: # no network should be startet here, # so we can delete all pid files if one exists - if ps -A|grep dhcpcd > /dev/null + if [[ ! -z $(pidof $(basename ${ALX_DHCP_PROG})) ]] then - echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT} - dhcpcd -k + rc_mecho "Forcing network down" + killall $(basename ${ALX_DHCP_PROG}) &> /dev/null sleep 1 - else - rm -f /var/run/dhcpcd-eth?.pid fi - [[ ${ALX_CONFD_NETWORKING} = true ]] && [[ ${RUNLEVEL} != S ]] && \ - ${rc_base}/init.d/network stop + [[ ${ALX_CONFD_NETWORKING} = true ]] && ${rc_base}/init.d/network stop - echo -e ${COLMAGENTA}"Starting preliminary networking ... "${COLDEFAULT} + rc_mecho "Starting preliminary networking ... " # start network configured from /etc/conf.d if [[ ${ALX_CONFD_NETWORKING} = true ]] then ${rc_base}/init.d/network start else - echo -e ${COLOREDSTAR}"Starting default dhcp based networking ... "${COLDEFAULT} - # -t 10 timeout of 10 secs - dhcpcd -t 10 &> /dev/null + rc_print "Starting default dhcp based networking ... " + ${ALX_DHCP_PROG} ${ALX_DHCP_START} &> /dev/null evaluate_retval fi ;; stop) - echo -e ${COLMAGENTA}"Stopping preliminary networking ... "${COLDEFAULT} + rc_mecho "Stopping preliminary networking ... " if [[ ${ALX_CONFD_NETWORKING} = true ]] then ${rc_base}/init.d/network stop else - echo -e ${COLOREDSTAR}"Stopping default dhcp based networking ... "${COLDEFAULT} - ifconfig eth0 down + rc_print "Stopping default dhcp based networking ... " + ifconfig ${ALX_IFACE} down fi - if ps -A|grep dhcpcd > /dev/null + if [[ ! -z $(pidof $(basename ${ALX_DHCP_PROG})) ]] then - dhcpcd -z &> /dev/null + killall $(basename ${ALX_DHCP_PROG}) &> /dev/null + sleep 1 fi evaluate_retval ;; @@ -710,32 +733,51 @@ { # force load of de kbdkeys loadkeys -q de - echo - echo -en ${COLRED} - echo -n "*** Warning: you are about to reset *all* local settings on this system!" - echo -e ${COLDEFAULT} - echo "*** Do you really want to continue ?" - echo -n "*** Enter 'yes' to continue, anything else to abort: " + rc_echo + rc_echo -en ${COLRED} + rc_echo -n "*** Warning: you are about to reset *all* local settings on this system!" + rc_echo -e ${COLDEFAULT} + rc_echo "*** Do you really want to continue ?" + rc_echo -n "*** Enter 'yes' to continue, anything else to abort: " read kbinsert if [[ ${kbinsert} = yes ]] then - echo -en ${COLRED} - echo -n "*** OK, you really want it ... killing all settings: " + rc_echo -en ${COLRED} + rc_echo -n "*** OK, you really want it ... killing all settings: " for i in 3 2 1 now do - echo -n " ${i}" + rc_echo -n " ${i}" sleep 1 done - echo -e ${COLDEFAULT} + rc_echo -e ${COLDEFAULT} ## reset all settings: rm -rf ${SETTINGSPATH}/* rm -f /etc/alxconfig-ng/serial rm -rf /etc/alxconfig-ng/state - echo "I am done now, press [Enter] to reboot system ..." + # clear all printers & net-shares + :> /etc/printcap + + # remove lprng + rc-config del lprng &> /dev/null + + # remove all user settings + [ -d ${ALX_UNPRIV_HOME} ] && rm -rf ${ALX_UNPRIV_HOME} + + # remove all ica-sessions + find ${ALX_ICA_SESSIONS} -type f -name '*.ica' | xargs rm + + # remove all old nics and modules configs + find /etc/conf.d -type f -name 'net.*' | xargs rm + find /etc/modprobe.d -type f -name 'net.*' | xargs rm + + # restore default networking + cat ${ALX_SKELETONS}/net/net.eth0 > /etc/conf.d/net.eth0 + + rc_echo "I am done now, press [Enter] to reboot system ..." else - echo "Aborted, press [Enter] to reboot system ..." + rc_echo "Aborted, press [Enter] to reboot system ..." fi read reboot @@ -863,8 +905,8 @@ [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state sleep 0.1 ;; + *) echo "Usage: $0 {start|stop} ..." ;; esac -