Kernel formatting

This commit is contained in:
John Mertz 2020-11-23 04:35:26 -05:00
parent 806f3996f2
commit f10d944e17
28 changed files with 1451 additions and 1234 deletions

118
README.md
View File

@ -1,39 +1,51 @@
# Simple Scripts # Simple Scripts
## Audio ## Audio
**audio/mute.sh** **audio/mute.sh**
Just a simple script to toggle Alsa mute. Just a simple script to toggle Alsa mute.
---
**audio/noise-cancel.sh** **audio/noise-cancel.sh**
Add a noise-cancelled version of existing interfaces to Pulseaudio. Add a noise-cancelled version of existing interfaces to Pulseaudio.
## i3 ## i3
I haven't used i3 in earnest for quite some time since moving to Sway, so it is very likely that some of these scripts are broken based on other config changes. I haven't used i3 in earnest for quite some time since moving to Sway, so it is
very likely that some of these scripts are broken based on other config changes.
**i3/i3move.sh** **i3/i3move.sh**
When any of the Xrandr scripts below is run, it will print it's name to a config file. This script will read that config file and then knows how the outputs are arranged. Once this is known, it allows hotkeys to know which output to move a workspace to. When any of the Xrandr scripts below is run, it will print it's name to a config
file. This script will read that config file and then knows how the outputs are
arranged. Once this is known, it allows hotkeys to know which output to move a
workspace to.
**i3/detached.sh** **i3/detached.sh**
Xrandr config. Just the laptop display. Xrandr config. Just the laptop display.
**i3/work.sh** **i3/detached.sh**
Xrandr config. Vertical on the left, horizontal aligned to top of the vertical, and laptop directly below that. Left-to-right order is Vertical-Horizontal-Laptop. Xrandr config. Just the laptop display.
**i3/home.sh** **i3/home.sh**
Xrandr config. Not a layout I currently use. Home is now the "stacked" view from sway/displays. Xrandr config. Not a layout I currently use. Home is now the "stacked" view from
sway/displays.
**i3/work.sh**
Xrandr config. Vertical on the left, horizontal aligned to top of the vertical,
and laptop directly below that. Left-to-right order is
Vertical-Horizontal-Laptop.
## Rofi ## Rofi
[Rofi](https://github.com/davatorium/rofi) is a neat graphical launcher and menu system. I use it for a bunch of stuff to supplement i3 and Sway to fill out same desktop niceties. See configs in 'dotfiles' repository. [Rofi](https://github.com/davatorium/rofi) is a neat graphical launcher and menu
system. I use it for a bunch of stuff to supplement i3 and Sway to fill out same
desktop niceties. See configs in 'dotfiles' repository.
**rofi/drun.sh** **rofi/drun.sh**
@ -53,7 +65,8 @@ Forward pasted link to ./send-to-kodi.sh.
**rofi/rofi-ssh-menu.sh** **rofi/rofi-ssh-menu.sh**
Open a terminal to any SSH shortcut machine. (TODO: Integrate with 'sshs' to get machine list from there instead of a static list). Open a terminal to any SSH shortcut machine. (TODO: Integrate with 'sshs' to get
machine list from there instead of a static list).
**rofi/sway-alt-tab.sh** **rofi/sway-alt-tab.sh**
@ -61,27 +74,40 @@ Show all currently running applications in Sway to locate window.
## Sway ## Sway
[Sway](https://github.com/swaywm/sway) is an i3-compatible Wayland compositor and tiling window manager. See configs in 'dotfiles' repository. Here are some scripts exclusively for automating or enhancing Sway. [Sway](https://github.com/swaywm/sway) is an i3-compatible Wayland compositor
and tiling window manager. See configs in 'dotfiles' repository. Here are some
scripts exclusively for automating or enhancing Sway.
**sway/displays.pl** **sway/displays.pl**
Script to automatically configure wayland outputs using swaymsg. Also forks waybars for each display. Allows custom configurations. No argument will run the last used configuration (~/config/last_display). '-w' will run only waybar without changing displays. Script to automatically configure wayland outputs using swaymsg. Also forks
waybars for each display. Allows custom configurations. No argument will run the
last used configuration (~/config/last_display). '-w' will run only waybar
without changing displays.
**sway/gammastep.pl** **sway/gammastep.pl**
Setup Gammastep based on current location. I don't have geolocation in my laptop, so this requires a URL that returns JSON, including a "lat" and "lon". My URL (restricted to my IPs) returns these as recorded by PhoneTrack on my phone similar to: Setup Gammastep based on current location. I don't have geolocation in my
laptop, so this requires a URL that returns JSON, including a "lat" and "lon".
My URL (restricted to my IPs) returns these as recorded by PhoneTrack on my
phone similar to:
``` ```
{"lat":"180.12345678","lon":"-180.12345678","timestamp":"1599831660"} {"lat":"180.12345678","lon":"-180.12345678","timestamp":"1599831660"}
``` ```
It forks to keep running if terminal is killed to remove the need for nohup. If location fails to be fetched it will try again every 5 seconds. It forks to keep running if terminal is killed. If location fails to be fetched
it will try again every 5 seconds.
**sway/popup-term.pl** **sway/popup-term.pl**
A DIY version of the Tilde terminal. If terminal is not running, it opens on the current display. If it is running but not on current display, it moves to current display. If it is already on current display, it is moved to a hidden display ('grave'). A DIY version of the Tilde terminal. If terminal is not running, it opens on the
current display. If it is running but not on current dislpay, it moves to
current display. If it is already on current display, it is moved to a hidden
display ('grave').
Note the relevant settings in dotfiles repository (sway/config) related to the 'grave' workspace, as well as UXTerm which is configured to open floating in the bottom corner. Note the relevant settings in dotfiles repository (sway/config) related to the
'grave' workspace, as well as UXTerm.
``` ```
for_window [class="UXTerm"] floating enable, resize set height 600px, resize set width 800px, move position 1120px 460px for_window [class="UXTerm"] floating enable, resize set height 600px, resize set width 800px, move position 1120px 460px
@ -91,58 +117,69 @@ bindsym $mod+Grave exec /home/jpm/scripts/sway/popup-term.pl
bindsym $mod+Shift+Grave workspace grave bindsym $mod+Shift+Grave workspace grave
``` ```
Also note that 'grave' has no label in waybar (waybar/config.template) to allow it to be *hidden*. Also note that 'grave' has no label in waybar (waybar/config.template) to allow
it to be *hidden*.
``` ```
"sway/workspaces": { "sway/workspaces": {
"format": "{icon}", "format": "{icon}",
"format-icons": { "format-icons": {
"0": "0 \uf073", // Example of workspace with a label "0": "0 \uf073", // Example of workspace with a label
"grave": "", "grave": "",
... ...
``` ```
**sway/swayidle.sh** **sway/swayidle.sh**
Work in progress. These scripts don't currently work the way I like. Work in progress. These scripts don't currently work the way I like.
Sway has an Idle detection daemon that can flexibly take different actions after certain periods of inactivity as well as prior to sleep and after wake. Sway has an Idle detection daemon that can flexibly take different actions after
certain periods of inactivity as well as prior to sleep and after wake.
This script is meant to unify all of the actions into one script by accepting an option. This script is meant to unify all of the actions into one script by accepting an
option.
**sway/swayidlecountdown.sh** **sway/swayidlecountdown.sh**
Prior to locking, a countdown should be provided. Currently testing how to manage a countdown with Dunst, which doesn't actually support dynamic notifications. Prior to locking a countdown should be provided. Currently testing how to manage
a countdown with Dunst, which doesn't actually support dynamic notifications.
**sway/toggle_outputs**
Swap between detached and docked modes using `sway/displays.pl`. Bound to function key for external monitor button.
## Thinkpad ## Thinkpad
**thinkpad/blc.pl** **thinkpad/blc.pl**
Overly complicated backlight brightness control script. Provides flexible control of backlight so that changes can be easily scripted or called from keyboard shortcuts. --help provides some usage docs. Overly complicated backlight brightness control script. Provides flexible
control of backlight so that changes can be easily scripted or called from
keyboard shortcuts. --help provides some usage docs.
**thinkpad/kbd_backlight.pl** **thinkpad/kbd_backlight.pl**
Simple script to cycle keyboard backlight. Gets max brightness, current brightness and then changes then increments the current brightness. Uses mod of max+1 so that it will cycle back around to 0 (disabled) if it is already at max. Simple script to cycle keyboard backlight. Gets max brightness, current
brightness and then changes then increments the current brightness. Uses mod of
max+1 so that it will cycle back around to 0 (disabled) if it is already at max.
**thinkpad/user-thinkpad-control@.service** **thinkpad/user-thinkpad-control@.service**
SystemD unit file used to give ownership of necessary sys files to whichever user it is enabled for `systemctl enable user-thinkpad-control@jpm`. Without this, the user won't be able to write these files and thus cannot set brightness values. SystemD unit file used to give ownership of necessary sys files to whichever
user it is enabled for `systemctl enable user-thinkpad-control@jpm`. Without
this, the user won't be able to write these files and thus cannot set brightness
values.
## Waybar ## Waybar
[Waybar](https://github.com/Alexays/Waybar) is a very flexible and customizable taskbar for Sway (and other Wlroots-based wayland compositors). Waybar applets have hover and click functionality and have several scripts related to those. See the .config repository for the actual Waybar and Sway configs. [Waybar](https://github.com/Alexays/Waybar) is a very flexible and customizable
taskbar for Sway (and other Wlroots-based wayland compositors). Waybar applets
have hover and click functionality and have several scripts related to those.
See the .config repository for the actual Waybar and Sway configs.
**waybar/waybar-cpu.sh** **waybar/waybar-cpu.sh**
Launch htop in floating window (bottom-right). If already running, kill it. Launch htop in floating window (bottom-right). If already running, kill it.
**waybar/waybar-disk.sh** **waybar/waybar-disk.sh**
Notification with disk usage summaries. Renders properly with Dunst, but not Mako. Notification with disk usage summaries. Renders properly with Dunst, but not
Mako.
**waybar/waybar-mem.sh** **waybar/waybar-mem.sh**
@ -156,8 +193,13 @@ Launch nmtui in floating window (bottom-right). If already running, kill it.
**send-to-kodi.sh** **send-to-kodi.sh**
[This script](https://github.com/allejok96/send-to-kodi) sends a URL or local file to a [Kodi](https://github.com/xbmc) media player. Only modified to have my local media server IP. [This script](https://github.com/allejok96/send-to-kodi) sends a URL or local
file to a [Kodi](https://github.com/xbmc) media player. Only modified to have my
local media server IP.
**apply-gruvbox.sh** **apply-gruvbox.sh**
A single theme version of the one provided [here](https://raw.githubusercontent.com/Mayccoll/Gogh). Applies the theme to a variety of terminals. Not really necessary after cloning the 'dotfiles' repository. A single theme version of the one provided
[here](https://raw.githubusercontent.com/Mayccoll/Gogh). Applies the theme to a
variety of terminals. Not really necessary after cloning the 'dotfiles'
repository.

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
# Microphone Realtime background noise reduction script # Microphone Realtime background noise reduction script
# author Luigi Maselli - https://grigio.org licence: AS-IS # author Luigi Maselli - https://grigio.org licence: AS-IS
# credits: http://askubuntu.com/questions/18958/realtime-noise-removal-with-pulseaudio # credits:
# http://askubuntu.com/questions/18958/realtime-noise-removal-with-pulseaudio
# run as: sudo && pulseaudio -k # run as: sudo && pulseaudio -k
sudo cp /etc/pulse/default.pa /etc/pulse/default.pa.bak sudo cp /etc/pulse/default.pa /etc/pulse/default.pa.bak
@ -8,4 +9,4 @@ sudo cat <<EOT >> /etc/pulse/default.pa
load-module module-echo-cancel source_name=noechosource sink_name=noechosink load-module module-echo-cancel source_name=noechosource sink_name=noechosink
set-default-source noechosource set-default-source noechosource
set-default-sink noechosink set-default-sink noechosink
EOT EOT

View File

@ -1,3 +1,10 @@
#!/bin/sh #!/bin/sh
xrandr --output DP-2-1 --off --output DP-2-2 --off --output DP-2-3 --off --output eDP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output HDMI-2 --off --output HDMI-1 --off --output DP-2 --off --output DP-1 --off xrandr \
--output DP-2-1 --off \
--output DP-2-2 --off \
--output DP-2-3 --off \
--output eDP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal \
--output HDMI-2 --off \
--output HDMI-1 --off --output DP-2 --off --output DP-1 --off
echo "detached" > ~/.config/screenlayout/i3.current echo "detached" > ~/.config/screenlayout/i3.current

View File

@ -1,3 +1,12 @@
#!/bin/sh #!/bin/sh
xrandr --output DP-2-1 --mode 1366x768 --pos 0x0 --rotate left --output DP-2-2 --mode 1920x1200 --pos 768x0 --rotate normal --output DP-2-3 --off --output eDP-1 --primary --mode 1920x1080 --pos 768x1200 --rotate normal --output HDMI-2 --off --output HDMI-1 --off --output DP-2 --off --output DP-1 --off xrandr \
--output DP-2-1 --mode 1366x768 --pos 0x0 --rotate left \
--output DP-2-2 --mode 1920x1200 --pos 768x0 --rotate normal \
--output DP-2-3 --off \
--output eDP-1 --primary --mode 1920x1080 --pos 768x1200 --rotate normal \
--output HDMI-2 --off \
--output HDMI-1 --off \
--output DP-2 --off \
--output DP-1 --off
echo "home" > ~/.config/screenlayout/i3.current echo "home" > ~/.config/screenlayout/i3.current

View File

@ -4,25 +4,25 @@ LAYOUT=`cat ~/.config/screenlayout/i3.current`
MIDDLE="eDP-1" MIDDLE="eDP-1"
if [[ $LAYOUT == 'home' ]]; then if [[ $LAYOUT == 'home' ]]; then
RIGHT="DP-2-2" RIGHT="DP-2-2"
LEFT="DP-2-1" LEFT="DP-2-1"
elif [[ $LAYOUT == 'work' ]]; then elif [[ $LAYOUT == 'work' ]]; then
RIGHT="DP-2-2" RIGHT="DP-2-2"
LEFT="DP-2-1" LEFT="DP-2-1"
elif [[ $LAYOUT == '3' ]]; then elif [[ $LAYOUT == '3' ]]; then
MIDDLE="DP-2-2" MIDDLE="DP-2-2"
LEFT="DP-2-1" LEFT="DP-2-1"
RIGHT="eDP-1" RIGHT="eDP-1"
else else
echo "No external displays connected" echo "No external displays connected"
fi fi
if [[ $1 == 'right' ]]; then if [[ $1 == 'right' ]]; then
i3 move workspace to output $RIGHT i3 move workspace to output $RIGHT
elif [[ $1 == 'middle' ]]; then elif [[ $1 == 'middle' ]]; then
i3 move workspace to output $MIDDLE i3 move workspace to output $MIDDLE
elif [[ $1 == 'left' ]]; then elif [[ $1 == 'left' ]]; then
i3 move workspace to output $LEFT i3 move workspace to output $LEFT
else else
echo "Invalid direction. Requires either 'up', 'left', or 'middle'" echo "Invalid direction. Requires either 'up', 'left', or 'middle'"
fi fi

View File

@ -1,3 +1,12 @@
#!/bin/sh #!/bin/sh
xrandr --output DP-2-1 --mode 1920x1080 --pos 0x0 --rotate left --output DP-2-2 --mode 1920x1080 --pos 1080x0 --rotate normal --output DP-2-3 --off --output eDP-1 --primary --mode 1920x1080 --pos 1080x1080 --rotate normal --output HDMI-2 --off --output HDMI-1 --off --output DP-2 --off --output DP-1 --off xrandr \
--output DP-2-1 --mode 1920x1080 --pos 0x0 --rotate left \
--output DP-2-2 --mode 1920x1080 --pos 1080x0 --rotate normal \
--output DP-2-3 --off \
--output eDP-1 --primary --mode 1920x1080 --pos 1080x1080 --rotate normal \
--output HDMI-2 --off \
--output HDMI-1 --off \
--output DP-2 --off \
--output DP-1 --off
echo "work" > ~/.config/screenlayout/i3.current echo "work" > ~/.config/screenlayout/i3.current

View File

@ -4,7 +4,7 @@ ROFI=$(pgrep -c rofi | cut -b 1)
echo $ROFI echo $ROFI
if [[ "$ROFI" -eq "0" ]]; then if [[ "$ROFI" -eq "0" ]]; then
rofi -config /home/jpm/.config/rofi/config -show drun rofi -config /home/jpm/.config/rofi/config -show drun
else else
killall rofi 2&>1 /dev/null killall rofi 2&>1 /dev/null
fi fi

View File

@ -5,25 +5,25 @@
res=$(echo "Connection|John.Me.tz|MailCleaner|Disconnect|Restart" | rofi -sep "|" -dmenu -i -p 'P ' "" -columns 9 -width 45 -l 1 -config /home/jpm/.config/rofi/config -hide-scrollbar -eh 1 -location 0 -auto-select -no-fullscreen) res=$(echo "Connection|John.Me.tz|MailCleaner|Disconnect|Restart" | rofi -sep "|" -dmenu -i -p 'P ' "" -columns 9 -width 45 -l 1 -config /home/jpm/.config/rofi/config -hide-scrollbar -eh 1 -location 0 -auto-select -no-fullscreen)
if [ $res = "Connection" ]; then if [ $res = "Connection" ]; then
/usr/bin/uxterm -e 'sudo /usr/bin/nmtui' /usr/bin/uxterm -e 'sudo /usr/bin/nmtui'
elif [ $res = "John.Me.tz" ]; then elif [ $res = "John.Me.tz" ]; then
sudo /usr/bin/systemctl stop openvpn-client@mailcleaner sudo /usr/bin/systemctl stop openvpn-client@mailcleaner
sudo /usr/bin/systemctl restart wg-quick@wg0
elif [ $res = "MailCleaner" ]; then
sudo /usr/bin/systemctl stop wg-quick@wg0
sudo /usr/bin/systemctl restart openvpn-client@mailcleaner
elif [ $res = "Disconnect" ]; then
sudo /usr/bin/systemctl stop openvpn-client@mailcleaner
sudo /usr/bin/systemctl stop wg-quick@wg0
elif [ $res = "Restart" ]; then
if [ "`ip addr show wg0 2> /dev/null`" != "" ]; then
sudo /usr/bin/systemctl restart wg-quick@wg0 sudo /usr/bin/systemctl restart wg-quick@wg0
fi elif [ $res = "MailCleaner" ]; then
if [ "`ip addr show tun0 2> /dev/null`" != "" ]; then sudo /usr/bin/systemctl stop wg-quick@wg0
sudo /usr/bin/systemctl restart openvpn-client@mailcleaner sudo /usr/bin/systemctl restart openvpn-client@mailcleaner
fi elif [ $res = "Disconnect" ]; then
sudo /usr/bin/systemctl stop openvpn-client@mailcleaner
sudo /usr/bin/systemctl stop wg-quick@wg0
elif [ $res = "Restart" ]; then
if [ "`ip addr show wg0 2> /dev/null`" != "" ]; then
sudo /usr/bin/systemctl restart wg-quick@wg0
fi
if [ "`ip addr show tun0 2> /dev/null`" != "" ]; then
sudo /usr/bin/systemctl restart openvpn-client@mailcleaner
fi
else else
exit exit
fi fi
# Waybar sometimes doesn't update with the VPN IP, for whatever reason. Restart it. # Waybar sometimes doesn't update with the VPN IP, for whatever reason. Restart it.

View File

@ -4,39 +4,39 @@
# Determine if Sway or i3 # Determine if Sway or i3
if [ -z ${SWAYSOCK+x} ]; then if [ -z ${SWAYSOCK+x} ]; then
WM="i3" WM="i3"
else else
WM="sway" WM="sway"
fi fi
if [[ $WM == 'i3' ]]; then if [[ $WM == 'i3' ]]; then
res=$(printf "🔒 Lock|↩ Logout|↻ Reload i3|↹ Restart i3|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -columns 1 -rows 7 -width 32 -l 1 -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100 -auto-select -no-fullscreen) res=$(printf "🔒 Lock|↩ Logout|↻ Reload i3|↹ Restart i3|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -columns 1 -rows 7 -width 32 -l 1 -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100 -auto-select -no-fullscreen)
else else
res=$(echo "🔒 Lock|↩ Logout|↻ Reload Sway|↻ Reload Waybar|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -no-lazy-grab -auto-select -no-fullscreen) res=$(echo "🔒 Lock|↩ Logout|↻ Reload Sway|↻ Reload Waybar|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -no-lazy-grab -auto-select -no-fullscreen)
fi fi
if [ "$res" == "🔒 Lock" ]; then if [ "$res" == "🔒 Lock" ]; then
${WM}lock -c 323232 ${WM}lock -c 323232
elif [ "$res" == "↩ Logout" ]; then elif [ "$res" == "↩ Logout" ]; then
# Prevent auto-login # Prevent auto-login
rm /home/jpm/.config/last_login_gui rm /home/jpm/.config/last_login_gui
${WM} exit ${WM} exit
elif [ "$res" == "↻ Reload i3" ]; then elif [ "$res" == "↻ Reload i3" ]; then
i3 reload i3 reload
elif [ "$res" == "↹ Restart i3" ]; then elif [ "$res" == "↹ Restart i3" ]; then
i3 restart i3 restart
elif [ "$res" == "↻ Reload Sway" ]; then elif [ "$res" == "↻ Reload Sway" ]; then
sway reload sway reload
elif [ "$res" == "↻ Reload Waybar" ]; then elif [ "$res" == "↻ Reload Waybar" ]; then
# Need to integrate with sway/displays.pl for alternative outputs # Need to integrate with sway/displays.pl for alternative outputs
/home/jpm/scripts/sway/displays.pl -w /home/jpm/scripts/sway/displays.pl -w
elif [ "$res" == "🡙 Reboot" ]; then elif [ "$res" == "🡙 Reboot" ]; then
rm $SSH_AUTH_SOCK rm $SSH_AUTH_SOCK
sudo systemctl reboot -i sudo systemctl reboot -i
elif [ "$res" == "⏻ Shutdown" ]; then elif [ "$res" == "⏻ Shutdown" ]; then
rm $SSH_AUTH_SOCK rm $SSH_AUTH_SOCK
sudo systemctl poweroff -i sudo systemctl poweroff -i
elif [ "$res" == "↯ Hibernate" ]; then elif [ "$res" == "↯ Hibernate" ]; then
sudo systemctl hibernate -i sudo systemctl hibernate -i
fi fi
exit 0 exit 0

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
INPUT="$(rofi -dmenu -i -p 'Kodi:' "" -columns 1 -rows 7 -width 32 -l 1 -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100)" INPUT="$(rofi -dmenu -i -p 'Kodi:' "" -columns 1 -rows 7 -width 32 -l 1 \
-hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100)"
/home/jpm/scripts/send-to-kodi.sh $INPUT 2>&1 /dev/null /home/jpm/scripts/send-to-kodi.sh $INPUT 2>&1 /dev/null

View File

@ -1,28 +1,33 @@
#!/bin/bash #!/bin/bash
res=$(echo "john.me.tz|root@john.me.tz|t470s.lan.john.me.tz|shb.ng|kipary.mailcleaner.net|media.lan.john.me.tz|pipcam.lan.john.me.tz|therm.lan.john.me.tz|hud.lan.john.me.tz|vm.lan.john.me.tz" | rofi -sep "|" -dmenu -i -p 'P ' "" -columns 1 -rows 1 -width 45 -l 1 -config /home/jpm/.config/rofi/config -hide-scrollbar -eh 1 -location 0 -yoffset 0 -padding 12 -opacity 100 -auto-select -no-fullscreen) res=$(echo "john.me.tz|root@john.me.tz|t470s.lan.john.me.tz|shb.ng|\
kipary.mailcleaner.net|media.lan.john.me.tz|pipcam.lan.john.me.tz|\
therm.lan.john.me.tz|hud.lan.john.me.tz|vm.lan.john.me.tz" | \
rofi -sep "|" -dmenu -i -p 'P ' "" -columns 1 -rows 1 -width 45 -l 1 -config \
/home/jpm/.config/rofi/config -hide-scrollbar -eh 1 -location 0 -yoffset 0 \
-padding 12 -opacity 100 -auto-select -no-fullscreen)
if [ $res = "john.me.tz" ]; then if [ $res = "john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs w' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs w'
elif [ $res = "root@john.me.tz" ]; then elif [ $res = "root@john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs r' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs r'
elif [ $res = "shb.ng" ]; then elif [ $res = "shb.ng" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs s' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs s'
elif [ $res = "kipary.mailcleaner.net" ]; then elif [ $res = "kipary.mailcleaner.net" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs d' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs d'
elif [ $res = "camera.lan.john.me.tz" ]; then elif [ $res = "camera.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs c' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs c'
elif [ $res = "hud.lan.john.me.tz" ]; then elif [ $res = "hud.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs h' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs h'
elif [ $res = "media.lan.john.me.tz" ]; then elif [ $res = "media.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs m' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs m'
elif [ $res = "programmer.lan.john.me.tz" ]; then elif [ $res = "programmer.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs p' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs p'
elif [ $res = "t470s.lan.john.me.tz" ]; then elif [ $res = "t470s.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs l' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs l'
elif [ $res = "therm.lan.john.me.tz" ]; then elif [ $res = "therm.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs t' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs t'
elif [ $res = "vm.lan.john.me.tz" ]; then elif [ $res = "vm.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs v' /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs v'
fi fi
exit 0 exit 0

View File

@ -9,10 +9,10 @@ sed -e 's/^\([0-9]*\)\t*\(.*\)/\2 \1/' |
rofi -dmenu -config ~/.config/rofi/sidebar.rasi | { rofi -dmenu -config ~/.config/rofi/sidebar.rasi | {
read -r read -r
id=`echo $REPLY | rev | cut -d' ' -f1 | rev` id=`echo $REPLY | rev | cut -d' ' -f1 | rev`
swaymsg "[con_id=$id]" focus swaymsg "[con_id=$id]" focus
} }

View File

@ -14,7 +14,7 @@ local_port=12345
show_help() show_help()
{ {
cat<<EOF cat<<EOF
Sends a video URL to Kodi Sends a video URL to Kodi
Usage: send-to-kodi.sh [URL] Usage: send-to-kodi.sh [URL]
@ -33,24 +33,24 @@ EOF
error() error()
{ {
if type zenity &>/dev/null; then if type zenity &>/dev/null; then
zenity --error --ellipsize --text "$*" zenity --error --ellipsize --text "$*"
else else
echo "$*" 1>&2 echo "$*" 1>&2
fi fi
exit 1 exit 1
} }
send_json() send_json()
{ {
curl \ curl \
${user:+--user "$user:$pass"} \ ${user:+--user "$user:$pass"} \
-X POST \ -X POST \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \ -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \
http://$host:$port/jsonrpc \ http://$host:$port/jsonrpc \
|| error "Failed to send link - is Kodi running?" || error "Failed to send link - is Kodi running?"
} }
ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid=' ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid='
@ -61,30 +61,35 @@ ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid='
# Dialog box? # Dialog box?
input=$1 input=$1
until [[ $input ]]; do until [[ $input ]]; do
input="$(zenity --entry --title "Send to Kodi" --text "Paste a video link here")" || exit input="$(zenity --entry --title "Send to Kodi" --text \
"Paste a video link here")" || exit
done done
if [[ $input =~ ^file:// ]]; then if [[ $input =~ ^file:// ]]; then
# Remove file:// and carrige return (\r) at the end # Remove file:// and carrige return (\r) at the end
input="$(sed 's%^file://%%;s/\r$//' <<< "$input")" input="$(sed 's%^file://%%;s/\r$//' <<< "$input")"
fi fi
# Get URL for... # Get URL for...
# Local media # Local media
if [[ -e $input ]]; then if [[ -e $input ]]; then
type nc &>/dev/null || error "netcat required" type nc &>/dev/null || error "netcat required"
[[ $local_hostname && $local_port ]] || error "Please set local hostname and port in configuration" [[ $local_hostname && $local_port ]] || \
error "Please set local hostname and port in configuration"
# Start netcat in background and kill it when we exit # Start netcat in background and kill it when we exit
nc -lp $local_port < "$input" & nc -lp $local_port < "$input" &
trap "kill $!" EXIT trap "kill $!" EXIT
url="tcp://$local_hostname:$local_port" url="tcp://$local_hostname:$local_port"
# youtube.com / youtu.be # youtube.com / youtu.be
elif [[ $input =~ ^https?://(www\.)?youtu(\.be/|be\.com/watch\?v=) ]]; then elif [[ $input =~ ^https?://(www\.)?youtu(\.be/|be\.com/watch\?v=) ]]; then
url="$ytplugin$(sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/' <<< "$input")" url="$ytplugin$(\
sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/'\
<<< "$input"\
)"
# Playable formats # Playable formats
elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jpg|png|gif|jpeg|tiff)(\?.*)?$ ]]; then elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jpg|png|gif|jpeg|tiff)(\?.*)?$ ]]; then
@ -92,8 +97,9 @@ elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jp
# Youtube-dl # Youtube-dl
else else
type youtube-dl &>/dev/null || error "youtube-dl required" type youtube-dl &>/dev/null || error "youtube-dl required"
url="$(youtube-dl -gf best "$input")" || error "No videos found, or site not supported by youtube-dl" url="$(youtube-dl -gf best "$input")" || \
error "No videos found, or site not supported by youtube-dl"
fi fi
[[ $url ]] && send_json "$url" [[ $url ]] && send_json "$url"

View File

@ -45,10 +45,10 @@ my $last = "$ENV{'HOME'}/.config/last_display";
# $ swaymsg -t get_outputs # $ swaymsg -t get_outputs
# Output eDP-1 'Unknown 0x057D *0x00000000*' # Output eDP-1 'Unknown 0x057D *0x00000000*'
my %outputs = ( my %outputs = (
'0x00000101' => 'Sam', '0x00000101' => 'Sam',
'3CQ4342S6W' => 'HP-1', '3CQ4342S6W' => 'HP-1',
'3CQ3310Q1Q' => 'HP-2', '3CQ3310Q1Q' => 'HP-2',
'0x00000000' => 'LVDS' '0x00000000' => 'LVDS'
); );
######################################################################## ########################################################################
@ -59,90 +59,90 @@ my %outputs = (
# Second-level keys are the display friendly-names, above # Second-level keys are the display friendly-names, above
# Third-level are the actual settings for that display # Third-level are the actual settings for that display
my %configs = ( my %configs = (
'detached' => { 'detached' => {
'HP-1' => { 'HP-1' => {
'on' => 0 'on' => 0
},
'HP-2' => {
'on' => 0
},
'Sam' => {
'on' => 0
},
'LVDS' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom'
}
}, },
'HP-2' => { 'stacked' => {
'on' => 0 'Sam' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 960,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom'
},
'HP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top'
},
'HP-2' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 1920,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top'
},
'LVDS' => {
'on' => 0
}
}, },
'Sam' => { 'sidebyside' => {
'on' => 0 'HP-1' => {
}, 'on' => 1,
'LVDS' => { 'width' => 1080,
'on' => 1, 'height' => 1920,
'width' => 1920, 'x' => 0,
'height' => 1080, 'y' => 225,
'x' => 0, 'rotate' => 270,
'y' => 0, 'waybar' => 'top'
'rotate' => 0, },
'waybar' => 'bottom' 'Sam' => {
'on' => 1,
'width' => 1200,
'height' => 1920,
'x' => 1080,
'y' => 0,
'rotate' => 90,
'waybar' => 'top'
},
'HP-2' => {
'on' => 1,
'width' => 1080,
'height' => 1920,
'x' => 2280,
'y' => 225,
'rotate' => 90,
'waybar' => 'top'
},
'LVDS' => {
'on' => 0,
}
} }
},
'stacked' => {
'Sam' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 960,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom'
},
'HP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top'
},
'HP-2' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 1920,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top'
},
'LVDS' => {
'on' => 0
}
},
'sidebyside' => {
'HP-1' => {
'on' => 1,
'width' => 1080,
'height' => 1920,
'x' => 0,
'y' => 225,
'rotate' => 270,
'waybar' => 'top'
},
'Sam' => {
'on' => 1,
'width' => 1200,
'height' => 1920,
'x' => 1080,
'y' => 0,
'rotate' => 90,
'waybar' => 'top'
},
'HP-2' => {
'on' => 1,
'width' => 1080,
'height' => 1920,
'x' => 2280,
'y' => 225,
'rotate' => 90,
'waybar' => 'top'
},
'LVDS' => {
'on' => 0,
}
}
); );
######################################################################## ########################################################################
@ -156,34 +156,37 @@ my $waybar_only = 0;
my $config; my $config;
if (scalar(@ARGV)) { if (scalar(@ARGV)) {
while (@ARGV) { while (@ARGV) {
my $arg = shift; my $arg = shift;
if ($arg eq "-w") { if ($arg eq "-w") {
$waybar_only = 1; $waybar_only = 1;
} else { } else {
if (defined $config) { if (defined $config) {
die "Too many arguments.\n"; die "Too many arguments.\n";
} }
$config = $arg; $config = $arg;
}
} }
}
} }
# Get previous config if one is not provided # Get previous config if one is not provided
unless (defined $config) { unless (defined $config) {
open(my $fh, '<', $last) || die "Config name not provided and failed to open $last\n"; open(my $fh, '<', $last) ||
$config = <$fh>; die "Config name not provided and failed to open $last\n";
close($fh); $config = <$fh>;
chomp $config; close($fh);
chomp $config;
} }
# Bail if requested config doesn't exist # Bail if requested config doesn't exist
unless (defined $configs{$config}) { unless (defined $configs{$config}) {
die "$config is not a defined configuration: " . join(', ', keys %configs) . "\n"; die "$config is not a defined configuration: "
. join(', ', keys %configs) . "\n";
} }
# Write config that is to be used so that it can be recovered as default # Write config that is to be used so that it can be recovered as default
open(my $fh, '>', $last) || print STDERR "Config name cannot be written to $last\n"; open(my $fh, '>', $last) ||
print STDERR "Config name cannot be written to $last\n";
print $fh $config; print $fh $config;
close($fh); close($fh);
@ -199,72 +202,77 @@ my $on;
my @off; my @off;
for (my $i = 0; $i < scalar(@$displays); $i++) { for (my $i = 0; $i < scalar(@$displays); $i++) {
# If a display is found without any settings, print error and turn it off # If a display is found without any settings print error and turn it off
unless (defined $configs{$config}{$outputs{$displays->[$i]->{serial}}}) { unless (defined $configs{$config}{$outputs{$displays->[$i]->{serial}}}){
print STDERR "Output $displays->[$i]->{name} ($displays->[$i]->{serial}) found without defined function. Disabling.\n"; print STDERR "Output $displays->[$i]->{name} ("
push @off, $displays->[$i]->{name}; . $displays->[$i]->{serial}
next; . ") found without defined function. Disabling.\n";
} push @off, $displays->[$i]->{name};
next;
}
# If display is enabled, copy all of the desired settings # If display is enabled, copy all of the desired settings
if ($configs{$config}{$outputs{$displays->[$i]->{serial}}}{on}) { if ($configs{$config}{$outputs{$displays->[$i]->{serial}}}{on}) {
$on->{$outputs{$displays->[$i]->{serial}}} = $configs{$config}{$outputs{$displays->[$i]->{serial}}}; $on->{$outputs{$displays->[$i]->{serial}}} =
$on->{$outputs{$displays->[$i]->{serial}}}{output} = $displays->[$i]->{name}; $configs{$config}{$outputs{$displays->[$i]->{serial}}};
# Otherwise simply list it for disabling $on->{$outputs{$displays->[$i]->{serial}}}{output} =
} else { $displays->[$i]->{name};
push @off, $displays->[$i]->{name}; # Otherwise simply list it for disabling
} } else {
push @off, $displays->[$i]->{name};
}
} }
# Skip enabling/disabling displays if only running waybar (re)start # Skip enabling/disabling displays if only running waybar (re)start
unless ($waybar_only) { unless ($waybar_only) {
# Number of simultaneous outputs is limited by gpu, so disabled displays first # Number of simultaneous outputs is limited by gpu, so disabled displays
foreach (@off) { # first
foreach (@off) {
# Sway returns status as JSON # Sway returns status as JSON
my $res_raw = `sway output $_ disable`; my $res_raw = `sway output $_ disable`;
my $res = $json->decode($res_raw)->[0]; my $res = $json->decode($res_raw)->[0];
# If failed, print to STDERR
unless ($res->{success}) {
print STDERR "Error ($res->{error}) in command 'sway"
. "output $_ disable'\n";
}
# If failed, print to STDERR
unless ($res->{success}) {
print STDERR "Error ($res->{error}) in command 'sway output $_ disable'\n";
} }
}
} }
# Kill existing Waybars # Kill existing Waybars
require Proc::ProcessTable; require Proc::ProcessTable;
my $t = new Proc::ProcessTable; my $t = new Proc::ProcessTable;
foreach my $p ( @{ $t->table } ) { foreach my $p ( @{ $t->table } ) {
my $cmndline = $p->{'cmndline'}; my $cmndline = $p->{'cmndline'};
$cmndline =~ s/\s*$//g; $cmndline =~ s/\s*$//g;
if ($cmndline =~ /^waybar.*/) { if ($cmndline =~ /^waybar.*/) {
# Never kill this process # Never kill this process
if ($p->{'pid'} == $$) { if ($p->{'pid'} == $$) {
next; next;
# SIGKILL match } else {
# TODO BUG: when multiple processes are running, some respawn with new PIDs. IDK why? $p->kill(9);
} else { }
$p->kill(9);
} }
}
} }
# Load in config template # Load in config template
my $template; my $template;
if (open (my $fh, '<', $waybar_template)) { if (open (my $fh, '<', $waybar_template)) {
while (<$fh>) { while (<$fh>) {
$template .= $_; $template .= $_;
} }
close $fh; close $fh;
chomp $template; chomp $template;
} else { } else {
print STDERR "Failed to load template $waybar_template\n"; print STDERR "Failed to load template $waybar_template\n";
} }
# If template is already set up as an array, remove the square brackets so that we can concatenate multiple displays # If template is already set up as an array, remove the square brackets so that
# we can concatenate multiple displays
$template =~ s/^[^\[\{]*\[(.*)\]$/$1/s; $template =~ s/^[^\[\{]*\[(.*)\]$/$1/s;
# Setup waybar config file # Setup waybar config file
@ -273,52 +281,57 @@ my $waybar = '';
# Configure each enabled display # Configure each enabled display
foreach my $out (keys %$on) { foreach my $out (keys %$on) {
unless ($waybar_only) { unless ($waybar_only) {
# Build command, starting by enabling and powering on # Build command, starting by enabling and powering on
my $cmd = "sway output $on->{$out}->{output} enable dpms on"; my $cmd = "sway output $on->{$out}->{output} enable dpms on";
# If additional options are provided, add them to command # If additional options are provided, add them to command
if (defined $on->{$out}->{rotate}) { if (defined $on->{$out}->{rotate}) {
$cmd .= " transform $on->{$out}->{rotate}"; $cmd .= " transform $on->{$out}->{rotate}";
} }
if (defined $on->{$out}->{x} && defined $on->{$out}->{y}) { if (defined $on->{$out}->{x} && defined $on->{$out}->{y}) {
$cmd .= " position $on->{$out}->{x} $on->{$out}->{y}"; $cmd .= " position $on->{$out}->{x} $on->{$out}->{y}";
} }
if (defined $on->{$out}->{width} && defined $on->{$out}->{height}) { if (defined $on->{$out}->{width} &&
$cmd .= " mode $on->{$out}->{width}x$on->{$out}->{height}"; defined $on->{$out}->{height} )
{
$cmd .= " mode $on->{$out}->{width}x$on->{$out}->{height}";
}
# Sway returns status as JSON
my $res_raw = `$cmd`;
my $res = $json->decode($res_raw)->[0];
# If failed, print to STDERR
unless ($res->{success}) {
print STDERR "Error ($res->{error}) in command '$cmd'\n";
}
} }
# Sway returns status as JSON # Skip waybar setup if template failed to be loaded
my $res_raw = `$cmd`; if ( (defined $template) &&
my $res = $json->decode($res_raw)->[0]; (defined $on->{$out}->{waybar}) &&
($on->{$out}->{waybar} =~ m/(top|bottom|left|right)/) )
{
# If there's already a display set up, add a comma
unless ($waybar eq '') {
$waybar .= ',';
}
$waybar .= $template;
# Replace basic preferences
$waybar =~ s/__OUTPUT__/"$on->{$out}->{output}"/;
$waybar =~ s/__POSITION__/"$on->{$out}->{waybar}"/;
if (defined $on->{$out}->{width}) {
$waybar =~ s/__WIDTH__/$on->{$out}->{width}/;
# If width is not set, comment that line out to use default
} else {
$waybar =~ s/([^\s]*\s*)__WIDTH__/\/\/ $1__WIDTH__/gg;
}
# If failed, print to STDERR
unless ($res->{success}) {
print STDERR "Error ($res->{error}) in command '$cmd'\n";
} }
}
# Skip waybar setup if template failed to be loaded
if ( (defined $template) && (defined $on->{$out}->{waybar}) && ($on->{$out}->{waybar} =~ m/(top|bottom|left|right)/) ) {
# If there's already a display set up, add a comma
unless ($waybar eq '') {
$waybar .= ',';
}
$waybar .= $template;
# Replace basic preferences
$waybar =~ s/__OUTPUT__/"$on->{$out}->{output}"/;
$waybar =~ s/__POSITION__/"$on->{$out}->{waybar}"/;
if (defined $on->{$out}->{width}) {
$waybar =~ s/__WIDTH__/$on->{$out}->{width}/;
# If width is not set, comment that line out to use default
} else {
$waybar =~ s/([^\s]*\s*)__WIDTH__/\/\/ $1__WIDTH__/gg;
}
}
} }
# Restore array formatting # Restore array formatting
@ -327,16 +340,16 @@ $waybar = '[' . $waybar . ']';
# Start Waybar as fork # Start Waybar as fork
my $pid = fork; my $pid = fork;
unless ($pid) { unless ($pid) {
open STDIN, '/dev/null'; open STDIN, '/dev/null';
open STDOUT, '>>/dev/null'; open STDOUT, '>>/dev/null';
open STDERR, '>>/dev/null'; open STDERR, '>>/dev/null';
# Write config to a temporary file # Write config to a temporary file
my $tmp = $waybar_temporary . "/waybar-" . time() .".config"; my $tmp = $waybar_temporary . "/waybar-" . time() .".config";
open ($fh, '>', $tmp); open ($fh, '>', $tmp);
print $fh $waybar; print $fh $waybar;
close $fh; close $fh;
`nohup waybar --config=$tmp`; `nohup waybar --config=$tmp`;
# Remove config # Remove config
unlink $tmp; unlink $tmp;
} }

View File

@ -16,27 +16,28 @@ my $lat_lon = fetch_lat_lon($ua, $json, $location);
my $pid = fork; my $pid = fork;
unless ($pid) { unless ($pid) {
open STDIN, '/dev/null'; open STDIN, '/dev/null';
open STDOUT, '>>/dev/null'; open STDOUT, '>>/dev/null';
open STDERR, '>>/dev/null'; open STDERR, '>>/dev/null';
`gammastep -l $lat_lon`; `gammastep -l $lat_lon`;
} }
sub fetch_lat_lon { sub fetch_lat_lon
my ($ua, $json, $location) = @_; {
my ($ua, $json, $location) = @_;
my $raw = $ua->get($location)->content();
if (defined $raw) {
my $decoded = $json->decode($raw);
if (defined $decoded->{lat} && defined $decoded->{lon}) {
return "$decoded->{lat}:$decoded->{lon}";
}
print $decoded->{lat};
my $raw = $ua->get($location)->content();
if (defined $raw) {
my $decoded = $json->decode($raw);
if (defined $decoded->{lat} && defined $decoded->{lon}) {
return "$decoded->{lat}:$decoded->{lon}";
} }
print $decoded->{lat}; sleep 5;
return fetch_lat_lon($ua, $json, $location);
}
sleep 5;
return fetch_lat_lon($ua, $json, $location);
} }
exit; exit;

View File

@ -19,57 +19,61 @@ my $root = $json->decode($raw);
my $display = $root->{focus}->[0]; my $display = $root->{focus}->[0];
my ($workspace, $term_id, $term_ws); my ($workspace, $term_id, $term_ws);
foreach my $d (@{$root->{nodes}}) { foreach my $d (@{$root->{nodes}}) {
# If both the current workspace and terminal have been found, nothing else to look for # If both the current workspace and terminal have been found
if (defined($workspace) && defined($term_id)) { # nothing else to look for
last; if (defined($workspace) && defined($term_id)) {
# If the display from this iteration of the loop is in focus, look for the active workspace
} elsif ($d->{id} eq $display) {
foreach my $w (@{$d->{nodes}}) {
# Again, if both found, skip
if (defined($workspace) && defined($term_id)) {
last; last;
# Otherwise if the current workspace is active, mark it # If the display from this iteration of the loop is in focus
} elsif ($w->{id} eq $d->{focus}->[0]) { # look for the active workspace
$workspace = $w->{name}; } elsif ($d->{id} eq $display) {
} foreach my $w (@{$d->{nodes}}) {
# In any case, look for the terminal app # Again, if both found, skip
foreach my $n (@{$w->{floating_nodes}}) { if (defined($workspace) && defined($term_id)) {
if ($n->{name} eq $term) { last;
$term_id = $n->{id}; # Otherwise if the current workspace is active, mark it
$term_ws = $w->{name}; } elsif ($w->{id} eq $d->{focus}->[0]) {
last; $workspace = $w->{name};
}
# In any case, look for the terminal app
foreach my $n (@{$w->{floating_nodes}}) {
if ($n->{name} eq $term) {
$term_id = $n->{id};
$term_ws = $w->{name};
last;
}
}
} }
} # All other displays only need to be quickly searched for the term_id
} } else {
# All other displays only need to be quickly searched for the term_id foreach my $w (@{$d->{nodes}}) {
} else { if (defined($term_id)) {
foreach my $w (@{$d->{nodes}}) { last;
if (defined($term_id)) { }
last; foreach my $n (@{$w->{floating_nodes}}) {
} if ($n->{name} eq $term) {
foreach my $n (@{$w->{floating_nodes}}) { $term_id = $n->{id};
if ($n->{name} eq $term) { $term_ws = $w->{name};
$term_id = $n->{id}; last;
$term_ws = $w->{name}; }
last; }
} }
}
} }
}
} }
print "Active workspace = $workspace\nTerminal ID = $term_id\nTerminal WS = $term_ws\n"; print "Active workspace = $workspace\n"
. "Terminal ID = $term_id\n"
. "Terminal WS = $term_ws\n";
# If there is no terminal found, spawn one # If there is no terminal found, spawn one
if (!defined($term_id)) { if (!defined($term_id)) {
print "No term running, starting one\n"; print "No term running, starting one\n";
exec $term exec $term
# If the current workspace is known and terminal isn't on it, bring and give focus # If the current workspace is known and terminal isn't on it, bring and focus
} elsif ($workspace != $term_ws) { } elsif ($workspace != $term_ws) {
print "Term not on current workspace, bringing it\n"; print "Term not on current workspace, bringing it\n";
`swaymsg "[con_id=$term_id]" move workspace $workspace`; `swaymsg "[con_id=$term_id]" move workspace $workspace`;
`swaymsg "[con_id=$term_id]" focus`; `swaymsg "[con_id=$term_id]" focus`;
# Otherwise hide it from whereever it is # Otherwise hide it from whereever it is
} else { } else {
print "Term is on current workspace or lost, moving to $hidden\n"; print "Term is on current workspace or lost, moving to $hidden\n";
`swaymsg "[con_id=$term_id]" move workspace $hidden`; `swaymsg "[con_id=$term_id]" move workspace $hidden`;
} }

View File

@ -3,30 +3,34 @@
BLFILE="/tmp/blc" BLFILE="/tmp/blc"
if [ -z $1 ]; then if [ -z $1 ]; then
echo "Missing argument: swayidlerun, swayidlewarn, swayidlesleep or swayidlewake" echo "Missing argument: swayidlerun, swayidlewarn, swayidlesleep or" \
" swayidlewake"
elif [ $1 == "swayidlerun" ]; then elif [ $1 == "swayidlerun" ]; then
swayidle timeout 270 "/home/jpm/scripts/swayidle.sh swayidlewarn" before-sleep "/home/jpm/scripts/swayidle.sh swayidlesleep" resume "/home/jpm/scripts/swayidle.sh swayidlewake" swayidle timeout 270 "/home/jpm/scripts/swayidle.sh swayidlewarn" \
before-sleep "/home/jpm/scripts/swayidle.sh swayidlesleep" \
resume "/home/jpm/scripts/swayidle.sh swayidlewake"
elif [ $1 == "swayidlewarn" ]; then elif [ $1 == "swayidlewarn" ]; then
# Store current brightness # Store current brightness
echo $(/home/jpm/bin/blc.pl %) > $BLFILE echo $(/home/jpm/bin/blc.pl %) > $BLFILE
# Dim display # Dim display
/home/jpm/bin/blc.pl = 1 /home/jpm/bin/blc.pl = 1
# Warning notifications # Warning notifications
/home/jpm/scripts/swayidlecountdown.sh /home/jpm/scripts/swayidlecountdown.sh
elif [ $1 == "swayidlesleep" ]; then elif [ $1 == "swayidlesleep" ]; then
# Change nick to AFK # Change nick to AFK
ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t 'screen -S irssi -X stuff "/nick jpmAFK^M"' ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
# Turn off monitor 'screen -S irssi -X stuff "/nick jpmAFK^M"'
swaymsg 'swaymsg "output * dpms off"' # Turn off monitor
# Lock screen swaymsg 'swaymsg "output * dpms off"'
swaylock -c 323232 # Lock screen
swaylock -c 323232
elif [ $1 == "swayidlewake" ]; then elif [ $1 == "swayidlewake" ]; then
# Kill sleep if running # Kill sleep if running
# Turn on monitor # Turn on monitor
swaymsg 'swaymsg "output * dpms on"' swaymsg 'swaymsg "output * dpms on"'
# Restore brightness level # Restore brightness level
kill `pgrep swayidlecountdo` kill `pgrep swayidlecountdo`
/home/jpm/bin/blc.pl = $(cat /tmp/blc) /home/jpm/bin/blc.pl = $(cat /tmp/blc)
else else
echo "Invalid argument: run, sleep or wake" echo "Invalid argument: run, sleep or wake"
fi fi

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
for i in `seq 0 30`; do for i in `seq 0 30`; do
notify-send -t 999 "Sleeping" $(expr 30 - $i); sleep 1 notify-send -t 999 "Sleeping" $(expr 30 - $i); sleep 1
done done

View File

@ -3,7 +3,7 @@
CURRENT=`cat /home/jpm/.config/last_display` CURRENT=`cat /home/jpm/.config/last_display`
if [ "$CURRENT" == "detached" ]; then if [ "$CURRENT" == "detached" ]; then
/home/jpm/scripts/sway/displays.pl stacked /home/jpm/scripts/sway/displays.pl stacked
else else
/home/jpm/scripts/sway/displays.pl detached /home/jpm/scripts/sway/displays.pl detached
fi fi

View File

@ -5,107 +5,117 @@ my $cur_file = "/sys/class/backlight/intel_backlight/brightness";
my $max_file = "/sys/class/backlight/intel_backlight/max_brightness"; my $max_file = "/sys/class/backlight/intel_backlight/max_brightness";
my $last_file = "/home/jpm/.config/blc.last"; my $last_file = "/home/jpm/.config/blc.last";
sub to_percent { sub to_percent
my $value = shift; {
if ($value eq "Permission Denied") { my $value = shift;
return $value; if ($value eq "Permission Denied") {
} else { return $value;
$value = int($value/get_max()*100);
return $value . '%';
}
}
sub get_offset {
return int(get_max()/100);
}
sub get_current {
open(my $c,'<',"$cur_file");
my $current = <$c>;
close $c;
chomp $current;
return $current;
}
sub get_max {
open(my $m,'<',"$max_file");
my $max = <$m>;
close $m;
chomp $max;
return $max;
}
sub get_min {
return int((get_max()/100)+2);
}
sub writable {
if (! -w $cur_file) {
return 0;
} else {
return 1;
}
}
sub increment {
if (writable()) {
my $current = get_current();
my $max = get_max();
my $target = $current+get_offset();
if ($target > $max) {
$target = $max;
}
open(my $c,'>',"$cur_file");
print $c $target;
close $c;
return $target;
} else {
return "Permission Denied";
}
}
sub decrement {
if (writable()) {
my $current = get_current();
my $min = get_min();
my $target = $current-get_offset();
if ($target < $min) {
$target = $min;
}
open(my $c,'>',"$cur_file");
print $c $target;
close $c;
return $target;
} else {
return "Permission Denied";
}
}
sub set {
my $value = shift;
if (writable()) {
$current = get_current();
if ($value > $current) {
for (my $i=$current;$i<=$value;$i++) {
open(my $c,'>',"$cur_file");
print $c $i;
close $c;
}
} else { } else {
for (my $i=$current;$i>=$value;$i--) { $value = int($value/get_max()*100);
open(my $c,'>',"$cur_file"); return $value . '%';
print $c $i;
close $c;
}
} }
return $value;
} else {
return "Permission Denied";
}
} }
sub help { sub get_offset
print " {
return int(get_max()/100);
}
sub get_current
{
open(my $c,'<',"$cur_file");
my $current = <$c>;
close $c;
chomp $current;
return $current;
}
sub get_max
{
open(my $m,'<',"$max_file");
my $max = <$m>;
close $m;
chomp $max;
return $max;
}
sub get_min
{
return int((get_max()/100)+2);
}
sub writable
{
if (! -w $cur_file) {
return 0;
} else {
return 1;
}
}
sub increment
{
if (writable()) {
my $current = get_current();
my $max = get_max();
my $target = $current+get_offset();
if ($target > $max) {
$target = $max;
}
open(my $c,'>',"$cur_file");
print $c $target;
close $c;
return $target;
} else {
return "Permission Denied";
}
}
sub decrement
{
if (writable()) {
my $current = get_current();
my $min = get_min();
my $target = $current-get_offset();
if ($target < $min) {
$target = $min;
}
open(my $c,'>',"$cur_file");
print $c $target;
close $c;
return $target;
} else {
return "Permission Denied";
}
}
sub set
{
my $value = shift;
if (writable()) {
$current = get_current();
if ($value > $current) {
for (my $i=$current;$i<=$value;$i++) {
open(my $c,'>',"$cur_file");
print $c $i;
close $c;
}
} else {
for (my $i=$current;$i>=$value;$i--) {
open(my $c,'>',"$cur_file");
print $c $i;
close $c;
}
}
return $value;
} else {
return "Permission Denied";
}
}
sub help
{
print "
Backlight Control Backlight Control
Usage: blc.pl [--silent|--notify] [OPTION] [VALUE] Usage: blc.pl [--silent|--notify] [OPTION] [VALUE]
@ -146,29 +156,30 @@ Print:
Any other option will be printed literally"; Any other option will be printed literally";
} }
sub advanced { sub advanced
$current = get_current(); {
$max = get_max(); $current = get_current();
print ". $max = get_max();
print ".
Print functions can be strung together but command will exit Print functions can be strung together but command will exit
with the first non-print option. eg. with the first non-print option. eg.
\$ blc.pl == / ^ \$ blc.pl == / ^
21/100 21/100
\$ blc.pl == ++ \$ blc.pl == ++
('==' ignored) ('==' ignored)
(Backlight incremented) (Backlight incremented)
Escape options with \\ in quotes to display them literally. eg. Escape options with \\ in quotes to display them literally. eg.
\$ blc.pl == / ^ '\\=' % \'\\%\' \$ blc.pl == / ^ '\\=' % \'\\%\'
" . $current . "/" . $max . "=" . int($current/$max*100) . "% " . $current . "/" . $max . "=" . int($current/$max*100) . "%
Only one \'\\' is removed per block. eg. Only one \'\\' is removed per block. eg.
\$ blc.pl '\\% \\' \$ blc.pl '\\% \\'
% \\ % \\
"; ";
} }
@ -177,107 +188,121 @@ my $current = get_current();
my (@output, $target, $silent, $notify); my (@output, $target, $silent, $notify);
if (scalar @ARGV) { if (scalar @ARGV) {
for (my $i=0;$i<scalar @ARGV;$i++) { for (my $i=0;$i<scalar @ARGV;$i++) {
if ($ARGV[$i] eq '++') { if ($ARGV[$i] eq '++') {
$target = increment(); $target = increment();
@output = to_percent($target);
last;
} elsif ($ARGV[$i] eq '+=') {
for (my $i=0;$i<scalar @ARGV;$i++) {
if ($ARGV[$i] eq '+=') {
if (defined $ARGV[($i+1)]) {
$count = $ARGV[($i+1)];
for (my $j=0;$j<$count;$j++) {
$target = increment();
if ($target eq "Permission Denied") {
last;
}
}
@output = to_percent($target); @output = to_percent($target);
} else { last;
@output = ("No value after $ARGV[$i]"); } elsif ($ARGV[$i] eq '+=') {
} for (my $i=0;$i<scalar @ARGV;$i++) {
last; if ($ARGV[$i] eq '+=') {
} if (defined $ARGV[($i+1)]) {
} $count = $ARGV[($i+1)];
last; for (my $j=0;$j<$count;$j++) {
} elsif ($ARGV[$i] eq '--') { $target = increment();
$target = decrement(); if ($target eq
@output = to_percent($target); "Permission Denied") {
last; last;
} elsif ($ARGV[$i] eq '-=') { }
for (my $i=0;$i<scalar @ARGV;$i++) { }
if ($ARGV[$i] eq '-=') { @output = to_percent($target);
if (defined $ARGV[($i+1)]) { } else {
$count = $ARGV[($i+1)]; @output =
for (my $j=0;$j<$count;$j++) { ("No value after $ARGV[$i]");
$target = decrement(); }
if ($target eq "Permission Denied") { last;
last; }
}
} }
last;
} elsif ($ARGV[$i] eq '--') {
$target = decrement();
@output = to_percent($target); @output = to_percent($target);
} else { last;
@output = ("No value after $ARGV[$i]"); } elsif ($ARGV[$i] eq '-=') {
} for (my $i=0;$i<scalar @ARGV;$i++) {
last; if ($ARGV[$i] eq '-=') {
} if (defined $ARGV[($i+1)]) {
} $count = $ARGV[($i+1)];
last; for (my $j=0;$j<$count;$j++) {
} elsif ($ARGV[$i] eq '=') { $target = decrement();
$target = $ARGV[($i+1)]; if ($target eq
if (defined $target) { "Permission Denied") {
if ($target < 1) { last;
$target = set(get_min()); }
} elsif ($target > get_max()) { }
$target = set(get_max()); @output = to_percent($target);
} elsif ($target > 100) { } else {
$target = set($target); @output =
("No value after $ARGV[$i]");
}
last;
}
}
last;
} elsif ($ARGV[$i] eq '=') {
$target = $ARGV[($i+1)];
if (defined $target) {
if ($target < 1) {
$target = set(get_min());
} elsif ($target > get_max()) {
$target = set(get_max());
} elsif ($target > 100) {
$target = set($target);
} else {
$target = set(
int((get_max()*$target/100)+1)
);
}
if ($target eq "Permission Denied") {
@output = $target;
} else {
@output = to_percent($target);
}
last;
} else {
@output = ("No value after $ARGV[$i]");
last;
}
} elsif ($ARGV[$i] eq '%') {
push @output,int(get_current()/get_max()*100);
} elsif ($ARGV[$i] eq '^') {
push @output,get_max();
} elsif ($ARGV[$i] eq '==') {
push @output,get_current();
} elsif ($ARGV[$i] eq '--help') {
help();
print " (see --HELP).\n\n";
exit();
} elsif ($ARGV[$i] eq '--HELP') {
help();
advanced();
exit();
} elsif ($ARGV[$i] eq '--silent') {
$silent = 'TRUE';
} elsif ($ARGV[$i] =~ /^--notify/) {
$notify = 'TRUE';
if ($ARGV[$i] =~ /=[0-9]+$/) {
$duration = $ARGV[$i];
$duration =~ s/.*=([0-9]+)/$1/;
} else {
$duration = 200;
}
} else { } else {
$target = set(int((get_max()*$target/100)+1)); my $add = $ARGV[$i];
$add =~ s/\\//;
push @output,$add;
} }
if ($target eq "Permission Denied") {
@output = $target;
} else {
@output = to_percent($target);
}
last;
} else {
@output = ("No value after $ARGV[$i]");
last;
}
} elsif ($ARGV[$i] eq '%') {
push @output,int(get_current()/get_max()*100);
} elsif ($ARGV[$i] eq '^') {
push @output,get_max();
} elsif ($ARGV[$i] eq '==') {
push @output,get_current();
} elsif ($ARGV[$i] eq '--help') {
help();
print " (see --HELP).\n\n";
exit();
} elsif ($ARGV[$i] eq '--HELP') {
help();
advanced();
exit();
} elsif ($ARGV[$i] eq '--silent') {
$silent = 'TRUE';
} elsif ($ARGV[$i] =~ /^--notify/) {
$notify = 'TRUE';
if ($ARGV[$i] =~ /=[0-9]+$/) {
$duration = $ARGV[$i];
$duration =~ s/.*=([0-9]+)/$1/;
} else {
$duration = 200;
}
} else {
my $add = $ARGV[$i];
$add =~ s/\\//;
push @output,$add;
} }
}
} else { } else {
@output = ('{"Backlight":{"Max":"' . get_max() . '","Current":"' . get_current() . '","Percentage","' . int(get_current()/get_max()*100) . '%"}}'); @output = (
'{"Backlight":{"Max":"'
. get_max()
. '","Current":"'
. get_current()
. '","Percentage","'
. int(get_current()/get_max()*100)
. '%"}}'
);
} }
@ -286,20 +311,26 @@ print $fh get_current();
close($fh); close($fh);
if ($silent) { if ($silent) {
exit();
} elsif ($notify) {
# Don't output anything if the value didn't change
if ($current == get_current()) {
exit(); exit();
} } elsif ($notify) {
my $concat; # Don't output anything if the value didn't change
foreach (@output) { if ($current == get_current()) {
$concat .= $_; exit();
} }
system "notify-send --urgency=normal -i /usr/share/icons/Papirus-Dark-Grey/48x48/status/notification-display-brightness.svg -t $duration \"$concat\""; my $concat;
exit(); foreach (@output) {
$concat .= $_;
}
system "notify-send --urgency=normal -i "
. "/usr/share/icons/Papirus-Dark-Grey/48x48/status/"
. "notification-display-brightness.svg -t "
. $duration
. ' "'
. $concat
. '"';
exit();
} else { } else {
print foreach @output; print foreach @output;
print "\n"; print "\n";
exit(); exit();
} }

View File

@ -8,32 +8,32 @@ my $current = "/sys/class/leds/tpacpi\:\:kbd_backlight/brightness";
my ($max, $now, $new); my ($max, $now, $new);
if (open(my $m, '<', $maxfile)) { if (open(my $m, '<', $maxfile)) {
$max = readline($m); $max = readline($m);
chomp $max; chomp $max;
close($m); close($m);
} else { } else {
print "Failed to read $maxfile\n"; print "Failed to read $maxfile\n";
exit; exit;
} }
print STDERR "max = $max\n"; print STDERR "max = $max\n";
if (open(my $c, '<', $current)) { if (open(my $c, '<', $current)) {
$now = readline($c); $now = readline($c);
chomp $now; chomp $now;
close($c); close($c);
} else { } else {
print "Failed to read $current\n"; print "Failed to read $current\n";
exit; exit;
} }
print STDERR "now = $now\n"; print STDERR "now = $now\n";
if (open(my $fh, '>', $current)) { if (open(my $fh, '>', $current)) {
$new = (($now+1) % ($max+1)); $new = (($now+1) % ($max+1));
chomp $new; chomp $new;
print $fh $new; print $fh $new;
close($fh); close($fh);
} else { } else {
print "Failed to write $current\n"; print "Failed to write $current\n";
exit; exit;
} }
print STDERR "new = $new\n"; print STDERR "new = $new\n";

View File

@ -2,7 +2,9 @@
Description=Give ownership of backlight to %I Description=Give ownership of backlight to %I
[Service] [Service]
ExecStart=chown %i:%i /sys/class/backlight/intel_backlight/brightness /sys/class/leds/tpacpi::kbd_backlight/brightness ExecStart=chown %i:%i \
/sys/class/backlight/intel_backlight/brightness \
/sys/class/leds/tpacpi::kbd_backlight/brightness
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -11,43 +11,52 @@ my $install = "$ENV{HOME}/.local/bin";
my $working = "/tmp/firefox.new"; my $working = "/tmp/firefox.new";
# Download link as provided by https://www.mozilla.org/$lang/firefox/developer/ # Download link as provided by https://www.mozilla.org/$lang/firefox/developer/
my $url = 'https://download.mozilla.org/?product=firefox-devedition-latest-ssl&os=linux64&lang='.$lang; my $url = 'https://download.mozilla.org/?product=firefox-devedition-latest-ssl'
. '&os=linux64&lang='.$lang;
# Ensure that we can unzip # Ensure that we can unzip
unless (which("bunzip2")) { unless (which("bunzip2")) {
die "Requires bunzip2. Try:\nsudo apt install zutils or your distro's equivalent\n"; die "Requires bunzip2. Try:\n"
. "sudo apt install zutils or your distro's equivalent\n";
} }
# Only understood argument is to not bother verifying the package # Only understood argument is to not bother verifying the package
my ($download_key, $verify) = (0,1); my ($download_key, $verify) = (0,1);
if (defined $ARGV[0]) { if (defined $ARGV[0]) {
if ($ARGV[0] eq '--no-verify') { if ($ARGV[0] eq '--no-verify') {
$verify = 0; $verify = 0;
} else { } else {
die "Didn't understand argument $ARGV[0]\n"; die "Didn't understand argument $ARGV[0]\n";
} }
} }
# If verification is to be done, make sure we have the key # If verification is to be done, make sure we have the key
unless ($verify) { unless ($verify) {
print "Checking for Mozilla GPG key in keyring...\n"; print "Checking for Mozilla GPG key in keyring...\n";
system("gpg --list-keys release\@mozillla.com 2>&1 > /dev/null"); system("gpg --list-keys release\@mozillla.com 2>&1 > /dev/null");
if ($?) { if ($?) {
my $YN = prompt (-in => *STDIN, "You don't currently have Mozilla's GPG key in your keyring.\nWould you like to install it? If not, installation will not be verified. [y/N]: ", -single); my $YN = prompt (-in => *STDIN, "You don't currently have "
if ($YN eq 'y' || $YN eq 'Y') { . "Mozilla's GPG key in your keyring.\n"
$download_key = 1; . "Would you like to install it? If not, installation "
} else { . "will not be verified. [y/N]: ",
$verify = 0; -single
);
if ($YN eq 'y' || $YN eq 'Y') {
$download_key = 1;
} else {
$verify = 0;
}
} }
}
} }
# If a previous download still exists remove it # If a previous download still exists remove it
if ( -e $working ) { if ( -e $working ) {
system("rm -rf $working"); system("rm -rf $working");
if ($?) { if ($?) {
die "Working directory $working already exists and failed to remove: $!\n"; die "Working directory "
} . $working
. "already exists and failed to remove: $!\n";
}
} }
# Get version currently installed # Get version currently installed
@ -58,19 +67,21 @@ chomp $current;
use WWW::Mechanize; use WWW::Mechanize;
my $mech = WWW::Mechanize->new(); my $mech = WWW::Mechanize->new();
# $url is actually going to redirect to the proper current dowload, so just get the redirect. # $url is actually going to redirect to the proper current dowload so just get
# the redirect.
my $head = $mech->head($url); my $head = $mech->head($url);
my ($location, $version); my ($location, $version);
# This redirect will have the version id, so we can use that to determine if a new version actually exists # This redirect will have the version id, so we can use that to determine if a
# new version actually exists
if ($head->{'_msg'}) { if ($head->{'_msg'}) {
$version = $location = $head->{'_previous'}->{'_headers'}->{'location'}; $version = $location = $head->{'_previous'}->{'_headers'}->{'location'};
$version =~ s/^.*\-([^\-]*)\.tar\.bz2$/$1/; $version =~ s/^.*\-([^\-]*)\.tar\.bz2$/$1/;
if ($version eq $current) { if ($version eq $current) {
die "Current ($current) is the same as New ($version)\n"; die "Current ($current) is the same as New ($version)\n";
} }
} else { } else {
print "unable to find new download\n"; print "unable to find new download\n";
} }
mkdir($working) || die "Couldn't make $working: $!\n"; mkdir($working) || die "Couldn't make $working: $!\n";
@ -78,77 +89,106 @@ mkdir($working) || die "Couldn't make $working: $!\n";
# Download package # Download package
print "Fetching package $location...\n"; print "Fetching package $location...\n";
$mech->get($location); $mech->get($location);
$mech->save_content( $working."/firefox-".$version.".tar.bz2", binmode => ':raw', decoded_by_headers => 1 ); $mech->save_content( $working."/firefox-".$version.".tar.bz2",
binmode => ':raw',
decoded_by_headers => 1
);
# If verification is required, get signature as well # If verification is required, get signature as well
if ($verify) { if ($verify) {
$location .= '.asc'; $location .= '.asc';
print "Fetching GPG signature $location...\n"; print "Fetching GPG signature $location...\n";
$mech->get($location); $mech->get($location);
$mech->save_content( $working."/firefox-".$version.".tar.bz2.asc", binmode => ':raw', decoded_by_headers => 1 ); $mech->save_content( $working."/firefox-".$version.".tar.bz2.asc",
binmode => ':raw',
decoded_by_headers => 1
);
} }
# If key still needs to be fetched, get it # If key still needs to be fetched, get it
if ($download_key) { if ($download_key) {
$location =~ s/linux-x86_64.*$/KEY/; $location =~ s/linux-x86_64.*$/KEY/;
print "Fetching GPG key $location...\n"; print "Fetching GPG key $location...\n";
$mech->get($location); $mech->get($location);
$mech->save_content( $working."/mozilla.pgp", binmode => ':raw', decoded_by_headers => 1 ); $mech->save_content( $working."/mozilla.pgp",
# And install it binmode => ':raw',
print "Installing Mozilla GPG key in keyring...\n"; decoded_by_headers => 1
system("gpg --import $working/mozilla.pgp 2>&1 > /dev/null"); );
if ($?) { # And install it
die "Warning: failed to import key. Cannot verify integrity.\nDownloaded to $working. You can check and install it to $install manually: $!\n"; print "Installing Mozilla GPG key in keyring...\n";
} system("gpg --import $working/mozilla.pgp 2>&1 > /dev/null");
unlink("$working/mozilla.pgp"); if ($?) {
die "Warning: failed to import key. Cannot verify integrity.\n"
. "Downloaded to "
. $working
. ". You can check and install it to "
. $install
. "manually: "
. $!
. "\n";
}
unlink("$working/mozilla.pgp");
} }
# Verify the package # Verify the package
if ($verify) { if ($verify) {
print "Verifying download with Mozilla GPG key...\n"; print "Verifying download with Mozilla GPG key...\n";
system("gpg --verify $working/firefox-$version.tar.bz2.asc"); system("gpg --verify $working/firefox-$version.tar.bz2.asc");
if ($?) { if ($?) {
die "Warning: failed to verify download. Signing failed.\nDownloaded to $working. You can check and install it to $install manually: $!\n"; die "Warning: failed to verify download. Signing failed.\n"
} . "Downloaded to "
. $working
. ". You can check and install it to "
. $install
. " manually: "
. $!
. "\n";
}
} }
# Uncompress # Uncompress
print "Uncompressing download with bunzip2...\n"; print "Uncompressing download with bunzip2...\n";
system("bunzip2 $working/firefox-$version.tar.bz2"); system("bunzip2 $working/firefox-$version.tar.bz2");
if ($?) { if ($?) {
die "Failed to uncompress: $!\n"; die "Failed to uncompress: $!\n";
} }
# Extract # Extract
print "Extracting from TAR archive...\n"; print "Extracting from TAR archive...\n";
system("tar -xf $working/firefox-$version.tar -C $working"); system("tar -xf $working/firefox-$version.tar -C $working");
if ($?) { if ($?) {
die "Failed to extract: $!\n"; die "Failed to extract: $!\n";
} }
# Bin the old backup # Bin the old backup
if (-e "$install/.firefox.old") { if (-e "$install/.firefox.old") {
print "Removing previous backup folder...\n"; print "Removing previous backup folder...\n";
system("rm -rf $install/.firefox.old"); system("rm -rf $install/.firefox.old");
if ($?) { if ($?) {
die "Failed to remove: $!\n"; die "Failed to remove: $!\n";
} }
} }
# Move current to old # Move current to old
print "Backing up currently installed version ($current) to $install/.firefox.old...\n"; print "Backing up currently installed version ("
. $current
. ") to "
. $install
. "/.firefox.old...\n";
system("mv $install/firefox $install/.firefox.old"); system("mv $install/firefox $install/.firefox.old");
if ($?) { if ($?) {
die "Failed to move: $!\n"; die "Failed to move: $!\n";
} }
# Move new to current # Move new to current
print "Moving new version to $install for final installation...\n"; print "Moving new version to $install for final installation...\n";
system("mv $working/firefox $install/"); system("mv $working/firefox $install/");
if ($?) { if ($?) {
die "Failed to move: $!\n"; die "Failed to move: $!\n";
} }
# Hurray! # Hurray!
print "Installation of version $version complete. You should restart firefox whenever it is convenient.\n"; print "Installation of version "
. $version
. " complete. You should restart firefox whenever it is convenient.\n";
exit(); exit();

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
if [ "$(pgrep -c htop)" -gt 0 ]; then if [ "$(pgrep -c htop)" -gt 0 ]; then
pkill htop pkill htop
else else
/usr/bin/uxterm -e htop /usr/bin/uxterm -e htop
fi fi

View File

@ -1,3 +1,7 @@
#!/bin/bash #!/bin/bash
notify-send -t 3000 Disks "$(lsblk -o NAME,SIZE,FSUSE%,MOUNTPOINT | grep -vP '^loop' | sed 's/MOUNTPOINT/MOUNT/' | sed -e 's/│ └─/+---/' | sed -e 's/ └─/+---/' | sed -e 's/├─/+-/' | sed -e 's/└─/+-/' | awk {'printf "%-20s %-7s %- 6s %-7s\n", $1, $2, $3, $4'})" notify-send -t 3000 Disks \
"$(lsblk -o NAME,SIZE,FSUSE%,MOUNTPOINT | grep -vP '^loop' | \
sed 's/MOUNTPOINT/MOUNT/' | sed -e 's/│ └─/+---/' | \
sed -e 's/ └─/+---/' | sed -e 's/├─/+-/' | sed -e 's/└─/+-/' | \
awk {'printf "%-20s %-7s %- 6s %-7s\n", $1, $2, $3, $4'})"

View File

@ -1,3 +1,5 @@
#!/bin/bash #!/bin/bash
notify-send 'Memory Usage' "`free -h | awk '{printf(\"%6s %6s %6s %6s\n\", $1, $2, $3, $4)}' | sed -r 's/(.*) shared$/ \1/'`" notify-send 'Memory Usage' "`free -h | \
awk '{printf(\"%6s %6s %6s %6s\n\", $1, $2, $3, $4)}' | \
sed -r 's/(.*) shared$/ \1/'`"

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
if [ "$(pgrep -c nmtui | cut -b 1)" -eq "0" ]; then if [ "$(pgrep -c nmtui | cut -b 1)" -eq "0" ]; then
echo true echo true
/usr/bin/xterm -e '/usr/bin/nmtui' /usr/bin/xterm -e '/usr/bin/nmtui'
else else
echo false echo false
pkill nmtui 2&>1 /dev/null pkill nmtui 2&>1 /dev/null
fi fi