From 7e48c8f75a6d1caa313b19883fc749e925412117 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Fri, 16 Sep 2022 20:08:03 +0300 Subject: [PATCH] Removed some old/unneeded shell scripts and formatted the rest --- .husky/pre-commit | 16 +-- efistub/update.sh | 4 +- root/etc/clamav/detected.sh | 24 ++-- scripts/autorotate.sh | 32 ++--- scripts/confgen/termite.conf.gen.sh | 26 ---- scripts/confgen/zathura.conf.gen.sh | 40 ------ scripts/hibernate-lowbattery.sh | 10 +- scripts/ipmi/auto.sh | 9 -- scripts/ipmi/fans.sh | 17 --- scripts/ipmi/full.sh | 10 -- scripts/ipmi/static.sh | 10 -- scripts/ipmi/temp.sh | 19 --- scripts/mail/notify-new-mail.sh | 15 ++- scripts/open_with_linux.py | 186 ---------------------------- secrets/secrets.sh | 2 +- 15 files changed, 51 insertions(+), 369 deletions(-) delete mode 100755 scripts/confgen/termite.conf.gen.sh delete mode 100755 scripts/confgen/zathura.conf.gen.sh delete mode 100755 scripts/ipmi/auto.sh delete mode 100755 scripts/ipmi/fans.sh delete mode 100755 scripts/ipmi/full.sh delete mode 100755 scripts/ipmi/static.sh delete mode 100755 scripts/ipmi/temp.sh delete mode 100755 scripts/open_with_linux.py diff --git a/.husky/pre-commit b/.husky/pre-commit index 25bf921..13224a4 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -31,14 +31,14 @@ if [ "$num_staged_lua" -gt 0 ]; then fi # Run shfmt on staged shell scripts -staged_sh=$(echo "$staged_files" | grep -E '(.sh$|pre-commit)' || true) -num_staged_sh=$(echo "$staged_sh" | grep -vce '^$' || true) -if [ "$num_staged_sh" -gt 0 ]; then - printf '\nFormatting %s staged shell scripts with shfmt\n' "$num_staged_sh" - shfmt -w "$staged_sh" - printf "Re-staging\n\n" - git add "$staged_sh" -fi +#staged_sh=$(echo "$staged_files" | grep -E '(.sh$|pre-commit)' || true) +#num_staged_sh=$(echo "$staged_sh" | grep -vce '^$' || true) +#if [ "$num_staged_sh" -gt 0 ]; then +# printf '\nFormatting %s staged shell scripts with shfmt\n' "$num_staged_sh" +# shfmt -w "$staged_sh" +# printf "Re-staging\n\n" +# git add "$staged_sh" +#fi # Run prettier on all other staged files # that are supported diff --git a/efistub/update.sh b/efistub/update.sh index 19a17d8..448eefd 100755 --- a/efistub/update.sh +++ b/efistub/update.sh @@ -2,12 +2,12 @@ # remove old entries for bootentry in $(efibootmgr | head -n 3 | tail -n 1 | cut -d' ' -f2- | sed 's/,/\n/g'); do - sudo efibootmgr -qBb $bootentry + sudo efibootmgr -qBb $bootentry done # add all entries back for bootscript in *.efi; do - ./$bootscript + ./$bootscript done # set bootorder diff --git a/root/etc/clamav/detected.sh b/root/etc/clamav/detected.sh index 6f3f1f9..4d15efc 100755 --- a/root/etc/clamav/detected.sh +++ b/root/etc/clamav/detected.sh @@ -5,22 +5,22 @@ alert="Signature detected: $CLAM_VIRUSEVENT_VIRUSNAME in $CLAM_VIRUSEVENT_FILENA # Send the alert to systemd logger if exist, othewise to /var/log if [[ -z $(command -v systemd-cat) ]]; then - echo "$(date) - $alert" >> /var/log/clamav/infected.log + echo "$(date) - $alert" >>/var/log/clamav/infected.log else - # as "emerg", this could cause your DE to show a visual alert. Happen in Plasma. but the next visual alert is much nicer - echo "$alert" | /usr/bin/systemd-cat -t clamav -p emerg + # as "emerg", this could cause your DE to show a visual alert. Happen in Plasma. but the next visual alert is much nicer + echo "$alert" | /usr/bin/systemd-cat -t clamav -p emerg fi #send an alrt to all graphical user -XUSERS=($(who|awk '{print $1}'|sort -u)) +XUSERS=($(who | awk '{print $1}' | sort -u)) for XUSER in $XUSERS; do - NAME=(${XUSER/(/ }) - DISPLAY=${NAME[1]/)/} - DBUS_ADDRESS=unix:path=/run/user/$(id -u ${NAME[0]})/bus - echo "run $NAME - $DISPLAY - $DBUS_ADDRESS -" >> /tmp/testlog - /usr/bin/sudo -u ${NAME[0]} DISPLAY=${DISPLAY} \ - DBUS_SESSION_BUS_ADDRESS=${DBUS_ADDRESS} \ - PATH=${PATH} \ - /usr/bin/notify-send -i dialog-warning "clamAV" "$alert" + NAME=(${XUSER/(/ }) + DISPLAY=${NAME[1]/)/} + DBUS_ADDRESS=unix:path=/run/user/$(id -u ${NAME[0]})/bus + echo "run $NAME - $DISPLAY - $DBUS_ADDRESS -" >>/tmp/testlog + /usr/bin/sudo -u ${NAME[0]} DISPLAY=${DISPLAY} \ + DBUS_SESSION_BUS_ADDRESS=${DBUS_ADDRESS} \ + PATH=${PATH} \ + /usr/bin/notify-send -i dialog-warning "clamAV" "$alert" done diff --git a/scripts/autorotate.sh b/scripts/autorotate.sh index 97cb94b..c4f6f67 100755 --- a/scripts/autorotate.sh +++ b/scripts/autorotate.sh @@ -1,22 +1,22 @@ #!/bin/bash function rotate_ms { - case $1 in - "normal") - swaymsg output eDP-1 transform 0 - ;; - "right-up") - swaymsg output eDP-1 transform 90 - ;; - "bottom-up") - swaymsg output eDP-1 transform 180 - ;; - "left-up") - swaymsg output eDP-1 transform 270 - ;; - esac + case $1 in + "normal") + swaymsg output eDP-1 transform 0 + ;; + "right-up") + swaymsg output eDP-1 transform 90 + ;; + "bottom-up") + swaymsg output eDP-1 transform 180 + ;; + "left-up") + swaymsg output eDP-1 transform 270 + ;; + esac } while IFS='$\n' read -r line; do - rotation="$(echo $line | sed -En "s/^.*orientation changed: (.*)/\1/p")" - [[ ! -z $rotation ]] && rotate_ms $rotation + rotation="$(echo $line | sed -En "s/^.*orientation changed: (.*)/\1/p")" + [[ ! -z $rotation ]] && rotate_ms $rotation done < <(stdbuf -oL monitor-sensor) diff --git a/scripts/confgen/termite.conf.gen.sh b/scripts/confgen/termite.conf.gen.sh deleted file mode 100755 index 415d887..0000000 --- a/scripts/confgen/termite.conf.gen.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -source ~/.cache/wal/colors.sh -echo "[colors] -foreground = $foreground -background = $background -color0 = $color0 -color1 = $color1 -color2 = $color2 -color3 = $color3 -color4 = $color4 -color5 = $color5 -color6 = $color6 -color7 = $color7 -color8 = $color8 -color9 = $color9 -color10 = $color10 -color11 = $color11 -color12 = $color12 -color13 = $color13 -color14 = $color14 -color15 = $color15 - -[options] -font = Noto Color Emoji 12 -font = Material Design Icons 12 -font = Hack Nerd Font 12" > ~/.config/termite/config diff --git a/scripts/confgen/zathura.conf.gen.sh b/scripts/confgen/zathura.conf.gen.sh deleted file mode 100755 index 68b1584..0000000 --- a/scripts/confgen/zathura.conf.gen.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh - -# Generates zathura configuration file with pywal colors - -. $HOME/.cache/wal/colors.sh - -cat < ~/.config/zathura/zathurarc -set completion-bg "$background" -set recolor-darkcolor "$foreground" -set recolor-lightcolor "$background" -set completion-fg "$foreground" -set completion-group-bg "$background" -set completion-group-fg "$color2" -set completion-highlight-bg "$foreground" -set completion-highlight-fg "$background" -set default-bg "$background" -set default-fg "$foreground" -set inputbar-bg "$background" -set inputbar-fg "$foreground" -set notification-bg "$background" -set notification-fg "$foreground" -set notification-error-bg "$color1" -set notification-error-fg "$foreground" -set notification-warning-bg "$color1" -set notification-warning-fg "$foreground" -set statusbar-bg "$background" -set statusbar-fg "$foreground" -set index-bg "$background" -set index-fg "$foreground" -set index-active-bg "$foreground" -set index-active-fg "$background" -set render-loading-bg "$background" -set render-loading-fg "$foreground" - -set smooth-scroll true -set window-title-home-tilde true -set statusbar-basename true -set selection-clipboard clipboard -set recolor false -CONF diff --git a/scripts/hibernate-lowbattery.sh b/scripts/hibernate-lowbattery.sh index d98df47..71fb0d1 100755 --- a/scripts/hibernate-lowbattery.sh +++ b/scripts/hibernate-lowbattery.sh @@ -1,9 +1,9 @@ #!/bin/sh acpi -b | awk -F'[,:%]' '{print $2, $3}' | { - read -r status capacity + read -r status capacity - if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then - logger "Critical battery threshold" - systemctl hibernate - fi + if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then + logger "Critical battery threshold" + systemctl hibernate + fi } diff --git a/scripts/ipmi/auto.sh b/scripts/ipmi/auto.sh deleted file mode 100755 index 60b7518..0000000 --- a/scripts/ipmi/auto.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -IPMIHOST=10.0.0.82 -IPMIUSER=ReekyMarko -IPMIPW={{@@ env['PASS_IPMI'] @@}} -IPMIEK=0000000000000000000000000000000000000000 - -printf "Activating dynamic fan control." -ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW -y $IPMIEK raw 0x30 0x30 0x01 0x01 diff --git a/scripts/ipmi/fans.sh b/scripts/ipmi/fans.sh deleted file mode 100755 index c23b4a6..0000000 --- a/scripts/ipmi/fans.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -IPMIHOST=10.0.0.82 -IPMIUSER=ReekyMarko -IPMIPW={{@@ env['PASS_IPMI'] @@}} -IPMIEK=0000000000000000000000000000000000000000 - -DATA=`ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW -y $IPMIEK sdr get "FAN 1 RPM" "FAN 2 RPM" "FAN 3 RPM" "FAN 4 RPM" "FAN 5 RPM" "FAN 6 RPM" | grep "Sensor Reading" | awk '{ print $4 }'` - -echo "$DATA" - -mosquitto_pub -u reekynet -P {{@@ env['PASS_MQTT'] @@}} -t "ipmi/fan1" -m "$(echo "$DATA" | head -1 | tail -1)" -mosquitto_pub -u reekynet -P {{@@ env['PASS_MQTT'] @@}} -t "ipmi/fan2" -m "$(echo "$DATA" | head -2 | tail -1)" -mosquitto_pub -u reekynet -P {{@@ env['PASS_MQTT'] @@}} -t "ipmi/fan3" -m "$(echo "$DATA" | head -3 | tail -1)" -mosquitto_pub -u reekynet -P {{@@ env['PASS_MQTT'] @@}} -t "ipmi/fan4" -m "$(echo "$DATA" | head -4 | tail -1)" -mosquitto_pub -u reekynet -P {{@@ env['PASS_MQTT'] @@}} -t "ipmi/fan5" -m "$(echo "$DATA" | head -5 | tail -1)" -mosquitto_pub -u reekynet -P {{@@ env['PASS_MQTT'] @@}} -t "ipmi/fan6" -m "$(echo "$DATA" | head -6 | tail -1)" diff --git a/scripts/ipmi/full.sh b/scripts/ipmi/full.sh deleted file mode 100755 index 8218be9..0000000 --- a/scripts/ipmi/full.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -IPMIHOST=10.0.0.82 -IPMIUSER=ReekyMarko -IPMIPW={{@@ env['PASS_IPMI'] @@}} -IPMIEK=0000000000000000000000000000000000000000 - -printf "speeeed!" -ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW -y $IPMIEK raw 0x30 0x30 0x01 0x00 -ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW -y $IPMIEK raw 0x30 0x30 0x02 0xff 0x64 diff --git a/scripts/ipmi/static.sh b/scripts/ipmi/static.sh deleted file mode 100755 index cc4bc50..0000000 --- a/scripts/ipmi/static.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -IPMIHOST=10.0.0.82 -IPMIUSER=ReekyMarko -IPMIPW={{@@ env['PASS_IPMI'] @@}} -IPMIEK=0000000000000000000000000000000000000000 - -printf "Activating manual fan speeds! (2160 RPM)" -ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW -y $IPMIEK raw 0x30 0x30 0x01 0x00 -ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW -y $IPMIEK raw 0x30 0x30 0x02 0xff 0x10 diff --git a/scripts/ipmi/temp.sh b/scripts/ipmi/temp.sh deleted file mode 100755 index b468b76..0000000 --- a/scripts/ipmi/temp.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -IPMIHOST=10.0.0.82 -IPMIUSER=ReekyMarko -IPMIPW={{@@ env['PASS_IPMI'] @@}} -IPMIEK=0000000000000000000000000000000000000000 -MAXTEMP=27 -TEMP=$(ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW -y $IPMIEK sdr type temperature |grep Ambient |grep degrees |grep -Po '\d{2}' | tail -1) - -mosquitto_pub -u reekynet -P {{@@ env['PASS_MQTT'] @@}} -t "ipmi/temp" -m "$TEMP" - - -if [[ $TEMP > $MAXTEMP ]]; - then - printf "Warning: Temperature is too high! Activating dynamic fan control! ($TEMP C)" - ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW -y $IPMIEK raw 0x30 0x30 0x01 0x01 - else - printf "Temperature is OK ($TEMP C)" -fi diff --git a/scripts/mail/notify-new-mail.sh b/scripts/mail/notify-new-mail.sh index 298d6b3..a4d2f30 100755 --- a/scripts/mail/notify-new-mail.sh +++ b/scripts/mail/notify-new-mail.sh @@ -5,20 +5,19 @@ COUNT=$(ls $NEWMAILDIR | wc -l) ICON=/usr/share/icons/Papirus-Dark/64x64/apps/email.svg SOUND=/usr/share/sounds/Oxygen-Im-Message-In.ogg - if [ $COUNT -ne 0 ]; then - mpv $SOUND & + mpv $SOUND & fi if [ $COUNT -gt 1 ]; then - fromaddress=$(cat $NEWMAILDIR/$(ls $NEWMAILDIR | sort -R | tail -1) | formail -x From | tail -1) - notify-send.sh -i $ICON "$COUNT new messages in $1" "From $fromaddress and others" + fromaddress=$(cat $NEWMAILDIR/$(ls $NEWMAILDIR | sort -R | tail -1) | formail -x From | tail -1) + notify-send.sh -i $ICON "$COUNT new messages in $1" "From $fromaddress and others" elif [ $COUNT -eq 1 ]; then - mailsubject=$(cat $NEWMAILDIR/* | formail -x Subject) - fromaddress=$(cat $NEWMAILDIR/* | formail -x From | tail -1) + mailsubject=$(cat $NEWMAILDIR/* | formail -x Subject) + fromaddress=$(cat $NEWMAILDIR/* | formail -x From | tail -1) - notify-send.sh -i $ICON "New message in $1" "$fromaddress $mailsubject" + notify-send.sh -i $ICON "New message in $1" "$fromaddress $mailsubject" else - echo "No new mail" + echo "No new mail" fi diff --git a/scripts/open_with_linux.py b/scripts/open_with_linux.py deleted file mode 100755 index 6a4f979..0000000 --- a/scripts/open_with_linux.py +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env python -from __future__ import print_function - -import os -import sys -import json -import struct -import subprocess - -VERSION = '7.2.2' - -try: - sys.stdin.buffer - - # Python 3.x version - # Read a message from stdin and decode it. - def getMessage(): - rawLength = sys.stdin.buffer.read(4) - if len(rawLength) == 0: - sys.exit(0) - messageLength = struct.unpack('@I', rawLength)[0] - message = sys.stdin.buffer.read(messageLength).decode('utf-8') - return json.loads(message) - - # Send an encoded message to stdout - def sendMessage(messageContent): - encodedContent = json.dumps(messageContent).encode('utf-8') - encodedLength = struct.pack('@I', len(encodedContent)) - - sys.stdout.buffer.write(encodedLength) - sys.stdout.buffer.write(encodedContent) - sys.stdout.buffer.flush() - -except AttributeError: - # Python 2.x version (if sys.stdin.buffer is not defined) - # Read a message from stdin and decode it. - def getMessage(): - rawLength = sys.stdin.read(4) - if len(rawLength) == 0: - sys.exit(0) - messageLength = struct.unpack('@I', rawLength)[0] - message = sys.stdin.read(messageLength) - return json.loads(message) - - # Send an encoded message to stdout - def sendMessage(messageContent): - encodedContent = json.dumps(messageContent) - encodedLength = struct.pack('@I', len(encodedContent)) - - sys.stdout.write(encodedLength) - sys.stdout.write(encodedContent) - sys.stdout.flush() - - -def install(): - home_path = os.getenv('HOME') - - manifest = { - 'name': 'open_with', - 'description': 'Open With native host', - 'path': os.path.realpath(__file__), - 'type': 'stdio', - } - locations = { - 'chrome': os.path.join(home_path, '.config', 'google-chrome', 'NativeMessagingHosts'), - 'chrome-beta': os.path.join(home_path, '.config', 'google-chrome-beta', 'NativeMessagingHosts'), - 'chrome-unstable': os.path.join(home_path, '.config', 'google-chrome-unstable', 'NativeMessagingHosts'), - 'chromium': os.path.join(home_path, '.config', 'chromium', 'NativeMessagingHosts'), - 'firefox': os.path.join(home_path, '.mozilla', 'native-messaging-hosts'), - } - filename = 'open_with.json' - - for browser, location in locations.items(): - if os.path.exists(os.path.dirname(location)): - if not os.path.exists(location): - os.mkdir(location) - - browser_manifest = manifest.copy() - if browser == 'firefox': - browser_manifest['allowed_extensions'] = ['openwith@darktrojan.net'] - else: - browser_manifest['allowed_origins'] = [ - 'chrome-extension://cogjlncmljjnjpbgppagklanlcbchlno/', # Chrome - 'chrome-extension://fbmcaggceafhobjkhnaakhgfmdaadhhg/', # Opera - ] - - with open(os.path.join(location, filename), 'w') as file: - file.write( - json.dumps(browser_manifest, indent=2, separators=(',', ': '), sort_keys=True).replace(' ', '\t') + '\n' - ) - - -def _read_desktop_file(path): - with open(path, 'r') as desktop_file: - current_section = None - name = None - command = None - for line in desktop_file: - if line[0] == '[': - current_section = line[1:-2] - if current_section != 'Desktop Entry': - continue - - if line.startswith('Name='): - name = line[5:].strip() - elif line.startswith('Exec='): - command = line[5:].strip() - - return { - 'name': name, - 'command': command - } - - -def find_browsers(): - apps = [ - 'Chrome', - 'Chromium', - 'chromium-browser', - 'firefox', - 'Firefox', - 'Google Chrome', - 'google-chrome', - 'opera', - 'Opera', - 'SeaMonkey', - 'seamonkey', - ] - paths = [ - os.path.join(os.getenv('HOME'), '.local/share/applications'), - '/usr/local/share/applications', - '/usr/share/applications' - ] - suffix = '.desktop' - - results = [] - for p in paths: - for a in apps: - fp = os.path.join(p, a) + suffix - if os.path.exists(fp): - results.append(_read_desktop_file(fp)) - return results - - -def listen(): - receivedMessage = getMessage() - if receivedMessage == 'ping': - sendMessage({ - 'version': VERSION, - 'file': os.path.realpath(__file__) - }) - elif receivedMessage == 'find': - sendMessage(find_browsers()) - else: - for k, v in os.environ.items(): - if k.startswith('MOZ_'): - try: - os.unsetenv(k) - except: - os.environ[k] = '' - - devnull = open(os.devnull, 'w') - subprocess.Popen(receivedMessage, stdout=devnull, stderr=devnull) - sendMessage(None) - - -if __name__ == '__main__': - if len(sys.argv) == 2: - if sys.argv[1] == 'install': - install() - sys.exit(0) - elif sys.argv[1] == 'find_browsers': - print(find_browsers()) - sys.exit(0) - - allowed_extensions = [ - 'openwith@darktrojan.net', - 'chrome-extension://cogjlncmljjnjpbgppagklanlcbchlno/', - 'chrome-extension://fbmcaggceafhobjkhnaakhgfmdaadhhg/', - ] - for ae in allowed_extensions: - if ae in sys.argv: - listen() - sys.exit(0) - - print('Open With native helper, version %s.' % VERSION) diff --git a/secrets/secrets.sh b/secrets/secrets.sh index 43691bf..2232d5e 100755 --- a/secrets/secrets.sh +++ b/secrets/secrets.sh @@ -2,7 +2,7 @@ source $DOTREPO/secrets/env -cat < $DOTREPO/secrets/secrets +cat <$DOTREPO/secrets/secrets export PASS_LIBREFM="$PASS_LIBREFM" export PASS_MUSICBRAINZ="$PASS_MUSICBRAINZ" export PASS_LISTENBRAINZ="$PASS_LISTENBRAINZ"