From e798cd3bb1b2d1e5997850ee5550645df5a13d49 Mon Sep 17 00:00:00 2001 From: ION606 Date: Tue, 17 Sep 2024 14:42:51 -0400 Subject: [PATCH] updated script for Arch --- .gitignore | 3 +- auto/icons/charging-station.svg | 16 ++ auto/icons/check.svg | 5 + auto/icons/info.svg | 425 ++++++++++++++++++++++++++++++++ auto/icons/low-battery.svg | 16 ++ auto/icons/no.svg | 4 + auto/icons/unplugged.svg | 22 ++ auto/restartservices.sh | 4 + auto/run.sh | 83 +++++++ auto/setupauto.sh | 34 +++ auto/shownotif.sh | 49 ++++ config | 14 +- setup.sh | 78 ++---- wofi/config | 20 ++ wofi/style.css | 40 +++ 15 files changed, 756 insertions(+), 57 deletions(-) create mode 100644 auto/icons/charging-station.svg create mode 100644 auto/icons/check.svg create mode 100644 auto/icons/info.svg create mode 100644 auto/icons/low-battery.svg create mode 100644 auto/icons/no.svg create mode 100644 auto/icons/unplugged.svg create mode 100644 auto/restartservices.sh create mode 100755 auto/run.sh create mode 100644 auto/setupauto.sh create mode 100755 auto/shownotif.sh create mode 100644 wofi/config create mode 100644 wofi/style.css diff --git a/.gitignore b/.gitignore index cd78447..c4c3aaa 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -temp/ \ No newline at end of file +temp/ +props.txt diff --git a/auto/icons/charging-station.svg b/auto/icons/charging-station.svg new file mode 100644 index 0000000..524939d --- /dev/null +++ b/auto/icons/charging-station.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/auto/icons/check.svg b/auto/icons/check.svg new file mode 100644 index 0000000..ad796fc --- /dev/null +++ b/auto/icons/check.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/auto/icons/info.svg b/auto/icons/info.svg new file mode 100644 index 0000000..6b4cb30 --- /dev/null +++ b/auto/icons/info.svg @@ -0,0 +1,425 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/auto/icons/low-battery.svg b/auto/icons/low-battery.svg new file mode 100644 index 0000000..57e8190 --- /dev/null +++ b/auto/icons/low-battery.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/auto/icons/no.svg b/auto/icons/no.svg new file mode 100644 index 0000000..fdcdede --- /dev/null +++ b/auto/icons/no.svg @@ -0,0 +1,4 @@ + + + + diff --git a/auto/icons/unplugged.svg b/auto/icons/unplugged.svg new file mode 100644 index 0000000..0055e3f --- /dev/null +++ b/auto/icons/unplugged.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/auto/restartservices.sh b/auto/restartservices.sh new file mode 100644 index 0000000..5aff8f8 --- /dev/null +++ b/auto/restartservices.sh @@ -0,0 +1,4 @@ +chmod +x $PWD/.customscripts/run.sh +sudo systemctl daemon-reload +sudo systemctl restart shownotif.service + diff --git a/auto/run.sh b/auto/run.sh new file mode 100755 index 0000000..094bd1c --- /dev/null +++ b/auto/run.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +PER=$(( $(cat /sys/class/power_supply/BAT1/charge_now) * 100 / $(cat /sys/class/power_supply/BAT1/charge_full) )) + + +# Check if the PC is charging +IS_CHARGING=false +[ "$(cat /sys/class/power_supply/BAT1/status)" == "Charging" ] && IS_CHARGING=true + +declare -A props + +# Load properties from file +load_props() { + local file="$PWD/props.txt" + if [[ -f "$file" ]]; then + while IFS='=' read -r key value; do + props["$key"]="$value" + done < "$file" + else + props["lowchargenotifsent"]=false + props["ischarge"]=$IS_CHARGING + props["ischargingnotifshown"]=false + props["isunpluggednotifshown"]=false # Add the new property for unplugging notification + fi +} + +# Save properties to file +save_props() { + local file="$PWD/props.txt" + > "$file" + for key in "${!props[@]}"; do + echo "$key=${props[$key]}" >> "$file" + done +} + +# Load the properties at the start +load_props + +# Battery percentage-based logic +if [[ "$PER" -le 10 ]]; then + # Always show notification if battery is 10% or less + bash $PWD/shownotif.sh lowbat +elif [[ "$PER" -le 20 && "${props["lowchargenotifsent"]}" == "false" ]]; then + # Show notification if battery is 20% or less, but only if it hasn't been sent already + bash $PWD/shownotif.sh lowbat + props["lowchargenotifsent"]=true +fi + +# Check if props["ischarge"] does not match IS_CHARGING and update accordingly +if [[ "${props["ischarge"]}" != "$IS_CHARGING" ]]; then + if [[ "$IS_CHARGING" == true ]]; then + bash $PWD/shownotif.sh charging-status-mismatch "Now Charging" + else + bash $PWD/shownotif.sh charging-status-mismatch "Now Unplugged" + fi + props["ischarge"]=$IS_CHARGING +fi + +# Check if the PC is charging and show a notification if needed +if [[ "$IS_CHARGING" == true && "${props["ischargingnotifshown"]}" == "false" ]]; then + bash $PWD/shownotif.sh charging + props["ischargingnotifshown"]=true + props["isunpluggednotifshown"]=false # Reset unplugged notification flag when charging +elif [[ "$IS_CHARGING" == false && "${props["isunpluggednotifshown"]}" == "false" ]]; then + # Show unplugged notification when the PC is no longer charging + bash $PWD/shownotif.sh unplugged + props["isunpluggednotifshown"]=true + props["ischargingnotifshown"]=false # Reset charging notification flag when unplugged +fi + +# Save updated properties +save_props + + +# temperature +TEMP=$(sensors | grep -i 'temp1' | head -n 1 | awk '{print $2}' | sed 's/+//g;s/°C//g') + +# force to int +TEMP=${TEMP%.*} + +if [ "$TEMP" -gt 20 ]; then + bash $PWD/shownotif.sh temperature +fi diff --git a/auto/setupauto.sh b/auto/setupauto.sh new file mode 100644 index 0000000..a0317b5 --- /dev/null +++ b/auto/setupauto.sh @@ -0,0 +1,34 @@ +cat << EOF > /etc/systemd/system/shownotif.timer +[Unit] +Description=shownotifs + +[Timer] +OnBootSec=1min +OnUnitActiveSec=1min +Persistent=true +OnCalendar=*:0/1 + +[Install] +WantedBy=timers.target +EOF + +cat << EOF > /etc/systemd/system/shownotif.service +[Unit] +Description=Run shownotif script + +[Service] +ExecStart=/home/$1/.customscripts/run.sh +Type=simple +User=$1 +Environment="DISPLAY=:0" +Environment="DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus" +EOF + +sudo systemctl daemon-reload +sudo systemctl enable --now shownotif.timer + +if systemctl list-timers --all | grep -q shownotif; then + bash +else + echo "shownotif timer install failed!" +fi diff --git a/auto/shownotif.sh b/auto/shownotif.sh new file mode 100755 index 0000000..904bcce --- /dev/null +++ b/auto/shownotif.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +PER=$(( $(cat /sys/class/power_supply/BAT1/charge_now) * 100 / $(cat /sys/class/power_supply/BAT1/charge_full) )) + + +IS_CHARGING=true +[ "$(cat /sys/class/power_supply/BAT1/status)" == "Charging" ] && IS_CHARGING=true || IS_CHARGING=false + + +case $1 in + info) + dunstify "INFO" "$2!" -u critical -i $PWD/icons/info.svg + ;; + + lowbat) + if [ $IS_CHARGING == true ]; then + action=$(dunstify -A default,exit "LOW BATTERY!" "battery at $PER%!" -u critical -i $PWD/icons/low-battery.svg) + + if [ "$(echo "$action" | xargs)" = "default" ]; then + brightnessctl set $(($(brightnessctl m) / 2)) + kill -9 $(ps aux | grep vesktop | grep -v grep | awk '{print $2}') + kill -9 $(ps aux | grep discord | grep -v grep | awk '{print $2}') + fi + fi + ;; + + success) + dunstify "SUCCESS!" "Action completed successfully!" -u low -i $PWD/icons/check.svg + ;; + + temperature) + dunstify "ERROR!" "YOUR PC IS OVERHEATING!!!\nDO SOMETHING!!!" -u critical -i $PWD/icons/no.svg + kill -9 $(ps aux | grep vesktop | grep -v grep | awk '{print $2}') + kill -9 $(ps aux | grep discord | grep -v grep | awk '{print $2}') + ;; + + err) + dunstify "ERROR!" "see $2 for more details" -u critical -i $PWD/icons/no.svg + ;; + + charging) + dunstify "CHARGING!" "battery at $PER%!" -u critical -i $PWD/icons/charging-station.svg + ;; + + unplugged) + dunstify "STOPPED CHARGING!" "battery at $PER%!" -u critical -i $PWD/icons/unplugged.svg + ;; + +esac diff --git a/config b/config index d14d9b8..dbf2b3d 100644 --- a/config +++ b/config @@ -36,9 +36,14 @@ set $menu wofi --show=drun style="/home/ion606/.cache/wofi/style.css" # Requires: desktop-backgrounds-compat, swaybg # output * bg /home/ion606/Pictures/bk.gif fill output * bg "$(find /home/ion606/Pictures/astolfo/ -type f | shuf -n 1)" fill +bindsym $mod+b exec swaymsg output "*" bg "$(find /home/ion606/Pictures/bk/ -type f | shuf -n 1)" fill + +# Misc apps on startup exec /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 exec nm-applet --indicator exec blueman-applet +exec bash /home/ion606/getargs.sh +exec mako set $colors { background #000000 @@ -98,10 +103,9 @@ input "2.4G Mouse" { ### Key bindings # # Basics: -# - bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -10% - bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +10% + bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5% + bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5% bindsym XF86AudioMute exec pactl set-sink-volume @DEFAULT_SINK@ 0 bindsym XF86MonBrightnessDown exec brightnessctl set 10%- bindsym XF86MonBrightnessUp exec brightnessctl set +10% @@ -198,8 +202,8 @@ input "2.4G Mouse" { # You can "split" the current object of your focus with # $mod+b or $mod+v, for horizontal and vertical splits # respectively. - bindsym $mod+b splith - bindsym $mod+v splitv + # bindsym $mod+b splith + # bindsym $mod+v splitv # Switch the current container between different layout styles bindsym $mod+s layout stacking diff --git a/setup.sh b/setup.sh index 501037d..5a5cf37 100644 --- a/setup.sh +++ b/setup.sh @@ -6,6 +6,9 @@ if [ "$EUID" -ne 0 ] exit fi +sudo pacman -Sy --needed --noconfirm --noconfirm fzf git yay +USERTEMP=$(who | awk '{print $1}' | sort -u | fzf) + # Explain what the script will do and ask for confirmation echo "This script will install and do the following: - Configuration files from https://github.com/ION606/swaybackup.git @@ -13,7 +16,6 @@ echo "This script will install and do the following: - Visual Studio Code - Various fonts - The latest version of Java -- Proton VPN - Alacritty terminal - Nautilus file manager - Node.js @@ -48,89 +50,63 @@ if [ "$answer" != "y" ]; then fi # Make temporary directory -mkdir ~/Downloads/tempinstall || "" -cd ~/Downloads/tempinstall +mkdir $USERTEMP/Downloads/tempinstall || "" +cd $USERTEMP/Downloads/tempinstall # Configuration Files git clone https://github.com/ION606/swaybackup.git cd swaybackup mv -f waybar/config /etc/xdg/waybar/ mv -f waybar/style.css /etc/xdg/waybar -mv -f config ~/.config/sway/config -mf -f lockscreen.sh ~/lockscreen.sh +mv -f config $USERTEMP/.config/sway/config +mf -f lockscreen.sh $USERTEMP/lockscreen.sh +# replace "ion606" with the selected user +sed -i "s/ion606/$USERTEMP/g" config + +# set up automations in child process +mkdir -p $USERTEMP/.automations && cp -r -f auto/* $USERTEMP/.automations/ && $(sudo pacman -Sy --needed --noconfirm dunst && sudo bash $USERTEMP/.automations/setupauto.sh $USERTEMP &> $USERTEMP/setuplogs.log) & # Installs - -# Automatically Answer "Y" -echo assumeyes=True | sudo tee -a /etc/dnf/dnf.conf - # Librewolf curl -fsSL https://rpm.librewolf.net/librewolf-repo.repo | pkexec tee /etc/yum.repos.d/librewolf.repo -# VS Code -rpm --import https://packages.microsoft.com/keys/microsoft.asc -printf "[vscode]\nname=packages.microsoft.com\nbaseurl=https://packages.microsoft.com/yumrepos/vscode/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc\nmetadata_expire=1h" | sudo tee -a /etc/yum.repos.d/vscode.repo - # Fonts -dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \ - https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm \ - install bitstream-vera-sans-fonts bitstream-vera-serif-fonts bitstream-vera-sans-mono-fonts \ - google-droid-sans-fonts google-droid-serif-fonts google-droid-sans-mono-fonts \ - urw-fonts || echo "failed to install fonts!" - -rpm -i https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm || echo "failed to install microsoft fonts!" +yay -Sy ttf-bitstream-vera ttf-droid gsfonts ttf-ms-win11-auto || echo "failed to install fonts!" # Install Java -LATEST_JDK=$(sudo dnf list available | grep -E 'java-[0-9]+-openjdk' | awk '{print $1}' | sort -V | tail -n 1) && dnf install -y $LATEST_JDK || echo "failed to install Java!" +LATEST_JDK=$(sudo dnf list available | grep -E 'java-[0-9]+-openjdk' | awk '{print $1}' | sort -V | tail -n 1) && yay -Sy --needed --noconfirm $LATEST_JDK || echo "failed to install Java!" -# Proton VPN -wget "https://repo.protonvpn.com/fedora-$(cat /etc/fedora-release | cut -d\ -f 3)-stable/protonvpn-stable-release/protonvpn-stable-release-1.0.1-2.noarch.rpm" \ - && dnf install ./protonvpn-stable-release-1.0.1-2.noarch.rpm \ - || echo "failed to install Proton VPN!" - - -# Install Docker and Minikube -dnf install dnf-plugins-core \ - && dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo \ - && dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin \ - || echo "failed to install Docker!" - -curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm \ - && sudo rpm -Uvh minikube-latest.x86_64.rpm \ - || echo "failed to install Minikube!" +# # Proton VPN +# wget "https://repo.protonvpn.com/fedora-$(cat /etc/fedora-release | cut -d\ -f 3)-stable/protonvpn-stable-release/protonvpn-stable-release-1.0.1-2.noarch.rpm" \ +# && dnf install ./protonvpn-stable-release-1.0.1-2.noarch.rpm \ +# || echo "failed to install Proton VPN!" # General Package Install -dnf install --refresh alacritty nautilus nodejs librewolf code \ +yay -Sy --needed --noconfirm alacritty nautilus nodejs librewolf vscodium-bin \ git gh proton-vpn-gnome-desktop neovim gparted liberation-fonts \ vlc gcc gcc-c++ asciiquarium thunderbird grim slurp xclip \ qbittorrent gimp audacity python3-pip htop obs-studio gnome-tweaks \ - torbrowser-launcher \ + torbrowser-launcher lm_sensors fancontrol blueman blueman-applet docker minikube \ + min-browser-bin libreoffice-fresh npm wofi nm-applet nm-connection-editor mako\ || echo "failed to install some packages!" npm install -g @bitwarden/cli alacritty-themes typescript || echo "failed to install Typescript!" -mkdir -p ~/.icons -echo -e "https://www.gnome-look.org/p/1305251\nhttps://www.gnome-look.org/p/2091068" > ~/.icons/links.txt +mkdir -p $USERTEMP/.icons +echo -e "https://www.gnome-look.org/p/1305251\nhttps://www.gnome-look.org/p/2091068" > $USERTEMP/.icons/links.txt alacritty-themes --create && alacritty-themes Hyper || echo "alacritty theme install failed!" +cp -r $USERTEMP/.config/wofi/ wofi > /dev/null 2>&1 & gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark' # Remove old programs -dnf remove thunar foot || "" - -# Install vesktop -wget -O vesktop.rpm https://vencord.dev/download/vesktop/amd64/rpm && dnf install vesktop || echo "failed to install Vesktop!" - -# Install Min -rpm -i https://github.com/minbrowser/min/releases/download/v1.32.1/min-1.32.1-x86_64.rpm --ignoreos --force +yay -R thunar foot || "" # Clean-up and update -sudo dnf clean all -sudo dnf update -echo assumeyes=False | sudo tee -a /etc/dnf/dnf.conf -cd ../ && rm -rf tempinstall || echo "failed to remove temporary directory at ~/Downloads/tempinstall" +yay && yay -Scc +cd ../ && rm -rf tempinstall || echo "failed to remove temporary directory at $PWD/tempinstall" # history preferences HISTIGNORE="*shutdown now*:*reboot*:erasedups" diff --git a/wofi/config b/wofi/config new file mode 100644 index 0000000..163574f --- /dev/null +++ b/wofi/config @@ -0,0 +1,20 @@ +hide_scroll=true +show=drun +width=30% +lines=8 +line_wrap=word +term=kitty +allow_markup=true +always_parse_args=false +show_all=true +print_command=true +layer=overlay +allow_images=true +sort_order=alphabetical +gtk_dark=true +prompt= +image_size=20 +display_generic=false +location=center +key_expand=Tab +insensitive=false diff --git a/wofi/style.css b/wofi/style.css new file mode 100644 index 0000000..8b4726c --- /dev/null +++ b/wofi/style.css @@ -0,0 +1,40 @@ +* { + font-family: JetBrainsMono; + color: #e5e9f0; + background: transparent; +} + +#window { + background: rgba(41, 46, 66, 0.5); + margin: auto; + padding: 10px; + border-radius: 20px; + border: 5px solid #b072d1; +} + +#input { + padding: 10px; + margin-bottom: 10px; + border-radius: 15px; +} + +#outer-box { + padding: 20px; +} + +#img { + margin-right: 6px; +} + +#entry { + padding: 10px; + border-radius: 15px; +} + +#entry:selected { + background-color: #2e3440; +} + +#text { + margin: 2px; +}