149 lines
2.5 KiB
Bash
Executable File
149 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Usage:
|
|
# bootanim start [timeout]
|
|
# bootanim stop
|
|
#
|
|
# Example hook:
|
|
# root@RK3588:/# more /etc/bootanim.d/gst-bootanim.sh
|
|
# #!/bin/sh
|
|
# [ -r /etc/bootanim.d/bootanim.mp4 ] || exit 1
|
|
# gst-play-1.0 /etc/bootanim.d/bootanim.mp4 -q --no-interactive&
|
|
|
|
SCRIPT=/usr/bin/bootanim
|
|
HOOK_DIR=/etc/bootanim.d/
|
|
PID_FILE=/var/run/bootanim.pid
|
|
TIMEOUT=${2:-${BOOTANIM_DEFAULT_TIMEOUT:-10}}
|
|
|
|
log()
|
|
{
|
|
if which logger >/dev/null; then
|
|
logger -t bootanim $@
|
|
fi
|
|
echo "bootanim: $@"
|
|
}
|
|
|
|
pid_by_sid()
|
|
{
|
|
sed "s/(.*)//" /proc/*/stat 2>/dev/null | cut -d' ' -f1,6 | grep -w "$1$" |
|
|
cut -d' ' -f1 || true
|
|
}
|
|
|
|
sid_by_pid()
|
|
{
|
|
sed "s/(.*)//" /proc/$1/stat | cut -d' ' -f6
|
|
}
|
|
|
|
bootanim_init()
|
|
{
|
|
# Save bootanim's pid
|
|
echo $$ > $PID_FILE
|
|
|
|
# Freeze display service
|
|
touch /dev/null $XSERVER_FREEZE_DISPLAY $WESTON_FREEZE_DISPLAY
|
|
}
|
|
|
|
bootanim_deinit()
|
|
{
|
|
# Kick display service
|
|
echo "compositor:state:on" >> ${WESTON_DRM_CONFIG:-/tmp/.weston_drm.conf}
|
|
xrefresh >/dev/null 2>/dev/null
|
|
|
|
# Unfreeze display service
|
|
rm -rf $XSERVER_FREEZE_DISPLAY $WESTON_FREEZE_DISPLAY
|
|
|
|
rm -rf "$PID_FILE"
|
|
}
|
|
|
|
bootanim_start()
|
|
{
|
|
[ -d $HOOK_DIR ] || return
|
|
|
|
log "Starting bootanim..."
|
|
|
|
bootanim_init
|
|
|
|
# Start bootanim hooks
|
|
unset BOOTANIM_STARTED
|
|
for hook in $(find $HOOK_DIR -maxdepth 1 -name "*.sh"); do
|
|
log "Starting hook: $hook..."
|
|
if $hook; then
|
|
BOOTANIM_STARTED=1
|
|
fi
|
|
log "Started hook: $hook..."
|
|
done
|
|
|
|
if [ -z "$BOOTANIM_STARTED" ]; then
|
|
log "No animation started..."
|
|
bootanim_deinit
|
|
return
|
|
fi
|
|
|
|
# Timeout killer
|
|
{
|
|
for t in $(seq 1 "$TIMEOUT"); do
|
|
# Check panel for x11 desktop
|
|
if ls -l /proc/*/exe 2>/dev/null | grep -wq panel; then
|
|
# Wait for panel painting
|
|
sleep 1
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
bootanim_stop
|
|
}&
|
|
}
|
|
|
|
children_pid()
|
|
{
|
|
[ -f $PID_FILE ] || return
|
|
|
|
SID=$(cat $PID_FILE)
|
|
[ "$SID" ] || return
|
|
|
|
pid_by_sid $SID | grep -wv $SID || true
|
|
}
|
|
|
|
bootanim_stop()
|
|
{
|
|
log "Stopping bootanim..."
|
|
|
|
# Parse children pid
|
|
CPID=$(children_pid)
|
|
|
|
if [ -z "$CPID" ]; then
|
|
bootanim_deinit
|
|
return
|
|
fi
|
|
|
|
{
|
|
# Pause animation -> unfreeze display -> kill animation
|
|
kill -STOP $CPID >/dev/null 2>/dev/null || true
|
|
bootanim_deinit
|
|
sleep 1
|
|
kill -9 $CPID >/dev/null 2>/dev/null || true
|
|
}&
|
|
wait
|
|
}
|
|
|
|
case "$1" in
|
|
start|"")
|
|
# Make sure that we own this session (pid equals sid)
|
|
if [ $(sid_by_pid $$) != $$ ] ||
|
|
[ $(realpath "$0") != $SCRIPT ] ; then
|
|
setsid $SCRIPT $@
|
|
else
|
|
bootanim_stop || true
|
|
bootanim_start
|
|
fi
|
|
;;
|
|
stop)
|
|
bootanim_stop
|
|
;;
|
|
*)
|
|
echo "Usage: $0 [start|stop]"
|
|
;;
|
|
esac
|
|
|
|
:
|