#!/bin/sh . /etc/rc.config size=$(stty size 2>/dev/null || echo 37 93) export RIGHT=${RIGHT-$((${size#* }-10))} export PATH=/sbin:/usr/sbin:/bin:/usr/bin failed() { touch /var/spool/failed } check_status() { status=$? if [ -n "$1" ]; then status=$1 elif [ -e /var/spool/failed ]; then status=1 fi rm -f /var/spool/failed echo -en "\\033[1A\\033[${RIGHT}G" if [ $status = 0 ]; then echo -en "\\033[1;32mdone" else if [ -n "$2" ]; then echo -en "\\033[1;37m$2" else echo -en "\\033[1;31mfailed" touch /var/spool/error fi fi echo -e "\\033[0;39m" echo $(($(cat /var/spool/bootstep 2>/dev/null || echo 0) + 1)) > /var/spool/bootstep echo 0 > /var/spool/subbootstep show_bootstep return $status } show_step() { subbootstep=$(($(cat /var/spool/subbootstep 2>/dev/null || echo 0) + 1)) echo $subbootstep > /var/spool/subbootstep echo -n "$(echo '|/-\' | cut -b $(($subbootstep%4+1)))" show_bootstep } show_bootstep() { bootstep=$(cat /var/spool/bootstep 2>/dev/null || echo 0) subbootstep=$(cat /var/spool/subbootstep 2>/dev/null || echo 0) if [ "$splash" = "silent" ]; then if [ -e /proc/splash ]; then echo "show $((65534 * $bootstep / ${BOOTSTEPS:-100} + ($subbootstep * 100)))" 2>/dev/null > /proc/splash else psplash-write "PROGRESS $((100 * $bootstep / ${BOOTSTEPS:-100} + ($subbootstep/6)))" fi fi } hide_splash() { if [ -e /proc/splash ]; then if echo "verbose" 2>/dev/null >/proc/splash && test -z "$1"; then # scroll one page down yes "" | head -n $(stty -F /dev/tty1 size | cut -d ' ' -f 1) > /dev/tty1 usleep 10000 fi else psplash-write "QUIT" fi } show_splash() { if [ "$splash" = "silent" ]; then if [ -e /proc/splash ]; then show_bootstep echo "silent" 2>/dev/null >/proc/splash else killall -q psplash psplash >/dev/null 2>&1 & fi fi } #call() #{ # if [ "$splash" = "silent" ]; then # eval "echo \"\$( ($1) 2>&1 )\"" & # else # eval "$1" # fi #} tr() { export LC_ALL=$LANG export TEXTDOMAIN eval "echo -en \"$(gettext "$1")\"" } register_setting() { name=$1 value=$2 description=$3 if [ -z "`grep -e "^$name=" /etc/rc.config`" ]; then if [ -z "$registerSetting" ]; then echo >> /etc/rc.config fi if [ -n "$description" ]; then echo "# $description" >> /etc/rc.config fi echo "$name=\"$value\"" >> /etc/rc.config eval "$name=\"$value\"" fi registerSetting=1 } update_setting() { name=$1 value=$2 description=$3 register_setting "$name" "$value" "$description" sed -ie "s|^$name=.*|$name=\"$value\"|g" /etc/rc.config eval "$name=\"$value\"" } register_config() { update_config "$1" "$2" "$3" } update_config() { search=$1 value=$2 file=$3 if grep -qs "$search" "$file"; then sed -ie "s|.*\($search\).*|$value|g" "$file" else echo -e "$value" >> "$file" fi } search_modules() { addon=$1 { pcimodules $addon; usbmodules $addon; } | /usr/bin/tr "\n" "," | sed "s/.$//" } load_modules() { name=$1 modullist=$2 status=0 if [ "$modullist" = "auto" ]; then eval "modullist=\"$(search_modules $name)\"" fi OLDIFS=$IFS IFS=, for modul in $modullist; do if [ -n "$modul" ]; then IFS=$OLDIFS eval "modprobe $modul" >>/dev/stdlog 2>&1 || status=$? IFS=, fi done echo "$modullist" > /tmp/$name.drivers return $status } unload_modules() { name=$1 status=0 OLDIFS=$IFS IFS="" modullist="$(echo -n ,$(cat /tmp/$name.drivers 2>/dev/null) | tac -bs ,)" IFS=, for modul in $modullist; do modul=${modul## } modul=${modul%% *} if [ -n "$modul" ]; then IFS=$OLDIFS modprobe -r $modul >>/dev/stdlog 2>/dev/null || status=$? IFS=, fi done return $status } setup_drivers() { name=${0##*/} name=${name%.*} values="$1" eval "driver=\"\$$(echo "$name" | /usr/bin/tr a-z- A-Z_)_DRIVER\"" auto="$(search_modules $name)" test "$driver" != "" && echo "$driver" test "$driver" != "$auto" -a -n "$auto" && echo "$auto" test "$driver" != "auto" && echo "auto" echo "-" echo "$values" } register_application() { /etc/applications/rc.register add "$1" "$2" "$3" } unregister_application() { /etc/applications/rc.register del "$1" "$2" "$3" }