slitaz-arm rev 13

Add custom rcS.conf, and shutdown, improve rcS
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 26 02:16:49 2012 +0200 (2012-05-26)
parents f915047f70ad
children 272a8df86398
files rootfs/etc/init.d/local.sh rootfs/etc/init.d/rcS rootfs/etc/init.d/shutdown.sh rootfs/etc/inittab rootfs/etc/rcS.conf rootfs/lib/libtaz.sh sat
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rootfs/etc/init.d/local.sh	Sat May 26 02:16:49 2012 +0200
     1.3 @@ -0,0 +1,6 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# /etc/init.d/local.sh: Local startup commands
     1.7 +#
     1.8 +# All commands here will be executed at boot time.
     1.9 +#
     2.1 --- a/rootfs/etc/init.d/rcS	Fri May 25 23:22:20 2012 +0200
     2.2 +++ b/rootfs/etc/init.d/rcS	Sat May 26 02:16:49 2012 +0200
     2.3 @@ -1,27 +1,77 @@
     2.4  #!/bin/sh
     2.5  #
     2.6 +# /etc/init.d/rcS : Initial boot script for SliTaz ARM
     2.7 +# Config file is  : /etc/rcS.conf
     2.8 +#
     2.9 +# rcS is the main initialization script used to check fs, mount, clean,
    2.10 +# run scripts and start daemons. This is a custom script for ARM to get
    2.11 +# fast boot under Qemu and skip things like handling cdrom.
    2.12 +#
    2.13 +# Copyright (C) 2012 SliTaz ARM - BSD License
    2.14 +#
    2.15  . /lib/libtaz.sh
    2.16 +. /etc/rcS.conf
    2.17  
    2.18 +# We still have busybox searching for .so file in /usr/cross/arm but after
    2.19 +# initialization all is fine. Use a static busybox build and have mdev ???
    2.20  PATH=/bin:/sbin:/usr/bin:/usr/sbin
    2.21  LD_LIBRARY_PATH=/usr/lib:/lib
    2.22  export PATH LD_LIBRARY_PATH
    2.23  
    2.24 -sleep 2
    2.25 -boldify "Executing: /etc/init.d/rcS"
    2.26 +echo $(colorize 34 "Processing:") "/etc/init.d/rcS"
    2.27  
    2.28 -/bin/mount proc
    2.29 -/bin/mount -a
    2.30 +# Mount /proc
    2.31 +echo -n "Mounting proc filesystem..."
    2.32 +mount proc
    2.33 +status
    2.34  
    2.35 -/bin/hostname -F /etc/hostname
    2.36 -/sbin/ifconfig lo 127.0.0.1 up
    2.37 -/sbin/ifconfig eth0 up
    2.38 -/sbin/udhcpc -i eth0
    2.39 +# Populate /dev
    2.40 +#mdev -s
    2.41 +#echo "/sbin/mdev" > /proc/sys/kernel/hotplug
    2.42  
    2.43 -if [ -f "/usr/share/kmap/default.kmap" ]; then
    2.44 -	echo "Loading keymap..."
    2.45 -	/sbin/loadkmap < /usr/share/kmap/default.kmap
    2.46 +# Mount all from: /etc/fstab
    2.47 +echo "Mounting filesystems in fstab..."
    2.48 +mount -a
    2.49 +
    2.50 +# Be quiet
    2.51 +echo "0 0 0 0" > /proc/sys/kernel/printk
    2.52 +
    2.53 +# Clean up
    2.54 +echo -n "Cleaning up the system..."
    2.55 +find /var/run -name "*.pid" -type f | xargs /bin/rm -f
    2.56 +rm -rf /tmp && mkdir /tmp && chmod 1777 /tmp
    2.57 +status
    2.58 +
    2.59 +# Start syslogd and klogd.
    2.60 +echo -n "Starting system log deamons: syslogd/klogd..."
    2.61 +syslogd -s $SYSLOGD_SIZE && klogd
    2.62 +status
    2.63 +
    2.64 +# Load all modules from config file
    2.65 +if [ "$LOAD_MODULES" ]; then
    2.66 +	colorize 33 "Loading Kernel modules..."
    2.67 +	for mod in $LOAD_MODULES; do
    2.68 +		modprobe -v $mod
    2.69 +	done
    2.70 +fi
    2.71 +
    2.72 +# Start all init scripts
    2.73 +for script in $RUN_SCRIPTS; do
    2.74 +	echo $(colorize 34 "Processing:") "/etc/init.d/$script"
    2.75 +	/etc/init.d/$script
    2.76 +done
    2.77 +
    2.78 +# Start all daemons
    2.79 +if [ "$RUN_DAEMONS" ]; then
    2.80 +	colorize 33 "Starting all daemons..."
    2.81 +	for daemon in $RUN_DAEMONS; do
    2.82 +		/etc/init.d/$daemon start
    2.83 +	done
    2.84  fi
    2.85  
    2.86  newline
    2.87 -colorize 32 "Welcome to SliTaz ARM"
    2.88 +colorize 32 "$MESSAGE"
    2.89  newline
    2.90 +
    2.91 +# Back to a verbose mode.
    2.92 +echo "7 4 1 7" > /proc/sys/kernel/printk
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/rootfs/etc/init.d/shutdown.sh	Sat May 26 02:16:49 2012 +0200
     3.3 @@ -0,0 +1,37 @@
     3.4 +#!/bin/sh
     3.5 +#
     3.6 +# /etc/init.d/shutdown.sh: System shutdown or reboot script
     3.7 +#
     3.8 +# Copyright (C) 2012 SliTaz ARM - BSD License
     3.9 +#
    3.10 +. /lib/libtaz.sh
    3.11 +. /etc/rcS.conf
    3.12 +
    3.13 +# Messages
    3.14 +boldify "System is going down for reboot or halt..."
    3.15 +colorize 32 $(uptime)
    3.16 +
    3.17 +# Store last alsa settings
    3.18 +#if [ -x /usr/sbin/alsactl ]; then
    3.19 +	#alsactl store
    3.20 +#fi
    3.21 +
    3.22 +# Stop all daemons started at boot time
    3.23 +if [ "$RUN_DAEMONS" ]; then
    3.24 +	colorize 33 "Stoping all daemons..."
    3.25 +	for daemon in $RUN_DAEMONS; do
    3.26 +		/etc/init.d/$daemon stop
    3.27 +	done
    3.28 +fi
    3.29 +
    3.30 +# Sync all filesystems
    3.31 +sync
    3.32 +
    3.33 +# Swap off
    3.34 +/sbin/swapoff -a
    3.35 +
    3.36 +# Kill all processes
    3.37 +killall5
    3.38 +
    3.39 +# Umount filesystems
    3.40 +/bin/umount -a -r 2>/dev/null
     4.1 --- a/rootfs/etc/inittab	Fri May 25 23:22:20 2012 +0200
     4.2 +++ b/rootfs/etc/inittab	Sat May 26 02:16:49 2012 +0200
     4.3 @@ -1,9 +1,18 @@
     4.4 -# /etc/inittab: init configuration for SliTaz ARM.
     4.5 +# /etc/inittab: Init configuration for SliTaz ARM
     4.6  #
     4.7  ::sysinit:/etc/init.d/rcS
     4.8 +
     4.9 +# Autologin
    4.10  ::respawn:-/bin/sh -l
    4.11 -#tty1::respawn:/sbin/getty 38400 tty1
    4.12 +
    4.13 +# SHell invocations for selected ttys
    4.14 +#tty1::respawn:/sbin/getty 38400 tty2
    4.15  tty2::respawn:/sbin/getty 38400 tty2
    4.16  tty3::askfirst:-/bin/sh
    4.17 +
    4.18 +# Stuff to do before rebooting or shuting down
    4.19 +::restart:/etc/init.d/shutdown.sh
    4.20 +::restart:/sbin/init
    4.21 +::shutdown:/etc/init.d/shutdown.sh
    4.22  ::ctrlaltdel:/bin/umount -a -r
    4.23  ::ctrlaltdel:/sbin/reboot
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/rootfs/etc/rcS.conf	Sat May 26 02:16:49 2012 +0200
     5.3 @@ -0,0 +1,18 @@
     5.4 +# /etc/rcS.conf - Initial boot script configuration for Arm
     5.5 +# Config file used by /etc/init.d/rcS
     5.6 +#
     5.7 +
     5.8 +# Syslogd: Max size (KB) before rotation
     5.9 +SYSLOGD_SIZE="40"
    5.10 +
    5.11 +# Kernel modules to load earlier in boot
    5.12 +LOAD_MODULES=""
    5.13 +
    5.14 +# Scripts to run at boot time. Important: system.sh after network.sh
    5.15 +RUN_SCRIPTS="network.sh system.sh local.sh"
    5.16 +
    5.17 +# Daemons/services to start later in boot process.
    5.18 +RUN_DAEMONS=""
    5.19 +
    5.20 +# Pre login bold message.
    5.21 +MESSAGE="Welcome to SliTaz ARM"
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/rootfs/lib/libtaz.sh	Sat May 26 02:16:49 2012 +0200
     6.3 @@ -0,0 +1,172 @@
     6.4 +#!/bin/sh
     6.5 +#
     6.6 +# SliTaz Base functions used from boot scripts to end user tools. Use
     6.7 +# gettext and not echo for messages. Keep output suitable for GTK boxes
     6.8 +# and Ncurses dialog. LibTaz should not depend on any configuration file.
     6.9 +# No bloated code here, functions must be used by at least 3-4 tools.
    6.10 +#
    6.11 +# Documentation: man libtaz or /usr/share/doc/slitaz/libtaz.txt
    6.12 +#
    6.13 +# Copyright (C) 2012 SliTaz GNU/Linux - BSD License
    6.14 +#
    6.15 +
    6.16 +# Internationalization. We can't export TEXTDOMAIN because this script
    6.17 +# includes to other scripts with other TEXTDOMAIN exported
    6.18 +. /usr/bin/gettext.sh
    6.19 +
    6.20 +# xgettext (from Makefile) can't extract strings from above example:
    6.21 +# gettext -d 'slitaz-base' 'Done'
    6.22 +# so, I define own function (and add it as option to xgettext to Makefile)
    6.23 +lgettext() {
    6.24 +	gettext -d 'slitaz-base' $1
    6.25 +}
    6.26 +
    6.27 +# Internal variables.
    6.28 +okmsg="$(lgettext 'Done')"
    6.29 +ermsg="$(lgettext 'Failed')"
    6.30 +: ${okcolor=32}
    6.31 +: ${ercolor=31}
    6.32 +: ${decolor=36}
    6.33 +
    6.34 +# Parse cmdline options and store values in a variable.
    6.35 +for opt in "$@"
    6.36 +do
    6.37 +	case "$opt" in
    6.38 +		--*=*) export ${opt#--} ;;
    6.39 +		--*) export ${opt#--}="yes" ;;
    6.40 +	esac
    6.41 +done
    6.42 +[ "$HTTP_REFERER" ] && output="html"
    6.43 +
    6.44 +# Get terminal columns
    6.45 +get_cols() {
    6.46 +	stty -a 2>/dev/null | head -n 1 | cut -d ";" -f 3 | awk '{print $2}'
    6.47 +}
    6.48 +
    6.49 +# Return command status. Default to colored console output.
    6.50 +status() {
    6.51 +	local check=$?
    6.52 +	case $output in
    6.53 +		raw|gtk)
    6.54 +			done=" $okmsg"
    6.55 +			error=" $ermsg" ;;
    6.56 +		html)
    6.57 +			done=" <span style='color: $okcolor;'>$okmsg</span>"
    6.58 +			error=" <span style='color: $ercolor;'>$ermsg</span>" ;;
    6.59 +		*)
    6.60 +			local cols=$(get_cols)
    6.61 +			[ "$cols" ] || cols=80
    6.62 +			local scol=$(($cols - 10))
    6.63 +			done="\\033[${scol}G[ \\033[1;${okcolor}m${okmsg}\\033[0;39m ]"
    6.64 +			error="\\033[${scol}G[ \\033[1;${ercolor}m${ermsg}\\033[0;39m ]" ;;
    6.65 +	esac
    6.66 +	if [ $check = 0 ]; then
    6.67 +		echo -e "$done"
    6.68 +	else
    6.69 +		echo -e "$error"
    6.70 +	fi
    6.71 +}
    6.72 +
    6.73 +# Line separator.
    6.74 +separator() {
    6.75 +	local sepchar="="
    6.76 +	[ "$HTTP_REFERER" ] && local sepchar="<hr />"
    6.77 +	case $output in
    6.78 +		raw|gtk) local sepchar="-" && local cols="8" ;;
    6.79 +		html) local sepchar="<hr />" ;;
    6.80 +		*)
    6.81 +			local cols=$(get_cols)
    6.82 +			[ "$cols" ] || cols=80 ;;
    6.83 +	esac
    6.84 +	for c in $(seq 1 $cols); do
    6.85 +		echo -n "$sepchar"
    6.86 +	done && echo ""
    6.87 +}
    6.88 +
    6.89 +# New line for echo -n or gettext.
    6.90 +newline() {
    6.91 +	echo ""
    6.92 +}
    6.93 +
    6.94 +# Display a bold message. GTK Yad: Works only in --text=""
    6.95 +boldify() {
    6.96 +	case $output in
    6.97 +		raw) echo "$@" ;;
    6.98 +		gtk) echo "<b>$@</b>" ;;
    6.99 +		html) echo "<strong>$@</strong>" ;;
   6.100 +		*) echo -e "\\033[1m$@\\033[0m" ;;
   6.101 +	esac
   6.102 +}
   6.103 +
   6.104 +# Better to keep messages unsplitted
   6.105 +# Example: unboldify "My <b>pretty</b> function ;)"
   6.106 +unboldify() {
   6.107 +	case $output in
   6.108 +		raw)	echo "$@" | sed -e 's|<b>||g;s|</b>||g' ;;
   6.109 +		gtk)	echo "$@" ;;
   6.110 +		html)	echo "$@" | sed -e 's|<b>|<strong>|g;s|</b>|</strong>|g' ;;
   6.111 +		*)		echo -e "$(echo "$@" | sed -e 's|<b>|\\033[1m|g;s|</b>|\\033[0m|g')" ;;
   6.112 +	esac
   6.113 +}
   6.114 +
   6.115 +# Usage: colorize "Message" colorNB or use --color=NB option
   6.116 +# when running a tool. Default to white/38 and no html or gtk.
   6.117 +colorize() {
   6.118 +	: ${color=$1}
   6.119 +	shift
   6.120 +	local content="$@"
   6.121 +	case $output in
   6.122 +		raw|gtk|html) echo "$content" ;;
   6.123 +		*)
   6.124 +			[ "$color" ] || color=38
   6.125 +			echo -e "\\033[1;${color}m${content}\\033[0;39m" ;;
   6.126 +	esac
   6.127 +	unset color
   6.128 +}
   6.129 +
   6.130 +# Indent text $1 spaces.
   6.131 +indent() {
   6.132 +	local in="$1"
   6.133 +	shift
   6.134 +	echo -e "\033["$in"G $@";
   6.135 +}
   6.136 +
   6.137 +# Check if user is logged as root.
   6.138 +check_root() {
   6.139 +	if [ $(id -u) != 0 ]; then
   6.140 +		lgettext "You must be root to execute:" && echo " $(basename $0) $@"
   6.141 +		exit 1
   6.142 +	fi
   6.143 +}
   6.144 +
   6.145 +# Display debug info when --debug is used.
   6.146 +debug() {
   6.147 +	[ "$debug" ] && echo "$(colorize $decolor "DEBUG:") $1"
   6.148 +}
   6.149 +
   6.150 +# Gettextize yes/no.
   6.151 +translate_query() {
   6.152 +	case $1 in
   6.153 +		y) lgettext "y" ;;
   6.154 +		Y) lgettext "Y" ;;
   6.155 +		n) lgettext "n" ;;
   6.156 +		N) lgettext "N" ;;
   6.157 +		# Support other cases but keep them untranslated.
   6.158 +		*) echo "$1" ;;
   6.159 +	esac
   6.160 +}
   6.161 +
   6.162 +# Usage: echo -n "The question" && confirm
   6.163 +confirm() {
   6.164 +	[ "$yes" ] && true
   6.165 +	echo -n " ($(translate_query y)/$(translate_query N)) ? "
   6.166 +	read answer
   6.167 +	[ "$answer" == "$(translate_query y)" ]
   6.168 +}
   6.169 +
   6.170 +# Log activities. $activity should be set by the script. The log format
   6.171 +# is suitable for web interfaces like cook. Usage: log "String"
   6.172 +log() {
   6.173 +	[ "$activity" ] || activity=/var/log/slitaz/libtaz.log
   6.174 +	echo "$(date '+%Y-%m-%d %H:%M') : $@" >> $activity
   6.175 +}
     7.1 --- a/sat	Fri May 25 23:22:20 2012 +0200
     7.2 +++ b/sat	Sat May 26 02:16:49 2012 +0200
     7.3 @@ -2,7 +2,7 @@
     7.4  #
     7.5  # Sat - SliTaz ARM Tool
     7.6  #
     7.7 -# Copyright (C) 2012 SliTaz GNU/Linux - BSD License
     7.8 +# Copyright (C) 2012 SliTaz ARM - BSD License
     7.9  # Author: Christophe Lincoln <pankso@slitaz.org>
    7.10  #
    7.11  . /lib/libtaz.sh
    7.12 @@ -33,9 +33,10 @@
    7.13  
    7.14  $(boldify "Options:")
    7.15    --spk      Include Spk package manager in the distro
    7.16 +  --kmap     Include the system keymap config in the distro
    7.17    --work=    Path to work dir with packages and rootfs
    7.18    --size=    Specify optional vdisk size (default 20Mb)
    7.19 -  --init=   Specify the initramfs compression: gz xz
    7.20 +  --init=    Specify the initramfs compression: gz xz
    7.21  
    7.22  EOT
    7.23  }
    7.24 @@ -136,6 +137,9 @@
    7.25  			tmp=$work/tmp-$$
    7.26  			mkdir -p $tmp
    7.27  			cp -r $work/rootfs/* $tmp
    7.28 +			if [ "$kmap" ]; then
    7.29 +				cp /etc/keymap.conf $tmp/etc
    7.30 +			fi
    7.31  			chown -R root.root $tmp
    7.32  			cp -a $tmp/* $distro && rm -rf $tmp
    7.33  			status