📄 w_scan_start.sh
字号:
#!/bin/sh######################################################## w_scan start script# 20060812 wirbel (handygewinnspiel AET gmx D*T de)## - 20060812: first version# - 20060822: many improvements# cu@vdr-portal########################################################umask 022export PATH="$(pwd):/bin:/usr/bin:/sbin:/usr/sbin"DATE="$(date +%Y)$(date +%m)$(date +%d)" # $DATE == "YYYYMMDD", i.e. 20060710W_SCAN=$(which w_scan 2>/dev/null)UDEVSTART=$(which udevstart)SCRIPT_VERSION="20080105"W_SCAN_VERSION=$($W_SCAN -V 2>&1)# Width of the ScreenCOLUMNS=$(stty size)COLUMNS=${COLUMNS##* }if [ "$COLUMNS" = "0" ]; then COLUMNS=80;fi# Measurements for positioning result messagesCOL=$(($COLUMNS - 12))WCOL=$(($COLUMNS - 30))# Set Cursur Position Commands, used via echo -eSET_COL="\\033[${COL}G"SET_WCOL="\\033[${WCOL}G"CURS_UP="\\033[A"# Set color commands, used via echo -eNORMAL="\\033[40;39m"SUCCESS="\\033[40;32m"WARNING="\\033[40;33m"FAILURE="\\033[40;31m"echo_ok(){ echo -e "$CURS_UP$SET_COL"["$SUCCESS"" OK ""$NORMAL"]}echo_failure(){ echo -e "$CURS_UP$SET_COL"["$FAILURE"" FAILED ""$NORMAL"]}echo_warning(){ echo -e "$CURS_UP$SET_WCOL$@$SET_COL"["$WARNING"" WARN ""$NORMAL"]}echo_yes(){ echo -e "$CURS_UP$SET_COL"["$SUCCESS"" YES ""$NORMAL"]}echo_no(){ echo -e "$CURS_UP$SET_COL"["$SUCCESS"" NO ""$NORMAL"]}echo_loaded(){ echo -e "$CURS_UP$SET_COL"["$SUCCESS"" LOADED ""$NORMAL"]}echo_not_loaded(){ echo -e "$CURS_UP$SET_COL"["$FAILURE""NOT LOADED""$NORMAL"]}print_error_msg(){ echo -e -n $FAILURE echo "****************************************************************" echo "* FAILURE. Something doesn't work here, *" echo "* last command gives me an error.. :-( *" echo "* *" echo "* Press Enter to continue.. *" echo "****************************************************************" echo -e -n $NORMAL && tput sgr0 read ENTER echo -e -n $NORMAL}CheckBinary(){ if [ -d $1 ]; then echo -e -n $FAILURE echo "Checking binary $1.." echo "$1 is a directory, not a binary. Cannot continue - EXITING." echo -e -n $NORMAL tput sgr0 && clear && exit -1 fi if [ ! -f $1 ]; then echo -e -n $FAILURE echo "Checking binary $1.." echo "$1 is not a valid file or not found. Cannot continue - EXITING." echo -e -n $NORMAL tput sgr0 && clear && exit -1 fi if [ ! -s $1 ]; then echo -e -n $FAILURE echo "Checking binary $1 (file size).." echo "$1 is not a valid file (zero size!!). Cannot continue - EXITING." echo -e -n $NORMAL tput sgr0 && clear && exit -1 fi if [ ! -x $1 ]; then echo -e -n $FAILURE echo "Checking permissions of binary $1 .." echo "$1 is not executable. Check permissions! Cannot continue - EXITING." echo -e -n $NORMAL tput sgr0 && clear && exit -1 fi}CheckVersions(){ if [ "$W_SCAN_VERSION" != "$SCRIPT_VERSION" ]; then echo -e -n $FAILURE echo "Using $W_SCAN" echo "w_scan is version $W_SCAN_VERSION." echo "This start script is version $SCRIPT_VERSION." echo "Both of them _must_ have the same version." echo "Cannot continue - EXITING." echo -e -n $NORMAL tput sgr0 && clear && exit -1 fi}eval_retval(){ errval=$? if [ $errval = 0 ]; then print_status success else print_status failure fi return 0}print_status(){ if [ $# = 0 ]; then echo "Usage: $0 {success|warning|failure}" return 1 fi case "$1" in success) echo_ok ;; warning) case "$2" in running) echo_warning "Already running" ;; not_running) echo_warning "Not running" ;; not_available) echo_warning "Not available" ;; esac ;; failure) echo_failure ;; esac}function Greeting (){ clear echo -e -n $SUCCESS echo "==============================================================================" echo -e "THIS IS THE ""\\033[44m"" W_SCAN START SCRIPT ""\\033[40m$SUCCESS"" (see http://free.pages.at/wirbel4vdr)" echo "" echo "It will try the following:" echo "" echo " step 1) checks wether vdr is running and if so, try to stop it" echo " step 2) check wether your dvb driver is loaded and if not, load it" echo " step 3) do a channel scan and create a vdr channels.conf" echo " step 4) ask you, wether your vdr should be restarted" echo "" echo "PRESS ANY KEY TO CONTINUE OR CTRL+C TO EXIT" echo "==============================================================================" echo -e -n $NORMAL && tput sgr0 read echo -e -n $NORMAL}function StopVDR (){ echo "Checking wether Video Disk Recorder software is stopped..." if [ "$(ps -A | grep vdr)" != "" ]; then echo_no echo -e -n $FAILURE echo "****************************************************************" echo "* *" echo "* W_SCAN CANNOT CONTINUE WHILE VDR IS RUNNING. *" echo "* Should I try to stop vdr for you? [y/n] *" echo "* *" echo "****************************************************************" echo -e -n $NORMAL && tput sgr0 read RESPONSE echo -e -n $NORMAL if [ "$RESPONSE" != "y" ]; then echo "OKAY. Exiting w_scan start script." sleep 2 tput sgr0 && clear && exit -1 else clear stopped=false echo "Trying to stop vdr..." echo "Checking for ct-vdr style startscript.." if [ -e /etc/init.d/vdr ]; then # c't-vdr echo_yes $(/etc/init.d/vdr stop) stopped=true else echo_no fi if [ $stopped == false ]; then echo "Checking for linvdr style startscript.." if [ -e /etc/init.d/runvdr ]; then # linvdr echo_yes $(/etc/init.d/runvdr stop) $(/etc/init.d/runvdr loaddriver) else echo_no fi fi if [ $stopped == false ]; then echo "Checking for runvdr in /usr/local/bin.." if [ -e /usr/local/bin/runvdr ]; then # -|- echo_yes echo " Checking wether /usr/local/bin/runvdr knows 'stop'..." VAR="$(cat /usr/local/bin/runvdr | grep 'stop)')" if [ "$VAR" != "" ]; then echo_yes $(/usr/local/bin/runvdr stop) else echo_no fi else echo_no fi fi if [ $stopped == false ]; then echo "Checking for runvdr in /usr/bin.." if [ -e /usr/bin/runvdr ]; then # -|- echo_yes echo " Checking wether this /usr/bin/runvdr knows 'stop'..." VAR="$(cat /usr/bin/vdr | grep 'stop)')" if [ "$VAR" != "" ]; then echo_yes $(/usr/bin/runvdr stop) else echo_no fi else echo_no fi fi if [ $stopped == false ]; then if [ "$(ps -A | grep vdr)" != "" ]; then # last Chance, but unusual system anyway.. echo "No stop script found - using killall.." KILLALL=$(which killall) $($KILLALL -9 vdr 2>&1 > /dev/null) $($KILLALL -9 runvdr 2>&1 > /dev/null) sleep 6 if [ "$(ps -A | grep vdr)" != "" ]; then # we should re-check here echo_failure echo "VDR is running and cannot be stopped - giving up." tput sgr0 && clear && exit -1 else echo_ok fi fi fi fi else echo_ok fi}function StartVDR (){ echo -e -n $SUCCESS echo "****************************************************************" echo "* *" echo "* All is done now. *" echo "* Should I try to restart vdr for you? [y/n] *" echo "* *" echo "****************************************************************" echo -e -n $NORMAL && tput sgr0 read RESPONSE echo -e -n $NORMAL if [ "$RESPONSE" != "y" ]; then echo -n -e "\\033[1;34m" echo "" echo "Okay, restarting vdr skipped." echo "GOODBYE! Exiting now." echo "" echo -e -n $NORMAL tput sgr0 && clear && exit 0 else started=false if [ -e /etc/init.d/vdr ]; then # c't-vdr /etc/init.d/vdr start started=true fi if [ $started == false ]; then if [ -e /etc/init.d/runvdr ]; then # linvdr /etc/init.d/runvdr start started=true fi fi if [ $started == false ]; then if [ -e /usr/local/bin/runvdr ]; then # -|- echo " Checking wether /usr/local/bin/runvdr knows 'start'.." VAR="$(cat /usr/local/bin/runvdr | grep 'start)')" if [ "$VAR" != "" ]; then echo_yes /usr/local/bin/runvdr start started=true else echo_no fi fi fi if [ $started == true ]; then if [ -e /usr/bin/runvdr ]; then # -|- echo " Checking wether this /usr/bin/runvdr knows 'start'..." VAR="$(cat /usr/bin/runvdr | grep 'start)')" if [ "$VAR" != "" ]; then echo_yes /usr/bin/runvdr start started=true else echo_no fi fi fi echo -n -e "\\033[1;34m" echo "" echo "On most systems vdr should run now - if not, reboot." echo "GOODBYE! Exiting now." echo "" echo -e -n $NORMAL fi}function LoadDriver (){ # debug messages to stdout [true/false] DEBUG_LOADDRIVER=false # <SPACE> separated lists
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -