diff options
| author | subh <subh@example.com> | 2026-01-19 21:47:02 +0530 |
|---|---|---|
| committer | subh <subh@example.com> | 2026-01-19 21:47:02 +0530 |
| commit | 65aad59ef0802708a8a7c8a312755232cc1823d3 (patch) | |
| tree | fe0a437f3e9a71ab5b9197d9b8fa72c24d2170ea /scripts | |
initial commit
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/cleanup-update.sh | 55 | ||||
| -rwxr-xr-x | scripts/fzf.sh | 45 | ||||
| -rwxr-xr-x | scripts/lock.sh | 2 | ||||
| -rwxr-xr-x | scripts/power.sh | 10 | ||||
| -rwxr-xr-x | scripts/strap.sh | 222 | ||||
| -rwxr-xr-x | scripts/vpn_connect.sh | 14 | ||||
| -rwxr-xr-x | scripts/vpn_disconnect.sh | 7 | ||||
| -rwxr-xr-x | scripts/wallpaper-picker.sh | 15 | ||||
| -rwxr-xr-x | scripts/wifi-connect.sh | 31 | ||||
| -rwxr-xr-x | scripts/wifi-disconnect.sh | 13 |
10 files changed, 414 insertions, 0 deletions
diff --git a/scripts/cleanup-update.sh b/scripts/cleanup-update.sh new file mode 100755 index 0000000..519668f --- /dev/null +++ b/scripts/cleanup-update.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# Arch Linux Update + Cleanup Script +# Author: ChatGPT +# Usage: ./arch-update-cleanup.sh + +set -euo pipefail + +# --- Colors for nice output --- +GREEN="\e[32m" +YELLOW="\e[33m" +RED="\e[31m" +RESET="\e[0m" + +echo -e "${GREEN}Starting Arch Linux update & cleanup...${RESET}" +echo + +# --- Step 1: Update pacman database and system --- +echo -e "${YELLOW}Updating system packages...${RESET}" +sudo pacman -Syu --noconfirm + +# --- Step 2: Remove unused dependencies --- +echo -e "${YELLOW}Removing unused dependencies...${RESET}" +sudo pacman -Rns $(pacman -Qtdq 2>/dev/null || echo "") || true + +# --- Step 3: Clean pacman cache (keep 3 latest versions) --- +echo -e "${YELLOW}Cleaning package cache...${RESET}" +sudo paccache -r -k3 + +# --- Step 4: Update AUR packages (if yay installed) --- +if command -v yay >/dev/null 2>&1; then + echo -e "${YELLOW}Updating AUR packages...${RESET}" + yay -Syu --noconfirm +fi + +# --- Step 5: Update Flatpak packages (if installed) --- +if command -v flatpak >/dev/null 2>&1; then + echo -e "${YELLOW}Updating Flatpak packages...${RESET}" + flatpak update -y +fi + +# --- Step 6: Update Snap packages (if installed) --- +if command -v snap >/dev/null 2>&1; then + echo -e "${YELLOW}Updating Snap packages...${RESET}" + sudo snap refresh +fi + +# --- Step 7: Optional cleanup: orphaned Flatpak runtimes --- +if command -v flatpak >/dev/null 2>&1; then + echo -e "${YELLOW}Removing unused Flatpak runtimes...${RESET}" + flatpak uninstall --unused -y +fi + +echo +echo -e "${GREEN}System update & cleanup complete!${RESET}" + diff --git a/scripts/fzf.sh b/scripts/fzf.sh new file mode 100755 index 0000000..5ef3dae --- /dev/null +++ b/scripts/fzf.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -e + +ZSHRC="$HOME/.zshrc" + +echo "▶ Installing fzf (Arch)…" +sudo pacman -S --needed fzf + +echo "▶ Updating ~/.zshrc…" + +# Remove unsupported Ctrl-R command if present +sed -i '/FZF_CTRL_R_COMMAND/d' "$ZSHRC" + +# Append config only if not already present +if ! grep -q "==== fzf key bindings (Arch Linux) ====" "$ZSHRC"; then +cat <<'EOF' >> "$ZSHRC" + +# ==== fzf key bindings (Arch Linux) ==== + +# Remove unsupported custom Ctrl-R command (prevents warning) +unset FZF_CTRL_R_COMMAND + +# fzf defaults +export FZF_DEFAULT_OPTS="--height 40% --layout=reverse --border" +export FZF_CTRL_R_OPTS="--tac --preview 'echo {}' --preview-window down:3:hidden:wrap" + +# Source fzf (Arch path) +if [[ -f /usr/share/fzf/key-bindings.zsh ]]; then + source /usr/share/fzf/key-bindings.zsh +fi + +if [[ -f /usr/share/fzf/completion.zsh ]]; then + source /usr/share/fzf/completion.zsh +fi + +# Ensure Ctrl+R works in vi insert mode +bindkey -M viins '^R' fzf-history-widget + +# ==== end fzf ==== +EOF +fi + +echo "✅ Done." +echo "➡ Open a NEW terminal or run: exec zsh" + diff --git a/scripts/lock.sh b/scripts/lock.sh new file mode 100755 index 0000000..e9e3323 --- /dev/null +++ b/scripts/lock.sh @@ -0,0 +1,2 @@ +hyprlock -c /home/subh/.config/hyprlock/hyprlock.conf + diff --git a/scripts/power.sh b/scripts/power.sh new file mode 100755 index 0000000..ef349fc --- /dev/null +++ b/scripts/power.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +choice=$(printf "⏻ Shutdown\n Reboot\n Suspend\n Logout" | rofi -dmenu -prompt "Power") + +case "$choice" in + "⏻ Shutdown") systemctl poweroff ;; + " Reboot") systemctl reboot ;; + " Suspend") systemctl suspend ;; + " Logout") /opt/scripts/lock.sh ;; +esac diff --git a/scripts/strap.sh b/scripts/strap.sh new file mode 100755 index 0000000..ea84acf --- /dev/null +++ b/scripts/strap.sh @@ -0,0 +1,222 @@ +#!/bin/sh +# strap.sh - setup BlackArch Linux keyring and install initial packages + +VERSION=20251011 +ARCH=$(uname -m) + +# mirror file to fetch and write +MIRROR_F='blackarch-mirrorlist' + +# simple error message wrapper +err() +{ + echo >&2 "$(tput bold; tput setaf 1)[-] ERROR: ${*}$(tput sgr0)" + + exit 1337 +} + +# simple warning message wrapper +warn() +{ + echo >&2 "$(tput bold; tput setaf 1)[!] WARNING: ${*}$(tput sgr0)" +} + +# simple echo wrapper +msg() +{ + echo "$(tput bold; tput setaf 2)[+] ${*}$(tput sgr0)" +} + +# check for root privilege +check_priv() +{ + if [ "$(id -u)" -ne 0 ]; then + err "you must be root" + fi +} + +# make a temporary directory and cd into +make_tmp_dir() +{ + tmp="$(mktemp -d /tmp/blackarch_strap.XXXXXXXX)" + + trap 'rm -rf $tmp' EXIT + + cd "$tmp" || err "Could not enter directory $tmp" +} + +set_umask() +{ + OLD_UMASK=$(umask) + + umask 0022 + + trap 'reset_umask' TERM +} + +reset_umask() +{ + umask $OLD_UMASK +} + +check_internet() +{ + tool='curl' + tool_opts='-s --connect-timeout 8' + + if ! $tool $tool_opts https://blackarch.org/ > /dev/null 2>&1; then + err "You don't have an Internet connection!" + fi + + return $SUCCESS +} + +# retrieve the BlackArch Linux keyring +fetch_keyring() +{ + curl -s -O \ + "https://www.blackarch.org/keyring/blackarch-keyring-$VERSION.tar.gz" + + curl -s -O \ + "https://www.blackarch.org/keyring/blackarch-keyring-$VERSION.tar.gz.sig" +} + +# verify the keyring signature +# note: this is pointless if you do not verify the key fingerprint +verify_keyring() +{ + if ! gpg --keyserver keyserver.ubuntu.com \ + --recv-keys 4345771566D76038C7FEB43863EC0ADBEA87E4E3 > /dev/null 2>&1 + then + if ! gpg --keyserver hkps://keyserver.ubuntu.com:443 \ + --recv-keys 4345771566D76038C7FEB43863EC0ADBEA87E4E3 > /dev/null 2>&1 + then + if ! gpg --keyserver hkp://pgp.mit.edu:80 \ + --recv-keys 4345771566D76038C7FEB43863EC0ADBEA87E4E3 > /dev/null 2>&1 + then + err "could not verify the key. Please check: https://blackarch.org/faq.html" + fi + fi + fi + + if ! gpg --keyserver-options no-auto-key-retrieve \ + --with-fingerprint "blackarch-keyring-$VERSION.tar.gz.sig" \ + > /dev/null 2>&1 + then + err "invalid keyring signature. please stop by https://matrix.to/#/#BlackArch:matrix.org" + fi +} + +# delete the signature files +delete_signature() +{ + if [ -f "blackarch-keyring-$VERSION.tar.gz.sig" ]; then + rm "blackarch-keyring-$VERSION.tar.gz.sig" + fi +} + +# make sure /etc/pacman.d/gnupg is usable +check_pacman_gnupg() +{ + pacman-key --init +} + +# install the keyring +install_keyring() +{ + tar xfz "blackarch-keyring-$VERSION.tar.gz" --strip-components=1 \ + -C /usr/share/pacman/keyrings/ + + # just in case + pacman-key --populate +} + +# ask user for mirror +get_mirror() +{ + mirror_p="/etc/pacman.d" + mirror_r="https://blackarch.org" + + msg "fetching new mirror list..." + if ! curl -s "$mirror_r/$MIRROR_F" -o "$mirror_p/$MIRROR_F" ; then + err "we couldn't fetch the mirror list from: $mirror_r/$MIRROR_F" + fi + + msg "you can change the default mirror under $mirror_p/$MIRROR_F" +} + +# update pacman.conf +update_pacman_conf() +{ + # delete blackarch related entries if existing + sed -i '/blackarch/{N;d}' /etc/pacman.conf + + cat >> "/etc/pacman.conf" << EOF +[blackarch] +Include = /etc/pacman.d/$MIRROR_F +EOF +} + +# synchronize and update +pacman_update() +{ + if pacman -Syy; then + return $SUCCESS + fi + + warn "Synchronizing pacman has failed. Please try manually: pacman -Syy" + + return $FAILURE +} + +pacman_upgrade() +{ + echo 'perform full system upgrade? (pacman -Su) [Yn]:' + read conf < /dev/tty + case "$conf" in + ''|y|Y) pacman -Su ;; + n|N) warn 'some blackarch packages may not work without an up-to-date system.' ;; + esac +} + + +# setup blackarch linux +blackarch_setup() +{ + msg 'installing blackarch keyring...' + check_priv + set_umask + make_tmp_dir + check_internet + fetch_keyring + #verify_keyring + delete_signature + check_pacman_gnupg + install_keyring + + echo + msg 'keyring installed successfully' + # check if pacman.conf has already a mirror + if ! grep -q "\[blackarch\]" /etc/pacman.conf; then + msg 'configuring pacman' + get_mirror + msg 'updating pacman.conf' + update_pacman_conf + fi + msg 'updating package databases' + pacman_update + reset_umask + msg 'installing blackarch-mirrorlist package' + pacman -S --noconfirm blackarch-mirrorlist + if [ -f /etc/pacman.d/blackarch-mirrorlist.pacnew ]; then + mv /etc/pacman.d/blackarch-mirrorlist.pacnew \ + /etc/pacman.d/blackarch-mirrorlist + fi + msg 'BlackArch repository is ready!' + msg 'You can install `blackarch-officials` metapackage with the most popular tools using the command below:' + msg 'sudo pacman -S --needed blackarch-officials' +} + +blackarch_setup + + diff --git a/scripts/vpn_connect.sh b/scripts/vpn_connect.sh new file mode 100755 index 0000000..d08b397 --- /dev/null +++ b/scripts/vpn_connect.sh @@ -0,0 +1,14 @@ +output=$(protonvpn connect) + +if echo "$output" | grep -q "Connection failed"; then + notify-send -u critical -i dialog-error "VPN Connection Status" "Failed to connect to VPN. Please check your network settings." +else + region=$(echo "$output" | awk '{print $3 ":" $12}') + + if [ -z "$region" ]; then + notify-send -u critical -i dialog-error "VPN Connection Status" "Failed to connect to VPN. Please check your connection settings." + else + notify-send -u normal -i network-wireless "VPN Connection Status" "Successfully connected to VPN. Region: $region" + fi +fi + diff --git a/scripts/vpn_disconnect.sh b/scripts/vpn_disconnect.sh new file mode 100755 index 0000000..bf46c20 --- /dev/null +++ b/scripts/vpn_disconnect.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +disc=$(protonvpn disconnect) + +if [ -z "$disc" ]; then + notify-send -u normal -i network-wireless "VPN Connection Status" "VPN successfully disconnected" +fi diff --git a/scripts/wallpaper-picker.sh b/scripts/wallpaper-picker.sh new file mode 100755 index 0000000..266c6dd --- /dev/null +++ b/scripts/wallpaper-picker.sh @@ -0,0 +1,15 @@ + +#!/bin/bash + +WALL_DIR="$HOME/wallpapers" + +choices=$(find "$WALL_DIR" -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.webp" \) \ + | sort \ + | rofi -dmenu -i -p "Pick wallpaper") + +[ -z "$choices" ] && exit +swww img "$choices" \ + --transition-fps 60 \ + --transition-type any + + diff --git a/scripts/wifi-connect.sh b/scripts/wifi-connect.sh new file mode 100755 index 0000000..b34f8f4 --- /dev/null +++ b/scripts/wifi-connect.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +[[ "$(nmcli -g WIFI general)" == "disabled" ]] && nmcli radio wifi on + +NETWORKS=$(nmcli -f SSID,SIGNAL,SECURITY dev wifi list | tail -n +2 | \ +awk -F ' +' ' + $1 != "" { + display = sprintf("%s (%s%%) [%s]", $1, $2, $3) + print display + } +' | sort -u) + +CHOICE=$(echo "$NETWORKS" | rofi -dmenu -i -p "WiFi") +[[ -z "$CHOICE" ]] && exit 0 + +SSID=$(echo "$CHOICE" | sed 's/ (.*//') + +BSSID=$(nmcli -t -f BSSID,SIGNAL dev wifi list | grep "^.*:$SSID$" | \ +awk -F: '{print $1}' | sort -nr | head -n1) + +[[ -z "$BSSID" ]] && BSSID="$SSID" + +if nmcli dev wifi connect "$BSSID" 2>/dev/null; then + notify-send -u normal -i network-wireless "WiFi Status" "$SSID Connected Successfully" +else + PASSWORD=$(rofi -dmenu -password -p "Password for $SSID") + [[ -z "$PASSWORD" ]] && exit 1 + nmcli dev wifi connect "$BSSID" password "$PASSWORD" && \ + notify-send -u normal -i network-wireless "WiFi Status" "$SSID Connected Successfully" +fi + diff --git a/scripts/wifi-disconnect.sh b/scripts/wifi-disconnect.sh new file mode 100755 index 0000000..aeaaa10 --- /dev/null +++ b/scripts/wifi-disconnect.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +output=$(nmcli device disconnect wlp8s0) +status_code=$? + +if [ $status_code -ne 0 ]; then + notify-send -u critical -i dialog-error "WiFi Status" "Failed to disconnect. Device not connected." +else + if echo $output | grep -q "successfully disconnected"; then + notify-send -u normal -i network-wireless "WiFi Status" "Device wlp8s0 disconnected." + fi +fi + |
