Working on neomutt setup and some other small fixes

This commit is contained in:
Marko Korhonen 2020-11-25 10:06:19 +02:00
parent ef6050fed3
commit a38b58d91a
No known key found for this signature in database
GPG key ID: 911B85FBC6003FE5
36 changed files with 152 additions and 155 deletions

22
scripts/autorotate.sh Executable file
View file

@ -0,0 +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
}
while IFS='$\n' read -r line; do
rotation="$(echo $line | sed -En "s/^.*orientation changed: (.*)/\1/p")"
[[ ! -z $rotation ]] && rotate_ms $rotation
done < <(stdbuf -oL monitor-sensor)

View file

@ -0,0 +1,26 @@
#!/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

View file

@ -0,0 +1,40 @@
#!/bin/sh
# Generates zathura configuration file with pywal colors
. $HOME/.cache/wal/colors.sh
cat <<CONF > ~/.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

View file

@ -0,0 +1,9 @@
#!/bin/sh
acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
read -r status capacity
if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
logger "Critical battery threshold"
systemctl hibernate
fi
}

9
scripts/ipmi/auto.sh Executable file
View file

@ -0,0 +1,9 @@
#!/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

17
scripts/ipmi/fans.sh Executable file
View file

@ -0,0 +1,17 @@
#!/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)"

10
scripts/ipmi/full.sh Executable file
View file

@ -0,0 +1,10 @@
#!/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

10
scripts/ipmi/static.sh Executable file
View file

@ -0,0 +1,10 @@
#!/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

19
scripts/ipmi/temp.sh Executable file
View file

@ -0,0 +1,19 @@
#!/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

24
scripts/mail/notify-new-mail.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
NEWMAILDIR=~/.mail/$1/INBOX/new
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 &
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"
elif [ $COUNT -eq 1 ]; then
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"
else
echo "No new mail"
fi

29
scripts/media/imageviewer Executable file
View file

@ -0,0 +1,29 @@
#!/bin/bash
if [ $# -eq 1 ]; then
DIR=/tmp/images
IMGNAME=$(basename $1)
if [ ! -d $DIR ]; then
mkdir $DIR
fi
if [ ! -f $DIR/$IMGNAME ]; then
wget $1 -O $DIR/$IMGNAME
fi
mimeo $DIR/$IMGNAME
else
DIR=/tmp/images/$(basename $1)
if [ ! -d $]; then
mkdir -p $DIR
fi
if [ ! -f $DIR/$IMGNAME ]; then
wget -P $DIR $@
fi
mimeo $DIR/*
fi

11
scripts/media/imgurviewer Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
ALBUMNAME=$(basename $1)
ALBUMDIR=/tmp/imgur/$ALBUMNAME
if [ ! -d $ALBUMDIR ]; then
mkdir -p $ALBUMDIR
imgur-album-downloader $1 $ALBUMDIR
fi
mimeo $ALBUMDIR

30
scripts/media/mpvqueue Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
MPVPIPE=/tmp/mpvqueue.playlist
notify="notify-send -i mpv -a mpv"
url="$1"
# See if MPV is already running
if [ -z "$(pidof mpv)" ]; then
# mpv is not running
# remove fifo
rm -f $MPVPIPE && mkfifo $MPVPIPE
# pause other players
playerctl pause
# start mpv
/usr/bin/mpv --no-terminal --input-file="${MPVPIPE}" "$url" & disown
# Wait for mpv to be up before moving on to adding anything else to playlist
while [ -z "$(pidof mpv)" ]; do
sleep 1
done
$notify "Playing $url"
else
# mpv is running, so add stuff to playlist
$notify "Adding $url"
echo "loadfile \"$url\" append-play" >> "${MPVPIPE}"
fi

186
scripts/open_with_linux.py Executable file
View file

@ -0,0 +1,186 @@
#!/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)