1#!/bin/sh 2# 3# Usage: 4# bootanim start [timeout] 5# bootanim stop 6# 7# Example hook: 8# root@RK3588:/# more /etc/bootanim.d/gst-bootanim.sh 9# #!/bin/sh 10# touch ${TAG_FILE:-/dev/null} 11# gst-play-1.0 /etc/bootanim.d/bootanim.mp4 -q --no-interactive& 12 13export TAG_FILE=/tmp/.bootanim 14rm -f $TAG_FILE 15 16SCRIPT=/usr/bin/bootanim 17HOOK_DIR=/etc/bootanim.d/ 18PID_FILE=/tmp/bootanim.pid 19LOG_FILE=/tmp/bootanim.log 20TIMEOUT=${2:-${BOOTANIM_DEFAULT_TIMEOUT:-5}} 21 22pid_sid() 23{ 24 ps x -o pid,sid | grep -w $@ 25} 26 27bootanim_start() 28{ 29 [ -d $HOOK_DIR ] || return 30 31 echo "Starting bootanim: $$..." 32 33 # Freeze display server 34 touch /dev/null $XSERVER_FREEZE_DISPLAY $WESTON_FREEZE_DISPLAY 35 36 # Start bootanim hooks 37 for hook in $(find $HOOK_DIR -maxdepth 1 -name "*.sh"); do 38 echo "Starting hook: $hook..." 39 $hook 40 echo "Started hook: $hook..." 41 done 42 43 # Save bootanim's pid 44 echo $$ > $PID_FILE 45 46 # Exit when no animation started 47 if [ ! -e "$TAG_FILE" ]; then 48 bootanim_stop 2>&1 | tee -a $LOG_FILE 49 return 50 fi 51 52 # Timeout killer 53 start-stop-daemon -S -q -b -n bootanim-stop \ 54 -x /bin/sh -- -c "sleep $TIMEOUT; $SCRIPT stop" 55} 56 57bootanim_stop() 58{ 59 [ -f $PID_FILE ] || return 60 61 # Parse our sid (same as bootanim's pid) 62 SID=$(cat $PID_FILE; rm -rf $PID_FILE) 63 [ -n "$SID" ] || return 64 65 # Parse children pid 66 CPID=$(pid_sid $SID | xargs -n 2 | cut -d' ' -f1 | xargs) 67 68 echo "Stopping bootanim: ${CPID:-none} for $SID..." 69 70 # Pause children 71 [ -z "$CPID" ] || kill -STOP $CPID &>/dev/null 72 73 # Unfreeze display server 74 rm -f $XSERVER_FREEZE_DISPLAY $WESTON_FREEZE_DISPLAY 75 sleep .1 76 77 # Kill children 78 [ -z "$CPID" ] || kill -9 $CPID &>/dev/null 79} 80 81case "$1" in 82 start|"") 83 # Make sure that we own this session (pid equals sid) 84 if ! pid_sid -q "$$$" || [ $(realpath "$0") != $SCRIPT ] ; then 85 setsid $SCRIPT $@ 86 else 87 # Run it 88 $SCRIPT stop 89 bootanim_start 2>&1 | tee -a $LOG_FILE& 90 fi 91 ;; 92 stop) 93 bootanim_stop 2>&1 | tee -a $LOG_FILE 94 ;; 95 *) 96 echo "Usage: $0 [start|stop]" 97 ;; 98esac 99 100: 101