dtfscripts: Major refactor with more modular service startup

This commit is contained in:
Salt 2018-08-26 16:11:25 -05:00
parent 5bb89623dc
commit 8a67f17003
14 changed files with 234 additions and 179 deletions

View File

@ -72,5 +72,6 @@ bspc rule -a explorer.exe state=fullscreen
bspc rule -a plasmashell state=floating sticky=on border=off bspc rule -a plasmashell state=floating sticky=on border=off
bspc rule -a krunner state=floating layer=above sticky=on border=off bspc rule -a krunner state=floating layer=above sticky=on border=off
# Widgets # Widgets
bspc rule -a Conky state=floating layer=below sticky=on
bspc rule -a pavucontrol-qt state=floating layer=above sticky=on bspc rule -a pavucontrol-qt state=floating layer=above sticky=on

View File

@ -5,6 +5,7 @@ conky.config = {
own_window_title = 'Conky', own_window_title = 'Conky',
own_window_class = 'Conky', own_window_class = 'Conky',
own_window_type = 'desktop', own_window_type = 'desktop',
own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
own_window_colour = '282828', own_window_colour = '282828',
double_buffer = true, double_buffer = true,

View File

@ -0,0 +1,53 @@
#! /usr/bin/env bash
#
# wmstartup service common functions
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
service_name="unnamed_service"
service_process="true"
function svc_log() {
if [ -z ${1+x} ]; then return 1; fi
dtf_log "$service_name: $1"
}
function prestart() {
if ! which $service_process > /dev/null 2>&1; then
svc_log "Could not find process"
return 1
fi
return 0
}
function start() {
if ! prestart; then
svc_log "Failed pre-start checks"
return 1
fi
svc_log "Starting"
$service_process > /dev/null 2>&1 &
return 0
}
function stop() {
svc_log "Stopping"
killall $service_process &
for i in {1..100}; do
if ! isup; then break; fi
sleep 0.01
if (( $i > 99 )); then
svc_log "Stopping with prejudice"
killall -9 $service_process
fi
done
return $?
}
function isup() {
pgrep "$service_process" > /dev/null 2>&1
return $?
}

View File

@ -0,0 +1,23 @@
#! /usr/bin/env bash
#
# Simple wmstartup service
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
source $DTF_SERVICES_DIR/common.bash
service_name="Compton"
service_process="compton"
function start() {
if [[ "$HOST" == "vm-*" ]]; then
svc_log "Will not start: in a VM"
return 0
else
svc_log "Starting"
$service_process > /dev/null 2>&1 &
return 0
fi
}

View File

@ -0,0 +1,24 @@
#! /usr/bin/env bash
#
# Simple wmstartup service
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
source $DTF_SERVICES_DIR/common.bash
service_name="Conky"
service_process="conky"
function start() {
if ! prestart; then
svc_log "Failed pre-start checks"
return 1
fi
for file in $XDG_CONFIG_HOME/conky/*.conf; do
svc_log "Starting with config $file"
conky -c $file > /dev/null 2>&1 &
done
return 0
}

View File

@ -0,0 +1,12 @@
#! /usr/bin/env bash
#
# Simple wmstartup service
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
source $DTF_SERVICES_DIR/common.bash
service_name="Dunst"
service_process="dunst"

View File

@ -0,0 +1,16 @@
#! /usr/bin/env bash
#
# Simple wmstartup service
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
source $DTF_SERVICES_DIR/common.bash
service_name="Krunner"
service_process="krunner"
function start() {
return 0
}

View File

@ -0,0 +1,12 @@
#! /usr/bin/env bash
#
# Simple wmstartup service
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
source $DTF_SERVICES_DIR/common.bash
service_name="Plasma"
service_process="plasmashell"

View File

@ -0,0 +1,35 @@
#! /usr/bin/env bash
#
# Simple wmstartup service
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
source $DTF_SERVICES_DIR/common.bash
service_name="Polybar"
service_process="polybar"
function start() {
if ! prestart; then
svc_log "Failed pre-start checks"
return 1
fi
export PB_MONITOR=$(xrandr -q | awk '/primary/{print $1}')
svc_log "Starting primary on monitor $PB_MONITOR"
polybar -r primary& > /dev/null 2>&1
polybar -r primary-2& > /dev/null 2>&1
export secondary_monitors=$(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}')
if [[ "$secondary_monitors" == "" ]]; then
return 0
fi
for monitor in $secondary monitors; do
svc_log "Starting secondary on monitor $monitor"
PB_MONITOR=$monitor
polybar -r secondary& > /dev/null 2>&1
polybar -r secondary-2& > /dev/null 2>&1
done
return 0
}

View File

@ -0,0 +1,23 @@
#! /usr/bin/env bash
#
# Simple wmstartup service
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
source $DTF_SERVICES_DIR/common.bash
service_name="sxhkd"
service_process="sxhkd"
function prestart() {
if ! which $service_process > /dev/null 2>&1; then
svc_log "Could not find process"
fi
if ! pgrep bspwm > /dev/null 2>&1; then
svc_log "Not under bspwm"
return 1
fi
return 0
}

View File

@ -20,11 +20,12 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
## Clean up some variables that I use in device-specific scripts ## Clean up some variables
# General # General
unset TERMINAL unset TERMINAL
# Specific to this script # Specific to this script
unset DTF_KILL_EXTRA unset DTF_KILL_EXTRA
unset DTF_SERVICES
# Polybar # Polybar
unset PB_MONITOR unset PB_MONITOR
unset PB_WM_RESTACK unset PB_WM_RESTACK
@ -39,158 +40,47 @@ unset PB_MODULE_WLAN_INTERFACE
unset BSPWM_DESKTOPS_TOTAL unset BSPWM_DESKTOPS_TOTAL
unset BSPWM_DESKTOPS_PRIMARY unset BSPWM_DESKTOPS_PRIMARY
## Patch path, if not already done # First parameter is the indentation level
if [[ "$PATH" != "*$HOME/.local/bin*" ]]; then # Second is the message
printf "[INFO] Patching path for $HOME/.local/bin\n" function dtf_log() {
name="$(basename $0 .sh)"
if [ -z ${1+x} ]; then return 1; fi
printf "$name: $1\n"
}
## Patch some directories
if [[ "$PATH" != *"$HOME/.local/bin"* ]]; then
dtf_log "Patching path for $HOME/.local/bin"
export PATH="$HOME/.local/bin:$PATH" export PATH="$HOME/.local/bin:$PATH"
fi fi
if [[ "$XDG_CONFIG_HOME" == "" ]]; then
## Set the runtime directory, if not already dtf_log "Correcting configuration directory"
export XDG_CONFIG_HOME="$HOME/.config"
fi
if [[ "$XDG_RUNTIME_DIR" == "" ]]; then if [[ "$XDG_RUNTIME_DIR" == "" ]]; then
dtf_log "Correcting runtime directory"
export XDG_RUNTIME_DIR="/run/user/$UID" export XDG_RUNTIME_DIR="/run/user/$UID"
fi fi
## Set some more variables
export DTF_SERVICES_DIR="$XDG_CONFIG_HOME/dtfscripts/services"
## Load device-specific scripts ## Load device-specific scripts
if [[ -x "$HOME/.config/dtfscripts/$(hostname).rc" ]]; then if [[ -x "$XDG_CONFIG_HOME/dtfscripts/devices/$(hostname).rc" ]]; then
printf "[INFO] Sourcing ~/.config/dtfscripts/$(hostname).rc\n" dtf_log "Sourcing devices/$(hostname).rc"
source $HOME/.config/dtfscripts/$(hostname).rc source $HOME/.config/dtfscripts/devices/$(hostname).rc
fi fi
printf "[INFO] Performing simple configuration\n" ## Run startup scripts
## SIMPLE CONFIGURATION for service in $DTF_SERVICES_DIR/*.dtf; do
xset -b (
xset -dpms source $service
xset s off if isup; then
# This depends on a script found at rehashedsalt/bin stop
xrdbupdate
## SERVICES AND DAEMONS
# Kill everything
printf "[INFO] Stopping existing services\n"
services="plasmashell krunner xfdesktop polybar compton conky sxhkd dunst xob"
for service in $services; do
printf " [INFO] Sending signal to all $service\n"
killall $service
done
# Kill more everything
printf "[INFO] Running secondary kill tasks\n"
for service in $DTF_KILL_EXTRA; do
printf " [INFO] Sending signal to all $service\n"
killall $service
done
# Wait for them to die
for service in $services; do
i=0
while pgrep $service > /dev/null 2>&1; do
if [[ "$i" = "10" ]]; then
printf " [INFO] Waited too long, killing $service with prejudice\n"
pkill -9 $service
break
else
printf " [INFO] Waiting on $service\n"
sleep 0.5
i=$(expr $i + 1)
fi fi
done start
unset i )
done done
# Start them back up dtf_log "Finished initialization"
printf "[INFO] Starting services\n"
# Start with key functionality
# SXHKD
if pgrep bspwm > /dev/null 2>&1; then
printf " [INFO] Found bspwm, starting sxhkd\n"
sxhkd &
else
printf " [WARN] bspwm was started, but sxhkd wasn't! Session may be unusable!\n"
fi
# Compton
if which compton > /dev/null 2>&1; then
# Don't start the compositor in a VM
if [[ $(hostname) != "vm"* ]]; then
printf " [INFO] Starting compton\n"
compton &
else
printf " [INFO] In a VM, not starting compositor\n"
fi
else
printf " [INFO] Could not find a compositor\n"
fi
# Polybar
if which polybar > /dev/null 2>&1; then
printf " [INFO] Starting polybar\n"
$HOME/.config/polybar/start.sh &
else
printf " [INFO] Could not find a bar\n"
fi
# Dunst
if which dunst > /dev/null 2>&1; then
printf " [INFO] Starting dunst\n"
dunst&
else
printf " [INFO] Could not find a notification daemon\n"
fi
# XOB
if which xob > /dev/null 2>&1; then
printf " [INFO] Starting xob instances\n"
pipes="brightness volume misc"
# Set up pipes
export XOB_PIPE_DIR="$XDG_RUNTIME_DIR/xob"
printf " [INFO] Using pipe directory \"$XOB_PIPE_DIR\"\n"
mkdir -m 700 "$XOB_PIPE_DIR"
for pipe in $pipes; do
if [ -p "$XOB_PIPE_DIR/$pipe" ]; then
printf " [INFO] Removing existing pipe \"$pipe\"\n"
rm "$XOB_PIPE_DIR/$pipe"
fi
mkfifo "$XOB_PIPE_DIR/$pipe"
if [ -p "$XOB_PIPE_DIR/$pipe" ]; then
printf " [INFO] Successfully created pipe \"$pipe\". Binding an xob instance to it\n"
export $pipe="$XOB_PIPE_DIR/$pipe"
tail -f "$XOB_PIPE_DIR/$pipe" | xob -s "$pipe" -t 2 &
else
printf " [WARN] Failed to create pipe \"$pipe\"\n"
fi
done
else
printf " [INFO] Could not find a bar overlay application\n"
fi
# Conky
if which conky > /dev/null 2>&1; then
printf " [INFO] Starting conky\n"
# Use all the config files in its config directory
for file in $HOME/.config/conky/*.conf; do
printf " [INFO] Found config file $file\n"
conky -c $file&
done
else
printf " [INFO] Could not find a desktop statistics application\n"
fi
# Wallpaper management
printf "[INFO] Setting wallpaper\n"
if which plasmashell > /dev/null 2>&1; then
printf " [INFO] Starting Plasma\n"
plasmashell &
elif which xfdesktop > /dev/null 2>&1; then
printf " [INFO] Starting xfdesktop\n"
xfdesktop --disable-wm-check&
elif which feh > /dev/null 2>&1; then
printf " [INFO] Setting wallpaper with feh\n"
printf " [WARN] This solution may cause problems on multi-monitor systems\n"
feh --randomize --bg-fill ~/Pictures/Wallpapers/.active &
elif which xsetroot > /dev/null 2>&1; then
printf " [INFO] Setting root window color\n"
xsetroot -solid "#282828"
else
printf " [WARN] Could not find a wallpaper manager\n"
fi
printf "[INFO] Finished initialization\n"

View File

@ -1,35 +0,0 @@
#!/bin/bash
#
# start.sh
# Copyright (C) 2018 salt <salt@iridium>
#
# Distributed under terms of the MIT license.
#
export PB_WM_RESTACK=bspwm
# Iterate through monitors and spawn bars on each
# Starting with the primary monitor...
export PB_MONITOR=$(xrandr -q | awk '/primary/{print $1}')
if [[ $PB_MONITOR == "" ]]; then
unset PB_MONITOR
fi
printf "[INFO] Starting Polybar primary on monitor $PB_MONITOR"
polybar -r primary&
polybar -r primary-2&
# ...and then moving on to secondaries, if we have them
# Alright, now this looks *really* bad, spawning so many subprocesses, but
# there's no way in hell you can get me to attempt to solve this with regex.
# To hell with regex. It starts more problems than it solves
export secondary_monitors=$(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}')
if [[ $secondary_monitors == "" ]]; then
exit 0
fi
for monitor in $secondary_monitors; do
printf "[INFO] Starting Polybar secondary on monitor $monitor"
PB_MONITOR=$monitor
polybar -r secondary&
polybar -r secondary-2&
done
disown
exit