在pi中启动屏幕之前的shell脚本

时间:2017-03-12 15:39:24

标签: linux shell raspberry-pi daemon startup

我有一个运行Jessie操作系统的覆盆子pi,并希望在它执行任何其他操作之前运行一个bash脚本来执行,例如启动画面。

shell脚本是一个简单的feh命令,因为我希望pi可以作为图片框架中图像的幻灯片显示而不是其他内容;因此需要pi立即启动shell脚本。

如果因为任何原因退出shell脚本,我可以使用重新启动它的功能也很棒。

我曾尝试过cron作业,/etc/init.d/etc/rc0.d,但是,这些作品还没有对我有用。

我在/home/imgs/slideshow.sh中有我的主shell脚本,然后我运行以下脚本来设置希望以init.d运行:

#!/bin/bash
sudo apt-get update
sudo apt-get install feh
sudo apt-get install xscreensaver
sudo apt-get upgrade

# Make slideshow startup file in init.d if it doesn't exit
# if it does, make a backup file and rewrite it
FILE=/etc/init.d/slideshow.sh
if [ -f "$FILE" ]
then
    sudo mv $FILE $FILE-backup-$(date +"%F-%T")
else
    echo "$FILE does not exist but will be created"
fi

# input this text into the file
/bin/cat <<EOM >"$FILE"
#!/bin/sh -e

DAEMON="slideshow" #Command to run
daemon_OPT=""  #arguments for your program
DAEMONUSER="user" #Program user
daemon_NAME="slideshow" #Program name (need to be identical to the executable).

PATH="/sbin:/bin:/usr/sbin:/usr/bin" #don't touch

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

d_start () {
        log_daemon_msg "Starting system $daemon_NAME Daemon"
    start-stop-daemon --background --name $daemon_NAME --start --quiet --chuid $DAEMONUSER --exec $DAEMON -- $daemon_OPT
        log_end_msg $?
}

d_stop () {
        log_daemon_msg "Stopping system $daemon_NAME Daemon"
        start-stop-daemon --name $daemon_NAME --stop --retry 5 --quiet --name $daemon_NAME
    log_end_msg $?
}

case "$1" in

        start|stop)
                d_${1}
                ;;

        restart|reload|force-reload)
                        d_stop
                        d_start
                ;;

        force-stop)
               d_stop
                killall -q $daemon_NAME || true #replace with an apropriate killing method
                sleep 2
                killall -q -9 $daemon_NAME || true #replace with an apropriate killing method
                ;;

        status)
                status_of_proc "$daemon_NAME" "$DAEMON" "system-wide $daemon_NAME" && exit 0 || exit $?
                ;;
        *)
                echo "Usage: /etc/init.d/$daemon_NAME {start|stop|force-stop|restart|reload|force-reload|status}"
                exit 1
                ;;
esac
exit 0
EOM


sudo chmod +x /etc/init.d/slideshow.sh
sudo chmod 0755 /etc/init.d/slideshow.sh
sudo chmod +x /home/pi/imgs/slideshow.sh
sudo chmod 0755 /home/pi/imgs/slideshow.sh
sudo systemctl daemon-reload
sudo update-rc.d slideshow.sh defaults

0 个答案:

没有答案