diff options
| author | subh <subh@subh.space> | 2026-04-03 14:47:03 +0530 |
|---|---|---|
| committer | subh <subh@subh.space> | 2026-04-03 14:47:03 +0530 |
| commit | 314d760de1922128124f2a9be0494fd4f6f7effb (patch) | |
| tree | 3f4bb374fc89be2b1cd4e2a0a21ae17d4bf83452 /scripts | |
| parent | 0203dd4b8d45c663356f797c11be17fdec6f22f2 (diff) | |
new music bar, auto usb mounting and more
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/mount-usb.sh | 109 | ||||
| -rwxr-xr-x | scripts/umount-usb.sh | 22 | ||||
| -rwxr-xr-x | scripts/weather.py | 36 |
3 files changed, 149 insertions, 18 deletions
diff --git a/scripts/mount-usb.sh b/scripts/mount-usb.sh new file mode 100755 index 0000000..ae53a14 --- /dev/null +++ b/scripts/mount-usb.sh @@ -0,0 +1,109 @@ +#!/bin/bash + +IFS=' +' +lsblkoutput="$(lsblk -rpo "uuid,name,type,size,label,mountpoint,fstype")" +allluks="$(echo "$lsblkoutput" | grep crypto_LUKS)" + +decrypted="$(find /dev/disk/by-id/dm-uuid-CRYPT-LUKS2-* 2>/dev/null | sed "s|.*LUKS2-||;s|-.*||")" + +filter() { sed "s/ /:/g" | awk -F':' '$7==""{printf "%s%s (%s) %s\n", $1,$3,$5,$6}'; } + +unopenedluks="$(for drive in $allluks; do + uuid="${drive%% *}" + uuid="${uuid//-}" + [ -n "$decrypted" ] && for open in $decrypted; do + [ "$uuid" = "$open" ] && break 1 + done && continue 1 + echo "๐ $drive" +done | filter)" + +normalparts="$(echo "$lsblkoutput" | grep -v crypto_LUKS | grep 'part\|rom\|crypt' | sed "s/^/๐พ /" | filter)" + +alldrives="$(echo "$unopenedluks +$normalparts" | sed "/^$/d;s/ *$//")" + +set -e +test -n "$alldrives" + +chosen="$(echo "$alldrives" | rofi -dmenu -p "Mount which drive?")" + +getmount() { + mp="$(find /mnt /media /mount /home -maxdepth 1 -type d 2>/dev/null | rofi -dmenu -p "Mount this drive where?")" + test -n "$mp" + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\nYes" | rofi -dmenu -p "$mp does not exist. Create it?") + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo mkdir -p "$mp") + fi +} + + +attemptmount() { + sudo mount "$chosen" || return 1 + notify-send "๐พ Drive mounted." "$chosen mounted." + exit +} + +case "$chosen" in + ๐พ*) + chosen="${chosen%% *}" + chosen="${chosen:1}" + parttype="$(echo "$lsblkoutput" | grep "$chosen")" + attemptmount || getmount + + case "${parttype##* }" in + vfat) sudo mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;; + btrfs) sudo mount "$chosen" "$mp" ;; + *) sudo mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)" ;; + esac + notify-send "๐พ Drive Mounted." "$chosen mounted to $mp" + ;; + + ๐*) + chosen="${chosen%% *}" + chosen="${chosen:1}" + + num="00" + while true; do + [ -b "/dev/mapper/usb$num" ] || break + num="$(printf "%02d" "$((10#$num + 1))")" + done + + MAPPER="$usb$num" + + ${TERMINAL:-st} -n floatpattern -g 60x1 -e sudo cryptsetup open "$chosen" "$MAPPER" + + if ! test -b "/dev/mapper/$MAPPER"; then + notify-send "โ Decryption Failed" "Could not open $chosen" + exit 1 + fi + + FSTYPE="$(blkid -o value -s TYPE "/dev/mapper/$MAPPER" 2>/dev/null)" + + getmount + + case "$FSTYPE" in + vfat|exfat) + sudo mount -t "$FSTYPE" "/dev/mapper/$MAPPER" "$mp" -o uid="$(id -u)",gid="$(id -g)",umask=022 + ;; + ntfs|ntfs-3g) + sudo mount -t ntfs-3g "/dev/mapper/$MAPPER" "$mp" -o uid="$(id -u)",gid="$(id -g)" + ;; + ext2|ext3|ext4|btrfs|xfs) + sudo mount -t "$FSTYPE" "/dev/mapper/$MAPPER" "$mp" + ;; + *) + sudo mount "/dev/mapper/$MAPPER" "$mp" + esac + + + if mountpoint -q "$mp"; then + notify-send "๐ Decrypted Drive Mounted." "$chosen mounted to $mp" + else + notify-send "โ Mount failed." "Could not mount /dev/mapper/$MAPPER to $mp." + sudo cryptsetup close "$MAPPER" + fi + + ;; +esac + diff --git a/scripts/umount-usb.sh b/scripts/umount-usb.sh new file mode 100755 index 0000000..e745ef2 --- /dev/null +++ b/scripts/umount-usb.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +lsblkoutput="$(lsblk -nrpo "name,type,size,mountpoint")" +mounteddrives="$(echo "$lsblkoutput" | awk '($2=="part"||$2="crypt")&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}')" + +allunmountable="$(echo "$mounteddrives" | sed "/^$/d;s/ *$//")" +test -n "$allunmountable" + +chosen="$(echo "$allunmountable" | rofi -dmenu -p "Unmount which drive?")" +chosen="${chosen%% *}" +test -n "$chosen" + +sudo umount -l "/${chosen#*/}" +notify-send "๐พ Device unmounted." "$chosen has been unmounted" + +cryptid="$(echo "$lsblkoutput" | grep "/${chosen#*/}$")" +cryptid="${cryptid%% *}" +test -b /dev/mapper/"${cryptid##*/}" +sudo cryptsetup close "$cryptid" +notify-send "๐ Device dencryption closed." "Drive is now securely locked again." diff --git a/scripts/weather.py b/scripts/weather.py index 0c2af7b..27395a9 100755 --- a/scripts/weather.py +++ b/scripts/weather.py @@ -6,41 +6,41 @@ import json from dotenv import load_dotenv def getWeatherIcon(isDayTime: bool, weatherDescription: str): - if weatherDescription in ["CLEAR", "MOSTLY_CLEAR"]: + if weatherDescription in ["CLEAR"]: if isDayTime: - return "๏ข " + return "โ๏ธ" else: - return "๏ " - if weatherDescription in ["PARTLY_CLOUDY"]: + return "๐ " + if weatherDescription in ["PARTLY_CLOUDY", "MOSTLY_CLEAR"]: if isDayTime: - return "๎ปฐ " + return "โ
" else: return "๎ปฏ " if weatherDescription in ["CLOUDY", "MOSTLY_CLOUDY"]: - return "๏ " + return "โ๏ธ" if weatherDescription in ["LIGHT_RAIN", "LIGHT_TO_MODERATE_RAIN","LIGHT_RAIN_SHOWERS"]: if isDayTime: - return "๎ผ " + return "๐ฆ๏ธ" else: return "๎ผ " if weatherDescription in ["RAIN", "RAIN_SHOWERS", "HEAVY_RAIN", "HEAVY_RAIN_SHOWERS", "MODERATE_TO_HEAVY_RAIN", "RAIN_PERIODICALLY_HEAVY"]: - return "๎น " + return "๐ง๏ธ" if weatherDescription in ["SNOW", "LIGHT_SNOW", "HEAVY_SNOW", "SNOW_SHOWERS", "LIGHT_SNOW_SHOWERS", "HEAVY_SNOW_SHOWERS", "SNOWSTORM", "BLOWING_SNOW", "RAIN_AND_SNOW", "HAIL"]: - return "๏ " + return "โ๏ธ" if weatherDescription in ["LIGHT_THUNDERSTORM_RAIN"]: if isDayTime: - return "๎ข " + return "โ๏ธ" else: - return "๎ช " + return "โ๏ธ" if weatherDescription in ["THUNDERSHOWER", "SCATTERED_THUNDERSTORMS", "THUNDERSTORM", "HEAVY_THUNDERSTORM"]: - return "๎ " + return "๐ฉ๏ธ" if weatherDescription in ["WINDY"]: if isDayTime: - return "๎ " + return "๐" else: - return "๎ญ " + return "๐" if weatherDescription in ["FOG","HAZE","DUST","MIST","SMOKE"]: if isDay: @@ -52,8 +52,8 @@ def getWeatherIcon(isDayTime: bool, weatherDescription: str): url = "https://weather.googleapis.com/v1/currentConditions:lookup" -lat = "25.4448" -long = "81.8432" +lat = "<LATITUDE>" +long = "<LONGITUDE>" load_dotenv() params = { @@ -69,8 +69,8 @@ currentTemperature = jsonDump["temperature"]["degrees"] weatherDescription = jsonDump["weatherCondition"]["type"] isDaytime = jsonDump["isDaytime"] precipitation = jsonDump["precipitation"]["probability"]["percent"] - +windSpeed = jsonDump["wind"]["speed"]["value"] weatherIcon = getWeatherIcon(isDaytime, weatherDescription) -print(weatherIcon, f"{currentTemperature}ยฐC",f"๎ {precipitation}%") +print(weatherIcon, f"{currentTemperature}ยฐC",f"โ {precipitation}%", f"๐ฌ๏ธ {windSpeed}kph") |
