# HG changeset patch # User Christophe Lincoln # Date 1337991409 -7200 # Node ID efe1212fa6afd2a1e4a751e0b3ab2f239228e2e2 # Parent f915047f70adde34cd7c7bf13aecee631dd96ebb Add custom rcS.conf, and shutdown, improve rcS diff -r f915047f70ad -r efe1212fa6af rootfs/etc/init.d/local.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rootfs/etc/init.d/local.sh Sat May 26 02:16:49 2012 +0200 @@ -0,0 +1,6 @@ +#!/bin/sh +# +# /etc/init.d/local.sh: Local startup commands +# +# All commands here will be executed at boot time. +# diff -r f915047f70ad -r efe1212fa6af rootfs/etc/init.d/rcS --- a/rootfs/etc/init.d/rcS Fri May 25 23:22:20 2012 +0200 +++ b/rootfs/etc/init.d/rcS Sat May 26 02:16:49 2012 +0200 @@ -1,27 +1,77 @@ #!/bin/sh # +# /etc/init.d/rcS : Initial boot script for SliTaz ARM +# Config file is : /etc/rcS.conf +# +# rcS is the main initialization script used to check fs, mount, clean, +# run scripts and start daemons. This is a custom script for ARM to get +# fast boot under Qemu and skip things like handling cdrom. +# +# Copyright (C) 2012 SliTaz ARM - BSD License +# . /lib/libtaz.sh +. /etc/rcS.conf +# We still have busybox searching for .so file in /usr/cross/arm but after +# initialization all is fine. Use a static busybox build and have mdev ??? PATH=/bin:/sbin:/usr/bin:/usr/sbin LD_LIBRARY_PATH=/usr/lib:/lib export PATH LD_LIBRARY_PATH -sleep 2 -boldify "Executing: /etc/init.d/rcS" +echo $(colorize 34 "Processing:") "/etc/init.d/rcS" -/bin/mount proc -/bin/mount -a +# Mount /proc +echo -n "Mounting proc filesystem..." +mount proc +status -/bin/hostname -F /etc/hostname -/sbin/ifconfig lo 127.0.0.1 up -/sbin/ifconfig eth0 up -/sbin/udhcpc -i eth0 +# Populate /dev +#mdev -s +#echo "/sbin/mdev" > /proc/sys/kernel/hotplug -if [ -f "/usr/share/kmap/default.kmap" ]; then - echo "Loading keymap..." - /sbin/loadkmap < /usr/share/kmap/default.kmap +# Mount all from: /etc/fstab +echo "Mounting filesystems in fstab..." +mount -a + +# Be quiet +echo "0 0 0 0" > /proc/sys/kernel/printk + +# Clean up +echo -n "Cleaning up the system..." +find /var/run -name "*.pid" -type f | xargs /bin/rm -f +rm -rf /tmp && mkdir /tmp && chmod 1777 /tmp +status + +# Start syslogd and klogd. +echo -n "Starting system log deamons: syslogd/klogd..." +syslogd -s $SYSLOGD_SIZE && klogd +status + +# Load all modules from config file +if [ "$LOAD_MODULES" ]; then + colorize 33 "Loading Kernel modules..." + for mod in $LOAD_MODULES; do + modprobe -v $mod + done +fi + +# Start all init scripts +for script in $RUN_SCRIPTS; do + echo $(colorize 34 "Processing:") "/etc/init.d/$script" + /etc/init.d/$script +done + +# Start all daemons +if [ "$RUN_DAEMONS" ]; then + colorize 33 "Starting all daemons..." + for daemon in $RUN_DAEMONS; do + /etc/init.d/$daemon start + done fi newline -colorize 32 "Welcome to SliTaz ARM" +colorize 32 "$MESSAGE" newline + +# Back to a verbose mode. +echo "7 4 1 7" > /proc/sys/kernel/printk diff -r f915047f70ad -r efe1212fa6af rootfs/etc/init.d/shutdown.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rootfs/etc/init.d/shutdown.sh Sat May 26 02:16:49 2012 +0200 @@ -0,0 +1,37 @@ +#!/bin/sh +# +# /etc/init.d/shutdown.sh: System shutdown or reboot script +# +# Copyright (C) 2012 SliTaz ARM - BSD License +# +. /lib/libtaz.sh +. /etc/rcS.conf + +# Messages +boldify "System is going down for reboot or halt..." +colorize 32 $(uptime) + +# Store last alsa settings +#if [ -x /usr/sbin/alsactl ]; then + #alsactl store +#fi + +# Stop all daemons started at boot time +if [ "$RUN_DAEMONS" ]; then + colorize 33 "Stoping all daemons..." + for daemon in $RUN_DAEMONS; do + /etc/init.d/$daemon stop + done +fi + +# Sync all filesystems +sync + +# Swap off +/sbin/swapoff -a + +# Kill all processes +killall5 + +# Umount filesystems +/bin/umount -a -r 2>/dev/null diff -r f915047f70ad -r efe1212fa6af rootfs/etc/inittab --- a/rootfs/etc/inittab Fri May 25 23:22:20 2012 +0200 +++ b/rootfs/etc/inittab Sat May 26 02:16:49 2012 +0200 @@ -1,9 +1,18 @@ -# /etc/inittab: init configuration for SliTaz ARM. +# /etc/inittab: Init configuration for SliTaz ARM # ::sysinit:/etc/init.d/rcS + +# Autologin ::respawn:-/bin/sh -l -#tty1::respawn:/sbin/getty 38400 tty1 + +# SHell invocations for selected ttys +#tty1::respawn:/sbin/getty 38400 tty2 tty2::respawn:/sbin/getty 38400 tty2 tty3::askfirst:-/bin/sh + +# Stuff to do before rebooting or shuting down +::restart:/etc/init.d/shutdown.sh +::restart:/sbin/init +::shutdown:/etc/init.d/shutdown.sh ::ctrlaltdel:/bin/umount -a -r ::ctrlaltdel:/sbin/reboot diff -r f915047f70ad -r efe1212fa6af rootfs/etc/rcS.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rootfs/etc/rcS.conf Sat May 26 02:16:49 2012 +0200 @@ -0,0 +1,18 @@ +# /etc/rcS.conf - Initial boot script configuration for Arm +# Config file used by /etc/init.d/rcS +# + +# Syslogd: Max size (KB) before rotation +SYSLOGD_SIZE="40" + +# Kernel modules to load earlier in boot +LOAD_MODULES="" + +# Scripts to run at boot time. Important: system.sh after network.sh +RUN_SCRIPTS="network.sh system.sh local.sh" + +# Daemons/services to start later in boot process. +RUN_DAEMONS="" + +# Pre login bold message. +MESSAGE="Welcome to SliTaz ARM" diff -r f915047f70ad -r efe1212fa6af rootfs/lib/libtaz.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rootfs/lib/libtaz.sh Sat May 26 02:16:49 2012 +0200 @@ -0,0 +1,172 @@ +#!/bin/sh +# +# SliTaz Base functions used from boot scripts to end user tools. Use +# gettext and not echo for messages. Keep output suitable for GTK boxes +# and Ncurses dialog. LibTaz should not depend on any configuration file. +# No bloated code here, functions must be used by at least 3-4 tools. +# +# Documentation: man libtaz or /usr/share/doc/slitaz/libtaz.txt +# +# Copyright (C) 2012 SliTaz GNU/Linux - BSD License +# + +# Internationalization. We can't export TEXTDOMAIN because this script +# includes to other scripts with other TEXTDOMAIN exported +. /usr/bin/gettext.sh + +# xgettext (from Makefile) can't extract strings from above example: +# gettext -d 'slitaz-base' 'Done' +# so, I define own function (and add it as option to xgettext to Makefile) +lgettext() { + gettext -d 'slitaz-base' $1 +} + +# Internal variables. +okmsg="$(lgettext 'Done')" +ermsg="$(lgettext 'Failed')" +: ${okcolor=32} +: ${ercolor=31} +: ${decolor=36} + +# Parse cmdline options and store values in a variable. +for opt in "$@" +do + case "$opt" in + --*=*) export ${opt#--} ;; + --*) export ${opt#--}="yes" ;; + esac +done +[ "$HTTP_REFERER" ] && output="html" + +# Get terminal columns +get_cols() { + stty -a 2>/dev/null | head -n 1 | cut -d ";" -f 3 | awk '{print $2}' +} + +# Return command status. Default to colored console output. +status() { + local check=$? + case $output in + raw|gtk) + done=" $okmsg" + error=" $ermsg" ;; + html) + done=" $okmsg" + error=" $ermsg" ;; + *) + local cols=$(get_cols) + [ "$cols" ] || cols=80 + local scol=$(($cols - 10)) + done="\\033[${scol}G[ \\033[1;${okcolor}m${okmsg}\\033[0;39m ]" + error="\\033[${scol}G[ \\033[1;${ercolor}m${ermsg}\\033[0;39m ]" ;; + esac + if [ $check = 0 ]; then + echo -e "$done" + else + echo -e "$error" + fi +} + +# Line separator. +separator() { + local sepchar="=" + [ "$HTTP_REFERER" ] && local sepchar="
" + case $output in + raw|gtk) local sepchar="-" && local cols="8" ;; + html) local sepchar="
" ;; + *) + local cols=$(get_cols) + [ "$cols" ] || cols=80 ;; + esac + for c in $(seq 1 $cols); do + echo -n "$sepchar" + done && echo "" +} + +# New line for echo -n or gettext. +newline() { + echo "" +} + +# Display a bold message. GTK Yad: Works only in --text="" +boldify() { + case $output in + raw) echo "$@" ;; + gtk) echo "$@" ;; + html) echo "$@" ;; + *) echo -e "\\033[1m$@\\033[0m" ;; + esac +} + +# Better to keep messages unsplitted +# Example: unboldify "My pretty function ;)" +unboldify() { + case $output in + raw) echo "$@" | sed -e 's|||g;s|||g' ;; + gtk) echo "$@" ;; + html) echo "$@" | sed -e 's|||g;s|||g' ;; + *) echo -e "$(echo "$@" | sed -e 's||\\033[1m|g;s||\\033[0m|g')" ;; + esac +} + +# Usage: colorize "Message" colorNB or use --color=NB option +# when running a tool. Default to white/38 and no html or gtk. +colorize() { + : ${color=$1} + shift + local content="$@" + case $output in + raw|gtk|html) echo "$content" ;; + *) + [ "$color" ] || color=38 + echo -e "\\033[1;${color}m${content}\\033[0;39m" ;; + esac + unset color +} + +# Indent text $1 spaces. +indent() { + local in="$1" + shift + echo -e "\033["$in"G $@"; +} + +# Check if user is logged as root. +check_root() { + if [ $(id -u) != 0 ]; then + lgettext "You must be root to execute:" && echo " $(basename $0) $@" + exit 1 + fi +} + +# Display debug info when --debug is used. +debug() { + [ "$debug" ] && echo "$(colorize $decolor "DEBUG:") $1" +} + +# Gettextize yes/no. +translate_query() { + case $1 in + y) lgettext "y" ;; + Y) lgettext "Y" ;; + n) lgettext "n" ;; + N) lgettext "N" ;; + # Support other cases but keep them untranslated. + *) echo "$1" ;; + esac +} + +# Usage: echo -n "The question" && confirm +confirm() { + [ "$yes" ] && true + echo -n " ($(translate_query y)/$(translate_query N)) ? " + read answer + [ "$answer" == "$(translate_query y)" ] +} + +# Log activities. $activity should be set by the script. The log format +# is suitable for web interfaces like cook. Usage: log "String" +log() { + [ "$activity" ] || activity=/var/log/slitaz/libtaz.log + echo "$(date '+%Y-%m-%d %H:%M') : $@" >> $activity +} diff -r f915047f70ad -r efe1212fa6af sat --- a/sat Fri May 25 23:22:20 2012 +0200 +++ b/sat Sat May 26 02:16:49 2012 +0200 @@ -2,7 +2,7 @@ # # Sat - SliTaz ARM Tool # -# Copyright (C) 2012 SliTaz GNU/Linux - BSD License +# Copyright (C) 2012 SliTaz ARM - BSD License # Author: Christophe Lincoln # . /lib/libtaz.sh @@ -33,9 +33,10 @@ $(boldify "Options:") --spk Include Spk package manager in the distro + --kmap Include the system keymap config in the distro --work= Path to work dir with packages and rootfs --size= Specify optional vdisk size (default 20Mb) - --init= Specify the initramfs compression: gz xz + --init= Specify the initramfs compression: gz xz EOT } @@ -136,6 +137,9 @@ tmp=$work/tmp-$$ mkdir -p $tmp cp -r $work/rootfs/* $tmp + if [ "$kmap" ]; then + cp /etc/keymap.conf $tmp/etc + fi chown -R root.root $tmp cp -a $tmp/* $distro && rm -rf $tmp status