Add a basic functional implementation
This commit is contained in:
parent
915def6100
commit
81e1dadb71
41
README.md
Normal file
41
README.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Firestarter
|
||||
|
||||
## Overview
|
||||
|
||||
**Firestarter** is a desktop environment startup script. Its job is to abstract out the startup and configuration of basic X session components. By default, it will attempt to piece together a fully functional desktop environment based on currently available programs and configuration files found in `~/.config/firestarter`. See [Usage](#usage) for details.
|
||||
|
||||
## Installation
|
||||
|
||||
Execute `firestarter` as your `.xinitrc`, either by replacing the file or by `exec`ing it after performing your own basic setup.
|
||||
|
||||
## Quickstart
|
||||
|
||||
Install as instructed per [Installation](#installation). Then, before starting the session, run Firestarter with the `-g` flag to produce default configs in `~/.config/firestarter`. These default configuration files can start most sessions, but can be edited to contain alternatives if desired.
|
||||
|
||||
## Configuration
|
||||
|
||||
When invoked with `firestarter -g`, Firestarter will generate a series of configuration files in `~/.config/firestarter`. These files consist of several lines that look like the following:
|
||||
|
||||
command -v i3
|
||||
i3
|
||||
|
||||
Every odd line is a command that must succeed in order for the following even line to be executed. Once an even command is executed, parsing stops. When Firestarter is invoked with no arguments, every configuration file is parsed this way.
|
||||
|
||||
If you would like to prevent all later alternatives from being parsed, simply set `:` or similar as an execution line. As an example, the following configuration file will only attempt to start a bar in an X environment:
|
||||
|
||||
[ -z "$DISPLAY" ]
|
||||
:
|
||||
command -v polybar
|
||||
polybar bar
|
||||
command -v lemonbar
|
||||
~/.bin/lemonbar.sh | lemonbar
|
||||
|
||||
All STDOUT and STDERR messages from these commands are saved to a logfile in '~/.local/share/firestarter/logs` under the same name as the configuration file.
|
||||
|
||||
## Usage
|
||||
|
||||
See `firestarter -h`
|
||||
|
||||
## Contribution
|
||||
|
||||
Firestarter by no means contains an exhaustive list of all possible programs. If you know of or have created a program that should be added, *please* open an issue about it. The script should be light but its choices massive.
|
332
firestarter
Executable file
332
firestarter
Executable file
@ -0,0 +1,332 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# firestarter.bash
|
||||
# A desktop environment startup script
|
||||
# Copyright (C) 2019 Vintage Salt <rehashedsalt@cock.li>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
#
|
||||
|
||||
# "Globals"
|
||||
g_name="firestarter"
|
||||
g_configdir="${XDG_CONFIG_HOME:-$HOME/.config}/$g_name"
|
||||
g_logdir="${XDG_DATA_HOME:-$HOME/.local/share}/$g_name/logs"
|
||||
|
||||
# Basic functions
|
||||
print() {
|
||||
# Write a message to STDOUT without a name attached
|
||||
[ -z "$1" ] && return 1
|
||||
printf "%s\\n" \
|
||||
"$1"
|
||||
}
|
||||
log() {
|
||||
# Write a message to STDOUT
|
||||
[ -z "$1" ] && return 1
|
||||
printf "%s log: %s\\n" \
|
||||
"$g_name" \
|
||||
"$1" >&1
|
||||
}
|
||||
err() {
|
||||
# Write a message to STDERR, also exit if arg 2 is specified
|
||||
[ -z "$1" ] && return 1
|
||||
printf "%s err: %s\\n" \
|
||||
"$g_name" \
|
||||
"$1" >&2
|
||||
[ -z "$2" ] && return 0
|
||||
if ! [ "$2" -ge "0" ] > /dev/null 2>&1; then
|
||||
err "Attempted to exit with malformed exit code \"$2\"" 10
|
||||
else
|
||||
exit "$2"
|
||||
fi
|
||||
}
|
||||
startfile() {
|
||||
# Start a program using an alternatives list
|
||||
[ -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
|
||||
}
|
||||
|
||||
# Steps in execution
|
||||
step_generate() {
|
||||
log "Creating default config setup in \"$g_configdir\""
|
||||
log "See firestarter -h for more information"
|
||||
# Audio daemon
|
||||
cat << EOF > "$g_configdir/audio-daemon"
|
||||
command -v pulseaudio
|
||||
pulseaudio
|
||||
EOF
|
||||
# Information bars
|
||||
cat << EOF > "$g_configdir/bar"
|
||||
command -v tint2
|
||||
tint2
|
||||
command -v lxpanel
|
||||
lxpanel
|
||||
command -v lxqt-panel
|
||||
lxqt-panel
|
||||
command -v mate-panel
|
||||
mate-panel
|
||||
command -v xfce4-panel
|
||||
xfce4-panel
|
||||
EOF
|
||||
# Polkit authentication agents
|
||||
cat << EOF > "$g_configdir/polkit-agent"
|
||||
command -v lxqt-policykit-agent
|
||||
lxqt-policykit-agent
|
||||
command -v lxpolkit
|
||||
lxpolkit
|
||||
command -v mate-polkit
|
||||
mate-polkit
|
||||
command -v polkit-efl-authentication-agent-1
|
||||
polkit-efl-authentication-agent-1
|
||||
EOF
|
||||
# Power daemons
|
||||
cat << EOF > "$g_configdir/power-daemon"
|
||||
command -v batterymon
|
||||
batterymon
|
||||
command -v cbatticon
|
||||
cbatticon
|
||||
command -v lxqt-powermangement
|
||||
lxqt-powermanagement
|
||||
command -v xfce4-power-manager
|
||||
xfce4-power-manager
|
||||
command -v mate-power-manager
|
||||
mate-power-manager
|
||||
command -v gnome-power-manager
|
||||
gnome-power-manager
|
||||
EOF
|
||||
# Settings daemons
|
||||
cat << EOF > "$g_configdir/settings-daemon"
|
||||
command -v xsettingsd
|
||||
xsettingsd
|
||||
command -v xsettings-kde
|
||||
xsettingskde
|
||||
command -v xfsettingsd
|
||||
xfsettingsd
|
||||
command -v mate-settings-daemon
|
||||
mate-settings-daemon
|
||||
command -v gnome-settings-daemon
|
||||
gnome-settings-daemon
|
||||
EOF
|
||||
# X compositor
|
||||
cat << EOF > "$g_configdir/x-compositor"
|
||||
[ -z "\$DISPLAY" ]
|
||||
:
|
||||
command -v unagi
|
||||
unagi
|
||||
command -v compton
|
||||
compton
|
||||
command -v xcompmgr
|
||||
xcompmgr
|
||||
EOF
|
||||
# X hotkey daemon
|
||||
cat << EOF > "$g_configdir/x-hotkey-daemon"
|
||||
[ -z "\$DISPLAY" ]
|
||||
:
|
||||
command -v sxhkd
|
||||
sxhkd
|
||||
EOF
|
||||
# X notification daemon
|
||||
cat << EOF > "$g_configdir/x-notification-daemon"
|
||||
[ -z "\$DISPLAY" ]
|
||||
:
|
||||
command -v dunst
|
||||
dunst
|
||||
command -v lxqt-notificationd
|
||||
notificationd
|
||||
EOF
|
||||
# X window managers
|
||||
cat << EOF > "$g_configdir/x-wm"
|
||||
[ -z "\$DISPLAY" ]
|
||||
:
|
||||
command -v 2bwm
|
||||
2bwm
|
||||
command -v aewm
|
||||
aewm
|
||||
command -v awesome
|
||||
awesome
|
||||
command -v bspwm
|
||||
bspwm
|
||||
command -v catwm
|
||||
catwm
|
||||
command -v cwm
|
||||
cwm
|
||||
command -v dwm
|
||||
dwm
|
||||
command -v evilwm
|
||||
evilwm
|
||||
command -v exwm
|
||||
exwm
|
||||
command -v fluxbox
|
||||
fluxbox
|
||||
command -v flwm
|
||||
flwm
|
||||
command -v fvwm
|
||||
fvwm
|
||||
command -v herbstluftwm
|
||||
herbstluftwm
|
||||
command -v i3
|
||||
i3
|
||||
command -v icewm
|
||||
icewm
|
||||
command -v jbwm
|
||||
jbwm
|
||||
command -v jwm
|
||||
jwm
|
||||
command -v lwm
|
||||
lwm
|
||||
command -v openbox
|
||||
openbox
|
||||
command -v pawm
|
||||
pawm
|
||||
command -v ratpoison
|
||||
ratpoison
|
||||
command -v twm
|
||||
twm
|
||||
command -v windowmaker
|
||||
windowmaker
|
||||
command -v wmii
|
||||
wmii
|
||||
command -v xmonad
|
||||
xmonad
|
||||
command -v xfwm4
|
||||
xfwm4
|
||||
command -v metacity
|
||||
metacity
|
||||
command -v mutter
|
||||
mutter
|
||||
command -v kwin
|
||||
kwin
|
||||
command -v tinywm
|
||||
tinywm
|
||||
EOF
|
||||
}
|
||||
step_printhelp() {
|
||||
cat << EOF
|
||||
Usage: $0 [OPTION...]
|
||||
Start or generate a desktop environment configuration
|
||||
|
||||
-h Show this help text
|
||||
-g Generate a default configuration
|
||||
-d Perform a dry run. This will print the results of all decisions
|
||||
without executing them.
|
||||
|
||||
Firestarter Copyright (c) 2019 Vintage Salt
|
||||
Licensed under the terms of the MIT License
|
||||
https://gitlab.com/rehashedsalt/firestarter
|
||||
EOF
|
||||
}
|
||||
step_preexecute() {
|
||||
# Special things that can't use simple configuration files
|
||||
[ "$dryrun" == "1" ] && return 0
|
||||
|
||||
# dbus
|
||||
if \
|
||||
[ -z "$DBUS_SESSION_BUS_ADDRESS" ] && \
|
||||
[ -n "$XDG_RUNTIME_DIR" ] && \
|
||||
[ "$XDG_RUNTIME_DIR" == "/run/user/$(id -u)" ] && \
|
||||
[ -S "$XDG_RUNTIME_DIR/bus" ]; then
|
||||
# We already have a bus started, use it
|
||||
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
|
||||
hasdbus=1
|
||||
elif \
|
||||
[ -z "$DBUS_SESSION_BUS_ADDRESS" ] && \
|
||||
command -v dbus-launch > /dev/null 2>&1; then
|
||||
# We have dbus but haven't started up a bus yet
|
||||
eval "$(dbus-launch --exit-with-session --sh-syntax)"
|
||||
hasdbus=1
|
||||
else
|
||||
log "Did not start dbus; some applications may misbehave"
|
||||
fi
|
||||
if [ -n "$hasdbus" ]; then
|
||||
if command -v dbus-update-activation-environment > /dev/null 2>&1; then
|
||||
dbus-update-activation-environment --verbose --systemd --all > /dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
unset hasdbus
|
||||
}
|
||||
step_execute() {
|
||||
if ! [ -d "$g_configdir" ]; then
|
||||
if ! mkdir -p "$g_configdir" > /dev/null 2>&1; then
|
||||
err "Failed to create configuration directory \"$g_configdir\"" 52
|
||||
fi
|
||||
fi
|
||||
if ! [ -d "$g_logdir" ]; then
|
||||
if ! mkdir -p "$g_logdir" > /dev/null 2>&1; then
|
||||
err "Failed to create log directory \"$g_logdir\"" 53
|
||||
fi
|
||||
fi
|
||||
for file in "$g_configdir"/*; do
|
||||
if ! [ -f "$file" ]; then
|
||||
err "No configuration files found; please run \"$0 -g\"" 54
|
||||
fi
|
||||
filename="$(basename -- "$file")"
|
||||
logfile="$g_logdir/$filename"
|
||||
# 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 [ -f "$logfile" ]; then
|
||||
[ -f "$logfile.old" ] && rm "$logfile.old"
|
||||
mv "$logfile" "$logfile.old"
|
||||
fi
|
||||
if ! [ "$dryrun" == "1" ]; then
|
||||
bash -c "$execline" > "$logfile" &
|
||||
fi
|
||||
break
|
||||
else
|
||||
continue
|
||||
fi
|
||||
done < "$file"
|
||||
done
|
||||
}
|
||||
step_wait() {
|
||||
[ "$dryrun" == "1" ] && exit 0
|
||||
log "Waiting for programs to exit"
|
||||
wait
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Main
|
||||
main() {
|
||||
while getopts ":dgh" opt; do
|
||||
case $opt in
|
||||
d)
|
||||
if ! [ "$dryrun" == "1" ]; then
|
||||
log "Performing a dry run"
|
||||
dryrun=1
|
||||
fi
|
||||
;;
|
||||
g)
|
||||
step_generate
|
||||
exit $?
|
||||
;;
|
||||
h)
|
||||
step_printhelp
|
||||
exit $?
|
||||
;;
|
||||
*)
|
||||
err "Unrecognized argument: \"$OPTARG\"" 50
|
||||
;;
|
||||
:)
|
||||
err "Invalid option: \"$OPTARG\"" 51
|
||||
;;
|
||||
esac
|
||||
done
|
||||
step_execute
|
||||
step_wait
|
||||
return 0
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user