From af3a27aeeed00d4781558a350a467240848085db Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 13 Aug 2018 22:51:16 +0200 Subject: bin/backlight: Adding script to set backlight on x2{2,3}0 using sysfs. --- bin/backlight | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 bin/backlight (limited to 'bin') diff --git a/bin/backlight b/bin/backlight new file mode 100755 index 0000000..ac8a466 --- /dev/null +++ b/bin/backlight @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# set backlight through sysfs + +set -euo pipefail + +# brightness steps in percentage +brightness_step_size=5 +brightness_device=/sys/class/backlight/intel_backlight/brightness +brightness_max_device=/sys/class/backlight/intel_backlight/max_brightness +calculated_brightness=0 +amount=0 + +brightness_steps=$(echo "100/${brightness_step_size}" |bc -l) +maximum_brightness_raw=$(cat $brightness_max_device) +current_brightness_raw=$(cat $brightness_device) +brightness_one_percent_raw=$(echo "${maximum_brightness_raw}/100" |bc -l) +current_brightness_percentage=$(echo "${current_brightness_raw}/(${maximum_brightness_raw}/100)" |bc -l) +current_brightness_remainder=$(echo "${current_brightness_percentage}%${brightness_step_size}"|bc -l) +current_step=$(echo ${current_brightness_percentage}/${brightness_step_size}|bc -l) + +check_if_number() { + if [[ $1 =~ ^[!\-0-9]+$ ]]; then + echo "Not an Integer: $1" + exit 1 + fi +} + +calculate_increment() { + check_if_number $1 + if [ $1 -eq 0 ]; then + echo "There's nothing to do." + exit 1 + fi + if [ $1 -gt 0 ]; then + if [ $(printf '%.0f' $current_brightness_percentage) -eq 100 ]; then + echo "Already at 100%" + exit 0 + elif [ $(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) -gt 100 ]; then + calculated_brightness=100 + else + calculated_brightness=$(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) + fi + else + if [ $(printf '%.0f' $current_brightness_percentage) -eq 0 ]; then + echo "Already at 0%" + exit 0 + elif [ $(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) -lt 0 ]; then + calculated_brightness=0 + else + calculated_brightness=$(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) + fi + fi +} + +calculate_percentage() { + check_if_number $1 + if [ $1 -lt 0 ] || [ $1 -gt 100 ]; then + echo "Invalid range: $1" + exit 1 + fi + calculated_brightness=$1 +} + +percentage_to_raw() { + printf '%.0f' $(echo "$1*${brightness_one_percent_raw}"|bc -l) +} + +set_brightness() { + echo "$(percentage_to_raw $calculated_brightness)" > $brightness_device +} + +print_help() { + echo -e "Usage:\n $0 -d \n or $0 -i " + exit 1 +} + +if [ ${#@} -gt 0 ]; then + while getopts 'hi:s:' flag; do + case "${flag}" in + h) + print_help + ;; + i) + calculate_increment $OPTARG + ;; + s) + calculate_percentage $OPTARG + ;; + *) + echo "Error! Try '${0} -h'." + exit 1 + ;; + esac + done +else + print_help +fi + +set_brightness -- cgit v1.2.3-70-g09d2 From 0fcb833bb8829c8d79d5c3bb769a5f8abae66f02 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 22 Aug 2018 22:28:55 +0200 Subject: bin/startsway: Add sway startup script. --- bin/startsway | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 bin/startsway (limited to 'bin') diff --git a/bin/startsway b/bin/startsway new file mode 100755 index 0000000..ae0b104 --- /dev/null +++ b/bin/startsway @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +export XKB_DEFAULT_LAYOUT=us,de +export XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle +/usr/bin/sway -dV -- cgit v1.2.3-70-g09d2 From 544e634c8ce9b041e1191253563bf54da2a4e88a Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 13 Sep 2018 18:55:02 +0200 Subject: bin/pkgs: Removing headers of list outputs. --- bin/pkgs | 2 -- 1 file changed, 2 deletions(-) (limited to 'bin') diff --git a/bin/pkgs b/bin/pkgs index ce208c4..59f2d9c 100755 --- a/bin/pkgs +++ b/bin/pkgs @@ -249,12 +249,10 @@ if [ $list_mode -eq 1 ] && \ elif [ $list_mode -eq 1 ] && \ [ $aur_mode -eq 1 ] && \ [ $community_mode -eq 0 ];then - echo "AUR packages:" cat "$aur_packagelist" elif [ $list_mode -eq 1 ] && \ [ $aur_mode -eq 0 ] && \ [ $community_mode -eq 1 ];then - echo "Community packages:" cat "$community_packagelist" elif [ $list_mode -eq 1 ] && \ [ $aur_mode -eq 1 ] && \ -- cgit v1.2.3-70-g09d2 From fda33adc1d546151ca32cb78c8c279fb7f3ce341 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 13 Sep 2018 19:09:33 +0200 Subject: bin/startsway: Log output to ~/.log/sway.log. --- bin/startsway | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/startsway b/bin/startsway index ae0b104..ee46560 100755 --- a/bin/startsway +++ b/bin/startsway @@ -2,4 +2,5 @@ export XKB_DEFAULT_LAYOUT=us,de export XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle -/usr/bin/sway -dV +mkdir -p "$HOME/.log" +/usr/bin/sway -dV > "$HOME/.log/sway.log" 2>&1 -- cgit v1.2.3-70-g09d2 From 56848bd7e34f484cdce7a69258cf22a57108d231 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 29 Sep 2018 11:07:28 +0200 Subject: bin/cs: Fixing script according to shellcheck. --- bin/cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'bin') diff --git a/bin/cs b/bin/cs index 363ba12..4eb7fe6 100755 --- a/bin/cs +++ b/bin/cs @@ -19,7 +19,7 @@ function open_cryptdevice() { echo "Crypt device has already been opened: /dev/mapper/$2" echo "Continuing..." else - /usr/bin/sudo /usr/bin/cryptsetup luksOpen "/dev/disk/by-uuid/$1" $2 + /usr/bin/sudo /usr/bin/cryptsetup luksOpen "/dev/disk/by-uuid/$1" "$2" fi else echo "Error: Device $2 (UUID=$1) is not available." @@ -28,7 +28,7 @@ function open_cryptdevice() { } function close_cryptdevice() { - /usr/bin/sudo /usr/bin/cryptsetup luksClose $1 + /usr/bin/sudo /usr/bin/cryptsetup luksClose "$1" } function mount_cryptdevice() { @@ -50,35 +50,35 @@ function unmount_cryptdevice() { if [ -x "$HOME/.config/cs/pre_umount/$1" ]; then "$HOME/.config/cs/pre_umount/$1" fi - /usr/bin/sudo /usr/bin/umount /mnt/$1 + /usr/bin/sudo /usr/bin/umount "/mnt/$1" } function validate_cryptdevice_name() { - local _result_valid_name=$1 + local _result_valid_name="$1" local name_found=0 - local input_name=${2:-} + local input_name="${2:-}" for name in "${!devices[@]}"; do - if [ $name = "${input_name}" ]; then + if [ "$name" = "${input_name}" ]; then name_found=1 - eval $_result_valid_name="'$name_found'" + eval "$_result_valid_name"="$name_found" fi done } -validate_cryptdevice_name valid_name ${device_name} +validate_cryptdevice_name valid_name "${device_name}" if [ $valid_name -eq 0 ]; then echo "No such device: '$device_name'!" exit 1 fi -case $1 in +case "$command_name" in "open") - open_cryptdevice ${devices[${2}]} $2 - mount_cryptdevice $2 + open_cryptdevice "${devices[${2}]}" "$2" + mount_cryptdevice "$2" ;; "close") - unmount_cryptdevice $2 - close_cryptdevice $2 + unmount_cryptdevice "$2" + close_cryptdevice "$2" ;; *) echo "cs only understands 'open' and 'close'." -- cgit v1.2.3-70-g09d2 From 63e6444533cb8960f918cba97fb65f0fdf70dd00 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Nov 2018 00:49:07 +0100 Subject: bin/xorg_lock: Properly quote variables. Rename variables for better readibility. --- bin/xorg_lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/xorg_lock b/bin/xorg_lock index 648099e..6ddeb0c 100755 --- a/bin/xorg_lock +++ b/bin/xorg_lock @@ -2,13 +2,13 @@ set -euo pipefail -lock=${XDG_RUNTIME_DIR}/xorg_autolock.lock -lockcmd="i3lock -n -e -c 000000 -f" +lock_file=${XDG_RUNTIME_DIR}/xorg_autolock.lock +lock_cmd="i3lock -n -e -c 000000 -f" if [ -x "/usr/bin/i3lock" ]; then - touch ${lock} - ${lockcmd} - rm -f ${lock} + touch "${lock_file}" + ${lock_cmd} + rm -f "${lock_file}" else echo "i3lock is not installed!" exit 1 -- cgit v1.2.3-70-g09d2 From 4f99bbc4e1fd137af0ae60afef1793794b4dfe58 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Nov 2018 00:50:50 +0100 Subject: bin/xorg_autolock: Properly quoting variables. Abstracting lock_cmd. --- bin/xorg_autolock | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/xorg_autolock b/bin/xorg_autolock index f30ae3e..181548e 100755 --- a/bin/xorg_autolock +++ b/bin/xorg_autolock @@ -4,15 +4,16 @@ set -euo pipefail lock=${XDG_RUNTIME_DIR}/xorg_autolock.lock lock_block=${XDG_RUNTIME_DIR}/xorg_autolock_block +lock_cmd="$HOME/bin/xorg_lock" lockafter=600000 -rm -f ${lock} ${lock_block} +rm -f "${lock}" "${lock_block}" -while [ 1 ]; do - if [ ! -f ${lock} -a ! -f ${lock_block} ];then +while true; do + if [ ! -f "${lock}" ] && [ ! -f "${lock_block}" ];then if [ -x "/usr/bin/xssstate" ]; then - if [ $(xssstate -i) -ge $lockafter ]; then - $HOME/bin/xorg_lock + if [ "$(xssstate -i)" -ge $lockafter ] && [ -x "$lock_cmd" ]; then + $lock_cmd fi else echo "xssstate is note installed!" -- cgit v1.2.3-70-g09d2 From 80a498c77c62d184731740b94ee5a6188e79726c Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Nov 2018 00:52:59 +0100 Subject: bin/setup_screens: Fixing and simplifying various things with the help of shellcheck. Using a separate get_display function to retrieve DISPLAY. --- bin/setup_screens | 66 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'bin') diff --git a/bin/setup_screens b/bin/setup_screens index 1a84bba..7cd0b17 100755 --- a/bin/setup_screens +++ b/bin/setup_screens @@ -2,23 +2,29 @@ # Script to setup screens on login and lid-switch-action # Uses autorandr to determine which screens are connected and which to setup. # -# Per default a configuration named "internal" will be used, if the computer is +# Per default a configuration named "default" will be used, if the computer is # a laptop and not docked. # A configuration named "docked-closed" will be used during login, when the lid # is closed and docked. -# A configuration named "docked-open" will be used during login, when the lid +# A configuration named "docked-all" will be used during login, when the lid # is open and docked. set -e -u lid_state="" -docking_state="" fingerprint="" action="" x_user="" +display="" current_user="" path="" +# get DISPLAY number +get_display() +{ + display=$(pgrep -a Xorg|cut -d':' -f2| cut -d' ' -f1) +} + # get current user running X get_x_user() { @@ -41,15 +47,17 @@ get_path() function get_lid_state() { if [ -r "/proc/acpi/button/lid/LID/state" ]; then - lid_state="$(cat /proc/acpi/button/lid/LID/state|awk '{print $2}')" + lid_state="$(awk '{print $2}' /proc/acpi/button/lid/LID/state)" fi } # Get current docking state ("true" or "false") -function get_docking_state() +function is_docked() { - if [ -x "/usr/bin/busctl" ]; then - docking_state="$(busctl introspect org.freedesktop.login1 /org/freedesktop/login1|grep "\.Docked"|awk '{print $4}')" + if command -v busctl > /dev/null; then + busctl introspect org.freedesktop.login1 /org/freedesktop/login1| grep -E '^.Docked'| awk '{print $4}' + else + echo false fi } @@ -63,8 +71,8 @@ function get_setup_fingerprint() function get_configuration_fingerprint() { local fingerprint="" - if [ -r $HOME/.config/autorandr/$1/setup ]; then - fingerprint="$(md5sum $HOME/.config/autorandr/$1/setup| cut -d ' ' -f 1)" + if [ -r "$HOME/.config/autorandr/$1/setup" ]; then + fingerprint="$(md5sum "$HOME/.config/autorandr/$1/setup"| cut -d ' ' -f 1)" fi echo "$fingerprint" } @@ -73,19 +81,19 @@ function set_configuration() { local state=0 # if the computer is docked - if [ "$docking_state" = "true" ]; then + if is_docked ; then # if there's a lid-switch action if [ -n "$action" ]; then case "$action" in "open") - if [ $(get_configuration_fingerprint "docked-open") == "$fingerprint" ]; then - echo "Loading docked-open." + if [ "$(get_configuration_fingerprint 'docked-all')" == "$fingerprint" ]; then + echo "Loading docked-all." state=1 - autorandr -l docked-open + autorandr -l docked-all fi ;; "close") - if [ $(get_configuration_fingerprint "docked-closed") == "$fingerprint" ]; then + if [ "$(get_configuration_fingerprint 'docked-closed')" == "$fingerprint" ]; then echo "Loading docked-closed." state=1 autorandr -l docked-closed @@ -96,10 +104,10 @@ function set_configuration() # check the lid state case "$lid_state" in "open") - if [[ $(get_configuration_fingerprint "docked-open") == "$fingerprint" ]]; then - echo "Loading docked-open." + if [[ $(get_configuration_fingerprint "docked-all") == "$fingerprint" ]]; then + echo "Loading docked-all." state=1 - autorandr -l docked-open + autorandr -l docked-all fi ;; "closed") @@ -125,11 +133,11 @@ function set_configuration() fi fi fi - # if the screen still has not been setup, try using internal + # if the screen still has not been setup, try using default if [ $state -ne 1 ]; then - if [[ $(get_configuration_fingerprint "internal") == "$fingerprint" ]]; then - echo "Loading internal." - autorandr -l internal + if [[ $(get_configuration_fingerprint "default") == "$fingerprint" ]]; then + echo "Loading default." + autorandr -l default fi fi } @@ -147,27 +155,25 @@ fi logger "Calling 'setup_screens'" get_x_user +get_display get_current_user get_path # Export Xorg DISPLAY and XAUTHORITY -export DISPLAY=$(ls /tmp/.X*|grep "lock"|cut -d '.' -f2| cut -d '-' -f1|sed -e 's/X/:/') -export XAUTHORITY="$(eval echo ~$x_user/.Xauthority)" +export DISPLAY=":$display" +export XAUTHORITY="/home/$x_user/.Xauthority" # if the script caller is the current X user or root (and lightdm is the current X user) -if [ "$current_user" = "$x_user" ] || [ $current_user = "root" -a $x_user = "lightdm" ]; then +if [ "$current_user" == "$x_user" ]; then get_lid_state - get_docking_state get_setup_fingerprint set_configuration -else - if [ $current_user = "root" ]; then +elif [ "$current_user" == "root" ]; then logger "Running $path as user $x_user now." - runuser -l $x_user -c $path - else + runuser -l "$x_user" -c "$path" +else echo "$current_user is not currently running X and is not allowed to let the current X user run this script." exit 1 - fi fi exit 0 -- cgit v1.2.3-70-g09d2