From 314d760de1922128124f2a9be0494fd4f6f7effb Mon Sep 17 00:00:00 2001 From: subh Date: Fri, 3 Apr 2026 14:47:03 +0530 Subject: new music bar, auto usb mounting and more --- scripts/mount-usb.sh | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/umount-usb.sh | 22 ++++++++++ scripts/weather.py | 36 ++++++++--------- 3 files changed, 149 insertions(+), 18 deletions(-) create mode 100755 scripts/mount-usb.sh create mode 100755 scripts/umount-usb.sh (limited to 'scripts') 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 = "" +long = "" 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") -- cgit v1.2.3