mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-10-20 02:42:03 +08:00
grub-btrfsd: Start subdaemon when --timeshift-auto
Fix #272 Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
GRUB_BTRFS_VERSION=4.12-master-2023-04-05T11:40:40+00:00
|
GRUB_BTRFS_VERSION=4.12-master-2023-04-05T15:09:30+00:00
|
||||||
|
|
||||||
# Disable grub-btrfs.
|
# Disable grub-btrfs.
|
||||||
# Default: "false"
|
# Default: "false"
|
||||||
|
|||||||
+22
-18
@@ -243,31 +243,33 @@ set_snapshot_dir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
daemon_function() {
|
daemon_function() {
|
||||||
|
trap 'vlog "$BASHPID: Received SIGINT/ SIGTERM"; exit 0' SIGINT SIGTERM
|
||||||
# start the actual daemon
|
# start the actual daemon
|
||||||
snapdir=$1
|
snapdir=$1
|
||||||
vlog "Snapshot dir watchtimeout: $watchtime"
|
vlog "Subdaemon function started, PID: $BASHPID" "${GREEN}"
|
||||||
vlog "Entering infinite while for $snapdir" "${GREEN}"
|
vlog "${BASHPID}: Entering infinite while for $snapdir" "${GREEN}"
|
||||||
|
vlog "${BASHPID}: Snapshot dir watchtimeout: $watchtime"
|
||||||
while true; do
|
while true; do
|
||||||
runs=false
|
runs=false
|
||||||
if [ ${timeshift_auto} = true ] && ! [ "${timeshift_pid}" -gt 0 ] ; then
|
if [ ${timeshift_auto} = true ] && ! [ "${timeshift_pid}" -gt 0 ] ; then
|
||||||
# watch the timeshift folder for a folder that is created when timeshift starts up
|
# watch the timeshift folder for a folder that is created when timeshift starts up
|
||||||
sleep 1 # for safety so the outer while is not going crazy
|
sleep 1 # for safety so the outer while is not going crazy
|
||||||
if [ "${timeshift_pid}" -eq -2 ]; then
|
if [ "${timeshift_pid}" -eq -2 ]; then
|
||||||
log "detected timeshift shutdown"
|
log "${BASHPID}: detected timeshift shutdown"
|
||||||
fi
|
fi
|
||||||
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
|
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
|
||||||
if [ "${#timeshift_pid}" -gt 0 ]; then
|
if [ "${#timeshift_pid}" -gt 0 ]; then
|
||||||
set_snapshot_dir
|
set_snapshot_dir
|
||||||
log "detected running Timeshift at daemon startup, PID is: $timeshift_pid"
|
log "${BASHPID}: detected running Timeshift at daemon startup, PID is: $timeshift_pid"
|
||||||
vlog "new snapshots directory is $snapdir"
|
vlog "${BASHPID}: new snapshots directory is $snapdir"
|
||||||
else
|
else
|
||||||
log "Watching /run/timeshift for timeshift to start"
|
log "Watching /run/timeshift for timeshift to start"
|
||||||
inotifywait ${inotify_qiet_flag} -e create -e delete /run/timeshift && {
|
inotifywait ${inotify_qiet_flag} -e create -e delete /run/timeshift && {
|
||||||
sleep 1
|
sleep 1
|
||||||
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
|
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
|
||||||
set_snapshot_dir
|
set_snapshot_dir
|
||||||
log "detected Timeshift startup, PID is: $timeshift_pid" "${CYAN}"
|
log "${BASHPID}: detected Timeshift startup, PID is: $timeshift_pid" "${CYAN}"
|
||||||
vlog "new snapshots directory is $snapdir" "${CYAN}"
|
vlog "${BASHPID}: new snapshots directory is $snapdir" "${CYAN}"
|
||||||
(create_grub_menu) # create the grub menu once immidiatly in a forking process. Snapshots from commandline using timeshift --create need this
|
(create_grub_menu) # create the grub menu once immidiatly in a forking process. Snapshots from commandline using timeshift --create need this
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
@@ -276,13 +278,13 @@ daemon_function() {
|
|||||||
while [ -d "$snapdir" ]; do
|
while [ -d "$snapdir" ]; do
|
||||||
# watch the actual snapshots folder for a new snapshot or a deletion of a snapshot
|
# watch the actual snapshots folder for a new snapshot or a deletion of a snapshot
|
||||||
if [ ${runs} = false ] && [ ${verbose} = false ]; then
|
if [ ${runs} = false ] && [ ${verbose} = false ]; then
|
||||||
log "Watching $snapdir for new snapshots..." "${CYAN}"
|
log "${BASHPID}: Watching $snapdir for new snapshots..." "${CYAN}"
|
||||||
else
|
else
|
||||||
vlog "Watching $snapdir for new snapshots..." "${CYAN}"
|
vlog "${BASHPID}: Watching $snapdir for new snapshots..." "${CYAN}"
|
||||||
fi
|
fi
|
||||||
runs=true
|
runs=true
|
||||||
inotifywait ${inotify_qiet_flag} ${inotify_recursive_flag} -e create -e delete -e unmount -t "$watchtime" "$snapdir" && {
|
inotifywait ${inotify_qiet_flag} ${inotify_recursive_flag} -e create -e delete -e unmount -t "$watchtime" "$snapdir" && {
|
||||||
log "Detected snapshot creation/ deletion, recreating Grub menu" "${CYAN}"
|
log "${BASHPID}: Detected snapshot creation/ deletion, recreating Grub menu" "${CYAN}"
|
||||||
sleep 5
|
sleep 5
|
||||||
create_grub_menu
|
create_grub_menu
|
||||||
}
|
}
|
||||||
@@ -296,15 +298,17 @@ daemon_function() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# for all dirs that got passed to the script, start a new fork with that dir
|
|
||||||
snapdirs=( "${@}" )
|
if [ ${timeshift_auto} = true ] ; then
|
||||||
for snapdir in "${snapdirs[@]}"
|
daemon_function &
|
||||||
|
else
|
||||||
|
# for all dirs that got passed to the script, start a new fork with that dir
|
||||||
|
snapdirs=( "${@}" )
|
||||||
|
for snapdir in "${snapdirs[@]}"
|
||||||
do
|
do
|
||||||
vlog "starting daemon with watching $snapdir..."
|
vlog "starting daemon watching $snapdir..."
|
||||||
daemon_function "${snapdir}" &
|
daemon_function "${snapdir}" &
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
wait # wait for forks to finish, kill child forks if SIGTERM is sent
|
wait # wait for forks to finish, kill child forks if SIGTERM is sent
|
||||||
|
|
||||||
|
|
||||||
exit 0 # tradition is tradition
|
exit 0 # tradition is tradition
|
||||||
|
|||||||
Reference in New Issue
Block a user