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