Modularization, prepare for some more thorough XDG autostart checks

This commit is contained in:
Salt 2019-06-21 21:40:43 -05:00
parent bb0482cf54
commit f5cd12c6c8

View File

@ -41,20 +41,22 @@ err() {
exit "$2"
fi
}
startfile() {
# Start a program using an alternatives list
gettarget() {
# Parse a defaults file to get the target program
[ -z "$1" ] && return 1
! [ -r "$1" ] && return 2
if [ -x "$1" ]; then
# File is a script
"$1" &
disown "$!"
else
# File is a defaults file
while read line; do
echo "$line"
done < "$1"
fi
[ -r "$1" ] || return 1
# Every odd line is the check line
# Every even one is the exec line
while read -r checkline; do
read -r execline
if bash -c "$checkline" > /dev/null 2>&1; then
_return="$execline"
return 0
else
continue
fi
done < "$1"
return 2
}
# Steps in execution
@ -261,15 +263,6 @@ command -v kwin
kwin
command -v tinywm
tinywm
EOF
# XDG autostarter
cat << EOF > "$_configdir/xdg-autostart"
command -v dex
dex -a
command -v fbautostart
fbautostart
command -v xdg-autostart
xdg-autostart "\${XDG_CURRENT_DESKTOP:-firestarter}"
EOF
}
step_printhelp() {
@ -411,26 +404,22 @@ step_execute() {
local filename="$(basename -- "$file")"
local logfile="$_logdir/$filename"
[ -n "$FS_NOLOG" ] && logfile="/dev/null"
# Every odd line is the check line
# Every even one is the exec line
while read -r checkline; do
read -r execline
if bash -c "$checkline" > /dev/null 2>&1; then
log "Found target for \"$filename\": \"$execline\""
if ! [ "$_dryrun" = "1" ]; then
if [ -f "$logfile" ]; then
[ -f "$logfile.old" ] && rm "$logfile.old"
mv "$logfile" "$logfile.old"
fi
bash -c "$execline" > "$logfile" 2>&1 &
if gettarget "$file"; then
target="$_return"
log "Found target for \"$filename\": \"$target\""
if ! [ "$_dryrun" = "1" ]; then
if [ -f "$logfile" ]; then
[ -f "$logfile.old" ] && rm "$logfile.old"
mv "$logfile" "$logfile.old"
fi
break
else
continue
bash -c "$target" > "$logfile" 2>&1 &
fi
done < "$file"
fi
done
# And then source in a user script if it exists
}
step_postexecute() {
# Wait for the WM to initialize, if one was found
# Source in a user script if it exists
if [ -r "$_firestarterrc" ] && [ -z "$_dryrun" ]; then
log "Sourcing .firestarterrc"
"$_firestarterrc"
@ -487,6 +476,7 @@ main() {
step_check
step_preexecute
step_execute
step_postexecute
step_wait
return 0
}