commit dd4979b215b6ca1ebd8dc5e8a5952155c3380ad3
parent 354869621a97b49a7721c2854ea0133166be089d
Author: mcol <mcol@posteo.net>
Date: Sun, 17 Mar 2019 14:43:55 +0000
adapted for system-wide installation with makefile
Diffstat:
10 files changed, 192 insertions(+), 39 deletions(-)
diff --git a/lemontools b/lemontools
@@ -86,6 +86,35 @@ exit
}
+get_dir() {
+ # check in order of priority
+ [[ -d $HOME/.config/lemontools ]] &&
+ echo $HOME/.config/lemontools && return 0
+
+ [[ -d $HOME/.lemontools ]] &&
+ echo $HOME/.lemontools && return 0
+
+ # default to the first, after creating it
+ mkdir -p $HOME/.config/lemontools/modules
+ mkdir -p $HOME/.config/lemontools/run
+ mkdir -p $HOME/.config/lemontools/themes
+ echo $HOME/.config/lemontools
+ return 0
+}
+
+
+copy_eg_modules() {
+ cp -vn $dir_usr/modules/* $dir/modules/
+ exit
+}
+
+
+copy_eg_themes() {
+ cp -vn $dir_usr/themes/* $dir/themes/
+ exit
+}
+
+
log() {
# print a message to stdout and to the log file
echo $1 | tee -a $log
@@ -250,35 +279,55 @@ start_bar() {
done
}
+RED='\033[0;31m'
+BLUE='\033[0;34m'
+BBLUE='\033[1;34m'
+GREEN='\033[0;32m'
+ORANGE='\033[0;33m'
+CYAN='\033[0;36m'
+NC='\033[0m'
+
#-----------------------------------------------------------------------------------
## Parse inputs
#-----------------------------------------------------------------------------------
# Lemonbar directory
-dir=$(dirname $(readlink -f $0))
+dir=$(get_dir)
+dir_usr=/usr/share/lemontools
# Modules
modules_dir=$dir/modules
+modules_c_dir=$dir/modules_c
+modules_dir_usr=$dir_usr/modules
+modules_c_dir_usr=$dir_usr/modules_c
# process arguments
-while getopts ":hlTvt:f:k:KdDu:" arg; do
+while getopts ":hlTvt:f:k:KdDu:cC" arg; do
case $arg in
h) print_help
;;
- l) printf "Available modules:\n"
+ l) echo -e "${BLUE}Available modules:${NC}"
ls $modules_dir
+ echo -e "\n${BLUE}Packaged modules (pass -C to copy to $dir):${NC}"
+ ls $modules_dir_usr
exit
;;
- T) printf "Available themees:\n"
- ls -1 $dir/themes | sed "s/\.bar//g"
- exit
+ T) if [[ -z "$(ls -1 $dir/themes)" ]]
+ then
+ echo "${BLUE}Pass -c to copy example themes into $dir${NC}"
+ exit
+ else
+ printf "${BLUE}Available themes:${NC}\n"
+ ls -1 $dir/themes | sed "s/\.bar//g"
+ ls -1 $dir_usr/themes | sed "s/\.bar//g"
+ exit
+ fi
;;
t) theme=$OPTARG
- theme_specified=true
;;
v) print_variables
@@ -302,9 +351,15 @@ while getopts ":hlTvt:f:k:KdDu:" arg; do
cat_fifo=true
;;
- u) echo update_$OPTARG > $dir/run/fifo-*
+ u) [[ -n $(ls $dir/run) ]] && echo update_$OPTARG > $dir/run/fifo-*
exit
;;
+
+ c) copy_eg_themes
+ ;;
+
+ C) copy_eg_modules
+ ;;
esac
done
@@ -314,20 +369,29 @@ done
#----------------------------------------------------------------------------------
# Source global settings
-. $dir/global_settings
+[[ -f $dir/global_settings ]] && . $dir/global_settings
+
+# Select theme if not yet selected on command line or in global_settings
+# try X resource 'lemontools.theme'
+[[ -z "$theme" ]] && theme=$(xrdb -query -all | grep lemontools.theme | awk '{print $2}')
-# check existence of specified theme if one is specified
-if ${theme_specified:-false} && ! [[ -f "$dir/themes/$theme.bar" ]]
+# otherwise print message instructing how to select theme
+if [[ -z "$theme" ]]
then
- echo "Theme $theme does not exist."
+ echo "Select a theme either on the command line:"
+ echo " lemontools -t <theme>"
+ echo "By setting this X resource:"
+ echo " lemontools.theme : <theme>"
+ echo "Or by setting this variable in $dir/global_settings:"
+ echo " theme=<theme>"
exit 1
fi
-# if not, try getting theme from wm.bartheme X resource
-if [[ -z "$theme" ]] && ! theme=$(xgetres wm.bartheme)
+# check theme file exists
+if ! [[ -f "$dir/themes/$theme.bar" ]]
then
- # or fall back to first in theme directory
- theme=$(ls -1 $dir/themes | head -1)
+ echo "Theme \"$theme\" does not exist."
+ exit 1
fi
# Source theme
@@ -372,11 +436,15 @@ do
then
. $modules_dir/$module
_$module
- elif [[ -f $dir/modules_c/$module ]]
+# elif [[ -f $modules_c_dir/$module ]] # running C modules directly
+# then
+# get_clicks $module
+# args=$(eval echo \$${module}_args)
+# $modules_c_dir/$module $fifo $(eval echo $args) &
+ elif [[ -f $modules_dir_usr/$module ]]
then
- get_clicks $module
- args=$(eval echo \$${module}_args)
- $dir/modules_c/$module $fifo $(eval echo $args) &
+ . $modules_dir_usr/$module
+ _$module
else
log "Module $module not found."
fi
diff --git a/makefile b/makefile
@@ -1,3 +1,62 @@
-all:
- @gcc -Wall src/cpu.c -o src/cpu
- @gcc -Wall src/alsa.c -o src/alsa -lasound
+CC = gcc
+CFLAGS += -Wall
+
+PREFIX ?= /usr
+MODPREFIX = $(PREFIX)/share/$(NAME)
+WAKEPREFIX = /lib/systemd/system-sleep/
+
+NAME = lemontools
+MODULES = $(SRC)/cpu $(SRC)/alsa
+SRC = modules_c
+
+
+#
+# modules
+#
+
+all: $(MODULES)
+
+$(SRC)/cpu:
+ $(CC) $(CFLAGS) $(SRC)/cpu.c -o $(SRC)/cpu
+
+$(SRC)/alsa:
+ $(CC) $(CFLAGS) -lasound $(SRC)/alsa.c -o $(SRC)/alsa
+
+clean:
+ @echo Removing compiled modules in modules_c
+ @find $(SRC) -type f ! -name '*.c' -delete
+
+
+#
+# Installation
+#
+
+install:
+ @if [[ ! -e $(SRC)/cpu ]]; then \
+ echo 'run make first'; \
+ exit 1; \
+ fi
+ @echo Installing $(NAME) to $(PREFIX)/bin
+ @install -m 755 $(NAME) $(PREFIX)/bin
+ @echo Installing modules and example themes to $(MODPREFIX)
+ @install -D -m 644 modules/* -t $(MODPREFIX)/modules/
+ @find $(SRC) -type f ! -name '*.c' -exec install -D -m 755 {} -t $(MODPREFIX)/modules_c/ \;
+ @install -D -m 644 themes/* -t $(MODPREFIX)/themes/
+ @if [[ -d $(WAKEPREFIX) ]]; then \
+ echo Installing sleep-update as update-lemontools in $(WAKEPREFIX); \
+ cp sleep-update $(WAKEPREFIX)/update-lemontools; \
+ chmod 755 $(WAKEPREFIX)/update-lemontools; \
+ fi
+
+uninstall:
+ @echo Removing $(PREFIX)/bin/$(NAME)
+ @rm $(PREFIX)/bin/$(NAME)
+ @echo Removing modules and example themes from $(MODPREFIX)
+ @rm -r $(MODPREFIX)
+ @if [[ -e $(WAKEPREFIX)/update-lemontools ]]; then \
+ echo Removing update-lemontools from $(WAKEPREFIX); \
+ rm $(WAKEPREFIX)/update-lemontools; \
+ fi
+
+
+.PHONY: all clean install uninstall
diff --git a/modules/alsa b/modules/alsa
@@ -21,15 +21,14 @@ update_alsa_mute() {
update_alsa() {
- local output
local volume
local icon
if [[ $# > 0 ]]
then
- volume=$($dir/modules_c/alsa -m $alsa_mixer -c $1)
+ volume=$($alsa_ex -m $alsa_mixer -c $1)
else
- volume=$($dir/modules_c/alsa -m $alsa_mixer)
+ volume=$($alsa_ex -m $alsa_mixer)
fi
if $muted
@@ -42,10 +41,7 @@ update_alsa() {
icon=%{O5}
fi
- output=$(eval echo $alsa_format)
- output=${alsa_pre}${output}${alsa_post}
-
- send "alsa='$output'"
+ send "alsa='${alsa_pre}$(eval echo $alsa_format)${alsa_post}'"
}
@@ -62,6 +58,20 @@ _alsa() {
muted=true
fi
+ # select executable
+ if [[ -f $modules_c_dir/alsa ]]
+ then
+ alsa_ex=$modules_c_dir/alsa
+ elif [[ -f $modules_c_dir_usr/alsa ]]
+ then
+ alsa_ex=$modules_c_dir_usr/alsa
+ else
+ # unset update function if not found. It will be ignored
+ unset -f update_alsa
+ log "C cpu executable not found for alsa module."
+ return 1
+ fi
+
update_alsa &
}
diff --git a/modules/cpu b/modules/cpu
@@ -18,6 +18,19 @@ _cpu() {
local cpu_val
local prev_cpu_val
local cpu_args
+ local cpu_ex
+
+ # select executable
+ if [[ -f $modules_c_dir/cpu ]]
+ then
+ cpu_ex=$modules_c_dir/cpu
+ elif [[ -f $modules_c_dir_usr/cpu ]]
+ then
+ cpu_ex=$modules_c_dir_usr/cpu
+ else
+ log "C cpu executable not found for cpu module."
+ return 1
+ fi
[[ -z "$cpu_format" ]] &&
cpu_format='$cpu_val'
@@ -31,7 +44,7 @@ _cpu() {
[[ -n "$cpu_refresh" ]] &&
cpu_args="$cpu_args -t $cpu_refresh"
- $dir/modules_c/cpu $cpu_args | while read cpu_val
+ $cpu_ex $cpu_args | while read cpu_val
do
[[ $cpu_val == $prev_cpu_val ]] && continue
prev_cpu_val=$cpu_val
diff --git a/modules/i3 b/modules/i3
@@ -2,9 +2,9 @@
# i3 module
#----------------------------------------------------------------------------------
+# WORK IN PROGRESS
+
# Display i3wm workspaces
-#
-# I no longer use i3 so if this is ever used it will need to be improved
_i3() {
diff --git a/modules/wireguard b/modules/wireguard
@@ -2,6 +2,8 @@
# wireguard interface module
#----------------------------------------------------------------------------------
+# Can be made as generic interface check
+
# This shows presence of a wireguard interface
# It polls every 10 seconds for the interface in /sys/class/net
diff --git a/modules_c/alsa b/modules_c/alsa
Binary files differ.
diff --git a/modules_c/cpu b/modules_c/cpu
Binary files differ.
diff --git a/sleep-update b/sleep-update
@@ -6,9 +6,12 @@
# Depends on systemd.
post(){
- lemontools -u battery
- lemontools -u clock
- lemontools -u date
+ if pgrep lemontools > /dev/null
+ then
+ lemontools -u battery
+ lemontools -u clock
+ lemontools -u date
+ fi
}
diff --git a/udev-battery b/udev-battery
@@ -1,6 +1,4 @@
-# This udev rule will update the battery module when the laptop charger is plugged in or removed
-#KERNEL=="AC0", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/bash -c 'if fifos=$(ls /home/*/git/lemontools/run/fifo-*); then for i in ${fifos[@]}; do echo update_battery > $i; done; fi'"
-#KERNEL=="AC0", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/bash -c 'if fifos=$(ls /home/*/git/lemontools/run/fifo-*); then for i in ${fifos[@]}; do echo update_battery > $i; done; fi'"
+# This udev rule will update the battery module when a laptop charger is plugged in or removed
KERNEL=="AC0", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/bash -c 'lemontools -u battery'"
KERNEL=="AC0", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/bash -c 'lemontools -u battery'"