Skip to content

Commit a6a92d1

Browse files
author
Sheoak
committed
Add missing scripts
1 parent 0e39bae commit a6a92d1

File tree

6 files changed

+237
-1
lines changed

6 files changed

+237
-1
lines changed

bin/msmtp-enqueue.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
QUEUEDIR=$HOME/.msmtpqueue
4+
5+
# Set secure permissions on created directories and files
6+
umask 077
7+
8+
# Change to queue directory (create it if necessary)
9+
if [ ! -d "$QUEUEDIR" ]; then
10+
mkdir -p "$QUEUEDIR" || exit 1
11+
fi
12+
cd "$QUEUEDIR" || exit 1
13+
14+
# Create new unique filenames of the form
15+
# MAILFILE: ccyy-mm-dd-hh.mm.ss[-x].mail
16+
# MSMTPFILE: ccyy-mm-dd-hh.mm.ss[-x].msmtp
17+
# where x is a consecutive number only appended if you send more than one
18+
# mail per second.
19+
BASE="`date +%Y-%m-%d-%H.%M.%S`"
20+
if [ -f "$BASE.mail" -o -f "$BASE.msmtp" ]; then
21+
TMP="$BASE"
22+
i=1
23+
while [ -f "$TMP-$i.mail" -o -f "$TMP-$i.msmtp" ]; do
24+
i=`expr $i + 1`
25+
done
26+
BASE="$BASE-$i"
27+
fi
28+
MAILFILE="$BASE.mail"
29+
MSMTPFILE="$BASE.msmtp"
30+
31+
# Write command line to $MSMTPFILE
32+
echo "$@" > "$MSMTPFILE" || exit 1
33+
34+
# Write the mail to $MAILFILE
35+
cat > "$MAILFILE" || exit 1
36+
37+
# If we are online, run the queue immediately.
38+
# Replace the test with something suitable for your site.
39+
ping -c 1 -w 2 bbs.archlinux.org > /dev/null
40+
if [ $? -eq 0 ]; then
41+
msmtp-runqueue.sh > /dev/null &
42+
else
43+
notify-send "[Mail] You are offline, mail will be sent later"
44+
fi
45+
46+
exit 0

