export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
DEBUG="/dev/null"
KERNEL="$(uname -r)"
+ARCH="$(uname -m)"
umask 022
# old linuxrc version:
# {{{ Read in boot parameters
if [ -z "$CMDLINE" ]; then
# if CMDLINE was set from the outside, we're debugging.
- # Otherwise, take CMDLINE from Kernel and config files.
+ # otherwise, take CMDLINE from Kernel and config files.
CMDLINE="$(cat /proc/cmdline)"
[ -d /cdrom/bootparams/ ] && CMDLINE="$CMDLINE $(cat /cdrom/bootparams/* | tr '\n' ' ')"
[ -d /live/image/bootparams/ ] && CMDLINE="$CMDLINE $(cat /live/image/bootparams/* | tr '\n' ' ')"
### {{{ Utility Functions
-# Simple shell grep
-stringinfile(){
- case "$(cat $2)" in *$1*) return 0;; esac
- return 1
-}
-
-# same for strings
-stringinstring(){
- case "$2" in *$1*) return 0;; esac
- return 1
-}
-
-# Reread boot command line; echo last parameter's argument or return false.
+# Get a bootoption's parameter: read boot command line and either
+# echo last parameter's argument or return false.
getbootparam(){
- stringinstring " $1=" "$CMDLINE" || return 1
- result="${CMDLINE##* $1=}"
- result="${result%%[ ]*}"
- echo "$result"
- return 0
+ local line
+ local ws
+ ws=' '
+ line=" $CMDLINE "
+ case "$line" in
+ *[${ws}]"$1="*)
+ result="${line##*[$ws]$1=}"
+ result="${result%%[$ws]*}"
+ echo "$result"
+ return 0 ;;
+ *) # no match?
+ return 1 ;;
+ esac
}
# Check boot commandline for specified option
checkbootparam(){
- stringinstring " $1" "$CMDLINE"
- return "$?"
+ [ -n "$1" ] || ( echo "Error: missing argument to checkbootparam()" ; return 1 )
+ local line
+ local ws
+ ws=' '
+ line=" $CMDLINE "
+ case "$line" in
+ *[${ws}]"$1"=*|*[${ws}]"$1"[${ws}]*)
+ return 0 ;;
+ *)
+ return 1 ;;
+ esac
}
+# Check wheter a configuration variable (like $CONFIG_TOHD) is
+# enabled or not
checkvalue(){
- if [ "$1" = "yes" ] ; then
- return 0
- else
- return 1
- fi
+ case "$1" in
+ [yY][eE][sS]) return 0 ;; # it's set to 'yes'
+ [tT][rR][uU][eE]) return 0 ;; # it's set to 'true'
+ *) return 1 ;; # default
+ esac
}
+# Are we using grml-small?
checkgrmlsmall(){
grep -q small /etc/grml_version 2>>$DEBUG && return 0 || return 1
}
-checkgrmlusb(){
- grep -q usb /etc/grml_version 2>>$DEBUG && return 0 || return 1
-}
-
# execute flite only if it's present
flitewrapper() {
[ -x /usr/bin/flite ] && flite -o play -t "$*"
}
mount_pts(){
- stringinfile "/dev/pts" /proc/mounts || mount -t devpts /dev/pts /dev/pts 2>/dev/null
+ grep -q "/dev/pts" /proc/mounts || mount -t devpts /dev/pts /dev/pts 2>/dev/null
}
mount_sys(){
# {{{ debug
config_debug(){
- checkbootparam 'debug' && BOOTDEBUG="yes"
- stringinstring "BOOT_IMAGE=debug " "$CMDLINE" && BOOTDEBUG="yes"
+ checkbootparam 'debug' && BOOTDEBUG="yes"
+ checkbootparam "BOOT_IMAGE=debug" && BOOTDEBUG="yes"
rundebugshell(){
if [ -n "$BOOTDEBUG" ]; then
ewarn "Skipping running vmware specific stuff as requested on boot commandline." ; eend 0
else
if [ -z "$INSTALLED" ] ; then
- if vmware-detect || stringinstring "BOOT_IMAGE=vmware " "$CMDLINE" ; then
+ if vmware-detect || checkbootparam "BOOT_IMAGE=vmware" ; then
if ! checkbootparam 'qemu' ; then
if [ -r /etc/X11/xorg.conf.vmware ] ; then
einfo "VMware: Copying /etc/X11/xorg.conf.vmware to /etc/X11/xorg.conf"
# skip startup of w3m {{{
config_fast(){
-if checkbootparam 'fast '; then
+if checkbootparam 'fast'; then
ewarn "Bootoption fast detected. Skipping startup of grml-quickconfig."
sed -i 's#^1:.*#1:12345:respawn:/usr/bin/openvt -f -c 1 -w -- /bin/zsh#' /etc/inittab
/sbin/telinit q ; eend $?
config_agp(){
if checkbootparam 'forceagp' ; then
# Probe for AGP. Hope this can fail safely
- stringinfile "AGP" "/proc/pci" 2>>$DEBUG && { modprobe agpgart || modprobe agpgart agp_try_unsupported=1; } >>$DEBUG 2>&1 && einfo "AGP bridge detected." ; eend 0
+ grep -q "AGP" "/proc/pci" 2>>$DEBUG && { modprobe agpgart || modprobe agpgart agp_try_unsupported=1; } >>$DEBUG 2>&1 && einfo "AGP bridge detected." ; eend 0
fi
}
# }}}
[ -d "/mnt/auto/$d" ] || mkdir -p "/mnt/auto/$d"
[ -L "/mnt/$d" ] || ln -s "/mnt/auto/$d" "/mnt/$d"
anew="$d -fstype=auto,$2 :$i"
- stringinfile "$anew" "/etc/auto.mnt" || echo "$anew" >> /etc/auto.mnt
+ grep -q "$anew" "/etc/auto.mnt" || echo "$anew" >> /etc/auto.mnt
AUTOMOUNTS="$AUTOMOUNTS $d"
new="$1 /mnt/auto/$d auto users,noauto,exec,$2 0 0"
else
[ -d /mnt/$d ] && mkdir -p /mnt/$d
new="$1 /mnt/$d auto users,noauto,exec,$2 0 0"
fi
- stringinfile "$new" "/etc/fstab" || echo "$new" >> /etc/fstab
+ grep -q "$new" "/etc/fstab" || echo "$new" >> /etc/fstab
}
AUTOMOUNTS="floppy cdrom"
einfo "Using GRML swapfile ${WHITE}${SWAPFILE}${NORMAL}."
eoutdent
fnew="$SWAPFILE swap swap defaults 0 0"
- stringinfile "$fnew" "/etc/fstab" || echo "$fnew" >> /etc/fstab
+ grep -q "$fnew" "/etc/fstab" || echo "$fnew" >> /etc/fstab
GRML_SWP="$GRML_SWP $SWAPFILE"
eend 0
fi
einfo "Network device ${WHITE}${DEVICE}${NORMAL} detected, DHCP broadcasting for IP. (Backgrounding)"
trap 2 3 11
ifconfig $DEVICE up >>$DEBUG 2>&1
- ( pump -i $DEVICE >>$DEBUG 2>&1 && echo finished_running_pump > /etc/network/status/$DEVICE ) &
+ ( pump -i $DEVICE --script=/usr/lib/grml-autoconfig/pump-runparts >>$DEBUG 2>&1 && echo finished_running_pump > /etc/network/status/$DEVICE ) &
trap "" 2 3 11
sleep 1
eend 0
# }}}
# {{{ Sound
+
config_mixer(){
-if ! [ -x /usr/bin/aumix ] ; then
- eerror "aumix binary not available. Can not set sound volumes therefore." ; eend 1
+if ! [ -x /usr/bin/amixer ] ; then
+ eerror "amixer binary not available. Can not set sound volumes therefore." ; eend 1
else
if ! [ -r /proc/asound/cards ] ; then
if checkbootparam 'nosound' ; then
einfo "Muting sound devices on request."
- # some IBM notebooks require the following stuff:
- if [ -x /usr/bin/amixer ] ; then
- if amixer get Front 1>/dev/null 2>>$DEBUG ; then
- amixer set Front unmute 1>/dev/null
- amixer set Front 0% 1>/dev/null
- fi
- fi
- ERROR=$(aumix -w 0 -v 0 -p 0 -m 0 2>&1) ; RC=$?
+
+ fix_ibm_sound 0
+ # mute the master, this should be sufficient
+ ERROR=$(amixer -q set Master mute)
+ RC=$?
+
if [ -n "$ERROR" ] ; then
eindent
eerror "Problem muting sound devices: $ERROR"
eend $RC
elif [ -z "$INSTALLED" ]; then
einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}."
- # some IBM notebooks require the following stuff:
- if [ -x /usr/bin/amixer ] ; then
- if amixer get Front 1>/dev/null 2>>$DEBUG ; then
- amixer set Front unmute 1>/dev/null
- amixer set Front ${VOL}% 1>/dev/null
- fi
- fi
+
+ fix_ibm_sound ${VOL}
+
# by default assume '0' as volume for microphone:
if checkbootparam 'micvol' ; then
MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)"
fi
# finally set the volumes:
- ERROR=$(aumix -w $VOL -v $VOL -p $VOL -m $MICVOL 2>&1) ; RC=$?
- if [ -n "$ERROR" ] ; then
- eindent
- eerror "Problem setting mixer volumes: $ERROR (no soundcard?)"
- eoutdent
+ RC=0
+ for CONTROL in Master PCM ; do
+ amixer -q set ${CONTROL} ${VOL}%
+ if [ $? -ne 0 ] ; then RC=$? ; fi
+ done
+ # dont know how to set microphone volume for all soundcards with amixer,
+ # so use aumix instead :/
+ if [ ${MICVOL} -ne 0 -a -x /usr/bin/aumix ] ; then
+ aumix -m $MICVOL &>/dev/null
+ if [ $? -ne 0 ] ; then RC=$? ; fi
fi
+
eend $RC
fi
fi
}
+
+# on some IBM notebooks the front control has to be toggled
+fix_ibm_sound() {
+ if [ -z $1 ] ; then
+ return
+ fi
+
+ VOL=${1}
+
+ if [ -x /usr/bin/amixer ] ; then
+ if amixer -q get Front 1>/dev/null 2>>$DEBUG ; then
+ amixer -q set Front unmute &>/dev/null
+ amixer -q set Front ${VOL}% &>/dev/null
+ fi
+ fi
+}
# }}}
# {{{ modem detection
}
# }}}
-# {{{ config files
-config_netconfig(){
- if checkbootparam 'netconfig' ; then
- CONFIG="$(getbootparam 'netconfig' 2>>$DEBUG)"
- CONFIGFILE='/tmp/netconfig.grml'
-
+# {{{ remote files
+get_remote_file() {
+ [ "$#" -eq 2 ] || ( echo "Error: wrong parameter for get_remote_file()" ; return 1 )
+ SOURCE=$(eval echo "$1")
+ TARGET="$2"
getconfig() {
- wget --timeout=10 --dns-timeout=10 --connect-timeout=10 \
- --read-timeout=10 $CONFIG -O $CONFIGFILE && return 0 || return 1
+ wget --timeout=10 --dns-timeout=10 --connect-timeout=10 --tries=1 \
+ --read-timeout=10 ${SOURCE} -O ${TARGET} && return 0 || return 1
}
- einfo "Trying to get ${WHITE}${CONFIG}${NORMAL}"
+ einfo "Trying to get ${WHITE}${TARGET}${NORMAL}"
counter=10
while ! getconfig && [[ "$counter" != 0 ]] ; do
- echo -n "Sleeping for 5 seconds and trying to get config again... "
+ echo -n "Sleeping for 1 second and trying to get config again... "
counter=$(( counter-1 ))
echo "$counter tries left" ; sleep 1
done
- if [ -r "$CONFIGFILE" ] ; then
+ if [ -s "$TARGET" ] ; then
einfo "Downloading was successfull." ; eend 0
- einfo "md5sum of ${WHITE}${CONFIG}${NORMAL}: "
- md5sum $CONFIGFILE ; eend 0
- cd / && einfo "Unpacking ${WHITE}${CONFIGFILE}${NORMAL}:" && /usr/bin/unp $CONFIGFILE $EXTRACTOPTIONS ; eend $?
+ einfo "md5sum of ${WHITE}${TARGET}${NORMAL}: "
+ md5sum ${TARGET} ; eend 0
+ return 0;
else
- einfo "Sorry, could not fetch $CONFIG" ; eend 1
+ einfo "Sorry, could not fetch ${SOURCE}" ; eend 1
+ return 1;
+ fi
+}
+# }}}
+
+# {{{ config files
+config_netconfig(){
+ if checkbootparam 'netconfig' ; then
+ CONFIG="$(getbootparam 'netconfig' 2>>$DEBUG)"
+ CONFIGFILE='/tmp/netconfig.grml'
+
+ if get_remote_file ${CONFIG} ${CONFIGFILE} ; then
+ cd / && einfo "Unpacking ${WHITE}${CONFIGFILE}${NORMAL}:" && /usr/bin/unp $CONFIGFILE $EXTRACTOPTIONS ; eend $?
+ fi
+
+ fi
+}
+# }}}
+
+# {{{ remote scripts
+config_netscript() {
+ if checkbootparam 'netscript' ; then
+ CONFIG="$(getbootparam 'netscript' 2>>$DEBUG)"
+ SCRIPTFILE='/tmp/netscript.grml'
+
+ if get_remote_file ${CONFIG} ${SCRIPTFILE} ; then
+ chmod +x ${SCRIPTFILE}
+ einfo "Running ${WHITE}${SCRIPTFILE}${NORMAL}:" && ${SCRIPTFILE} ; eend $?
fi
+
fi
}
# }}}
config_x_startup(){
# make sure we start X only if startx is used *before* a nostartx option
# so it's possible to disable automatic X startup using nostart
-if checkbootparam 'startx' && ! grep -q 'startx.*nostartx' "$CMDLINE" ; then
- if [ -x /usr/X11R6/bin/X ] ; then
+if checkbootparam 'startx' && ! echo "$CMDLINE" | grep -q 'startx.*nostartx' ; then
+ if [ -x $(which X) ] ; then
if [ -z "$INSTALLED" ] ; then
WINDOWMANAGER="$(getbootparam 'startx' 2>>$DEBUG)"
if [ -z "$WINDOWMANAGER" ] ; then
if checkbootparam 'myconfig' ; then
DCSDEVICE="$(getbootparam 'myconfig' 2>>$DEBUG)"
if [ -z "$DCSDEVICE" ]; then
- einfo "No device for bootoption myconfig provided." ; eend 1
+ eerror "Error: No device for bootoption myconfig provided." ; eend 1
fi # [ -z "$DCSDEVICE" ]
elif checkvalue $CONFIG_MYCONFIG; then # checkbootparam myconfig
einfo "Searching for device(s) labeled with GRMLCFG. (Disable this via boot option: noautoconfig)" ; eend 0
fi
fi
DCSDEVICE=$(blkid -t LABEL=GRMLCFG | head -1 | awk -F: '{print $1}')
+ eoutdent
fi
- if [ -n "$DCSDEVICE" ]; then
+
+ # if not specified/present then assume default:
+ if [ -z "$DCSDEVICE" ]; then
+ DCSDIR="/live/image"
+ else
+ eindent
einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0
DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2 }}')"
if [ -n "$DCSDIR" ]; then
- einfo "$DCSDEVICE already mounted on $DCSDIR"; eend 0
+ ewarn "$DCSDEVICE already mounted on $DCSDIR"; eend 0
else
[ -d /mnt/grml ] || mkdir /mnt/grml
umount /mnt/grml 1>>$DEBUG 2>&1 # make sure it is not mounted
mount -o ro -t auto $DCSDEVICE /mnt/grml ; RC="$?"
if [[ $RC == 0 ]]; then
einfo "Successfully mounted $DCSDEVICE to /mnt/grml (readonly)." ; eend 0
- eindent
+ else
+ eerror "Error: mounting $DCSDEVICE to /mnt/grml (readonly) failed." ; eend 1
fi
DCSDIR="/mnt/grml"
fi
+ eoutdent
fi
fi
fi
-if [ -n "$DCSDIR" ]; then
- einfo "Debs, config, scripts will be read from $DCSDIR." ; eend 0
+if [ -n "$DCSDIR" -a "$DCSDIR" != "/live/image" ] ; then
+ einfo "Debs, config, scripts (if present) will be read from $DCSDIR." ; eend 0
elif checkbootparam 'debs' || checkbootparam 'config' || checkbootparam 'scripts'; then
einfo "Debs, config, scripts will be read from the live image directly." ; eend 0
fi
# {{{ grml2hd: automatic installation
config_grml2hd(){
-if stringinstring "BOOT_IMAGE=grml2hd " "$CMDLINE" ; then
+if checkbootparam "BOOT_IMAGE=grml2hd" ; then
if checkbootparam 'user' ; then
NEWUSER=''
ewarn "There was an error adjusting /etc/grml2hd/config. Skipping execution of grml2hd for security reasons." ; eend 1
fi
-fi # if stringinstring "BOOT_IMAGE=grml2hd ...
+fi # if checkbootparam "BOOT_IMAGE=grml2hd ...
}
# }}}
# {{{ debootstrap: automatic installation
config_debootstrap(){
-if stringinstring "BOOT_IMAGE=debian2hd " "$CMDLINE" ; then
+if checkbootparam "BOOT_IMAGE=debian2hd" ; then
einfo "Bootoption debian2hd found. Setting up environment for automatic installation via grml-debootstrap." ; eend 0
einfo "Invoking a shell, just exit to continue booting..."
/bin/zsh
-fi # stringinstring "BOOT_IMAGE=debian2hd
+fi # checkbootparam "BOOT_IMAGE=debian2hd
}
# }}}