bin/msmtp-listqueue.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
QUEUEDIR=$HOME/.msmtpqueue
4+
5+
for i in $QUEUEDIR/*.mail; do
6+
egrep -s --colour -h '(^From:|^To:|^Subject:)' "$i" || echo "No mail in queue";
7+
echo " "
8+
done

bin/msmtp-runqueue.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
QUEUEDIR="$HOME/.msmtpqueue"
4+
LOCKFILE="$QUEUEDIR/.lock"
5+
MAXWAIT=120
6+
7+
OPTIONS=$@
8+
9+
# wait for a lock that another instance has set
10+
WAIT=0
11+
while [ -e "$LOCKFILE" -a "$WAIT" -lt "$MAXWAIT" ]; do
12+
sleep 1
13+
WAIT="`expr "$WAIT" + 1`"
14+
done
15+
if [ -e "$LOCKFILE" ]; then
16+
echo "Cannot use $QUEUEDIR: waited $MAXWAIT seconds for"
17+
echo "lockfile $LOCKFILE to vanish, giving up."
18+
echo "If you are sure that no other instance of this script is"
19+
echo "running, then delete the lock file."
20+
notify-send -u critical "Cannot run mailqueue: lock file exists"
21+
exit 1
22+
fi
23+
24+
# change into $QUEUEDIR
25+
cd "$QUEUEDIR" || exit 1
26+
27+
# check for empty queuedir
28+
if [ "`echo *.mail`" = '*.mail' ]; then
29+
echo "No mails in $QUEUEDIR"
30+
exit 0
31+
fi
32+
33+
# lock the $QUEUEDIR
34+
touch "$LOCKFILE" || exit 1
35+
36+
# process all mails
37+
for MAILFILE in *.mail; do
38+
MSMTPFILE="`echo $MAILFILE | sed -e 's/mail/msmtp/'`"
39+
echo "*** Sending $MAILFILE to `sed -e 's/^.*-- \(.*$\)/\1/' $MSMTPFILE` ..."
40+
if [ ! -f "$MSMTPFILE" ]; then
41+
echo "No corresponding file $MSMTPFILE found" >&2
42+
echo "FAILURE" >&2
43+
notify-send -u critical "Error while running mail queue: no $MSMTPFILE found"
44+
continue
45+
fi
46+
msmtp $OPTIONS `cat "$MSMTPFILE"` < "$MAILFILE"
47+
if [ $? -eq 0 ]; then
48+
rm "$MAILFILE" "$MSMTPFILE"
49+
echo "$MAILFILE sent successfully"
50+
notify-send -t 5000 "Mail sent successfully"
51+
else
52+
echo "FAILURE" >&2
53+
notify-send -u critical "Error while running mail queue, msmtp failure."
54+
fi
55+
done
56+
57+
# remove the lock
58+
rm -f "$LOCKFILE"
59+
60+
exit 0

bin/rofi-wifi-menu

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
3+
# Starts a scan of available broadcasting SSIDs
4+
# nmcli dev wifi rescan
5+
6+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7+
SECURITY=0
8+
9+
if [ ! -r "$DIR/config" ]; then
10+
echo "WARNING: config file not found! Using default values."
11+
FIELDS=SSID,SECURITY,BARS
12+
ROFI_OPTS=
13+
elif [ -r "$DIR/config" ]; then
14+
# Get values from config
15+
source $DIR/config
16+
fi
17+
18+
LIST=$(nmcli --fields "$FIELDS" device wifi list | sed '/^--/d')
19+
# For some reason rofi always approximates character width 2 short... hmmm
20+
RWIDTH=$(($(echo "$LIST" | head -n 1 | awk '{print length($0); }')+2))
21+
# Dynamically change the height of the rofi menu
22+
LINENUM=$(echo "$LIST" | wc -l)
23+
let LINENUM+=2
24+
25+
# Gives a list of known connections so we can parse it later
26+
KNOWNCON=$(nmcli connection show)
27+
# telling if there is currently a connection (enabled or disabled)
28+
CONSTATE=$(nmcli r wifi)
29+
30+
CURRSSID=$(iwgetid -r)
31+
32+
33+
if [[ ! -z $CURRSSID ]]; then
34+
HIGHLINE=$(echo "$(echo "$LIST" | awk -F "[ ]{2,}" '{print $1}' | grep -Fxn -m 1 "$CURRSSID" | awk -F ":" '{print $1}') + 1" | bc )
35+
fi
36+
37+
# HOPEFULLY you won't need this as often as I do
38+
# If there are more than 8 SSIDs, the menu will still only have 8 lines
39+
if [ "$LINENUM" -gt 8 ] && [[ "$CONSTATE" =~ "enabled" ]]; then
40+
LINENUM=8
41+
elif [[ "$CONSTATE" =~ "disabled" ]]; then
42+
LINENUM=1
43+
fi
44+
45+
if [[ "$CONSTATE" =~ "enabled" ]]; then
46+
TOGGLE="toggle off"
47+
elif [[ "$CONSTATE" =~ "disabled" ]]; then
48+
TOGGLE="toggle on"
49+
fi
50+
51+
52+
CHENTRY=$(echo -e "$TOGGLE\nmanual\n$LIST" | uniq -u | rofi -dmenu -p "Wi-Fi SSID: " -lines "$LINENUM" -a "$HIGHLINE" $ROFI_OPTS -width -"$RWIDTH")
53+
CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $1}')
54+
55+
if [[ -z $CHENTRY ]]; then
56+
exit;
57+
fi
58+
59+
# If the user inputs "manual" as their SSID in the start window, it will bring them to this screen
60+
if [ "$CHENTRY" = "manual" ] ; then
61+
# Manual entry of the SSID and password (if appplicable)
62+
MSSID=$(echo "enter the SSID of the network (SSID,password)" | rofi -dmenu -p "Manual Entry: " -lines 1 $ROFI_OPTS)
63+
# Separating the password from the entered string
64+
MPASS=$(echo "$MSSID" | awk -F "," '{print $2}')
65+
66+
if [[ -z $MSSID ]]; then
67+
exit;
68+
fi
69+
70+
# FIXME: connexion logic duplicated, merge with bottom lines
71+
# If the user entered a manual password, then use the password nmcli command
72+
if [ "$MPASS" = "" ]; then
73+
nmcli dev wifi con "$MSSID"
74+
else
75+
nmcli dev wifi con "$MSSID" password "$MPASS"
76+
fi
77+
78+
elif [ "$CHENTRY" = "toggle on" ]; then
79+
nmcli radio wifi on
80+
81+
elif [ "$CHENTRY" = "toggle off" ]; then
82+
nmcli radio wifi off
83+
84+
else
85+
86+
# If the connection is already in use, then this will still be able to get the SSID
87+
if [ "$CHSSID" = "*" ]; then
88+
CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $3}')
89+
fi
90+
91+
# Parses the list of preconfigured connections to see if it already contains the chosen SSID. This speeds up the connection process
92+
# FIXME: not always working
93+
if [[ $(echo "$KNOWNCON" | grep "$CHSSID") = "$CHSSID" ]]; then
94+
nmcli con up "$CHSSID"
95+
else
96+
if [[ "$CHENTRY" =~ "WPA1" ]] || [[ "$CHENTRY" =~ "WPA2" ]] || [[ "$CHENTRY" =~ "WEP" ]]; then
97+
SECURITY=1
98+
WIFIPASS=$(rofi -dmenu -no-fixed-num-lines -p "password: " -mesg "if connection is stored, hit enter" $ROFI_OPTS)
99+
fi
100+
101+
# FIXME: merge with previous code one fixed
102+
if [[ -z $WIFIPASS ]] && [[ $SECURITY ]]; then
103+
# network regitered already, force connection
104+
nmcli con up id "$CHSSID"
105+
else
106+
# connect and store the network
107+
nmcli dev wifi con "$CHSSID" password "$WIFIPASS"
108+
fi
109+
nmcli dev wifi con "$CHSSID" password "$WIFIPASS"
110+
fi
111+
112+
fi

bin/sway-start

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export TERMINAL=kitty
66
export WLC_REPEAT_DELAY=270
77
export WLC_REPEAT_RATE=52
88

9-
sway
9+
sway -dV

bin/trackpad-toggle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
device='ELAN1201:00 04F3:3098 Touchpad'
4+
state=$(xinput list-props "$device" | grep "Device Enabled" | grep -o "[01]$")
5+
6+
if [ $state == '1' ];then
7+
xinput --disable "$device"
8+
else
9+
xinput --enable "$device"
10+
fi

0 commit comments

Comments
 (0)