diff options
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | svpm | 202 |
2 files changed, 222 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..277fac7 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +INSTALL_DIR = /usr/bin +SCRIPT_NAME = svpm.sh +TARGET_NAME = svpm +INSTALL_PATH = $(INSTALL_DIR)/$(TARGET_NAME) + +.PHONY: install + +install: + @echo "Installing $(TARGET_NAME)..." + install -m 0755 $(SCRIPT_NAME) $(INSTALL_PATH) + @echo "Done." + +uninstall: + @echo "Uninstalling $(TARGET_NAME)..." + @if [ -f $(INSTALL_PATH) ]; then \ + rm -f $(INSTALL_PATH); \ + echo "Removed $(INSTALL_PATH)"; \ + else \ + echo "$(INSTALL_PATH) not found."; \ + fi @@ -0,0 +1,202 @@ +#!/bin/sh + +# ---------- Config ---------- +MIRROR_CONF="/etc/xbps.d/00-repository-main.conf" +RETRIES=3 + +# ---------- Color ---------- +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +CYAN='\033[0;36m' +NC='\033[0m' + +# ---------- Helpers ---------- +is_root() { + [ "$(id -u)" -eq 0 ] +} + +run() { + if is_root; then + "$@" + else + sudo "$@" + fi +} + +retry_run() { + for i in $(seq 1 $RETRIES); do + "$@" && return 0 + printf '%b\n' "${YELLOW}Attempt $i/$RETRIES failed... retrying${NC}" + sleep 2 + done + printf '%b\n' "${RED}Command failed after $RETRIES retries.${NC}" + return 1 +} + +# ---------- Main ---------- +cmd="$1" +if [ -z "$cmd" ]; then + cmd="help" +else + shift +fi + +case "$cmd" in + install) + if [ $# -eq 0 ]; then exec "$0" help; fi + run xbps-install -S "$@" 2> /tmp/svpm_err.log + status=$? + if [ "$status" -ne 0 ]; then + if grep -q -E "fetch|connection|GPG|signature|network" /tmp/svpm_err.log; then + printf '%b\n' "${YELLOW}Retrying...${NC}" + retry_run run xbps-install -S "$@" + else + cat /tmp/svpm_err.log + exit "$status" + fi + fi + rm -f /tmp/svpm_err.log + ;; + remove) + if [ $# -eq 0 ]; then exec "$0" help; fi + run xbps-remove "$@" + ;; + update) + run xbps-install -S + ;; + upgrade) + retry_run run xbps-install -Su "$@" + for arg in "$@"; do + if [ "$arg" = "--clean" ]; then + run xbps-remove -o + break + fi + done + ;; + search) + if [ $# -eq 0 ]; then exec "$0" help; fi + xbps-query -Rs "$@" + ;; + smart-search) + if [ $# -eq 0 ]; then exec "$0" help; fi + printf '%b\n' "${YELLOW}Searching installed packages:${NC}" + xbps-query -s "$@" + printf '\n%b\n' "${YELLOW}Searching remote repositories:${NC}" + xbps-query -Rs "$@" + ;; + list) + xbps-query -l + ;; + files) + if [ $# -eq 0 ]; then exec "$0" help; fi + xbps-query -f "$@" + ;; + reconfigure) + if [ $# -eq 0 ]; then exec "$0" help; fi + run xbps-reconfigure "$@" + ;; + reconfigure-all) + run xbps-reconfigure -a + ;; + rdeps) + if [ $# -eq 0 ]; then exec "$0" help; fi + xbps-query -Rx "$@" + ;; + owns) + if [ $# -eq 0 ]; then exec "$0" help; fi + xbps-query -S -o "$@" + ;; + info) + if [ $# -eq 0 ]; then exec "$0" help; fi + xbps-query -R "$@" + ;; + list-files) + for pkg in $(xbps-query -l | awk '{print $2}'); do + printf '### %s\n' "$pkg" + xbps-query -f "$pkg" + printf '\n' + done + ;; + held) + printf '%b\n' "${YELLOW}Held packages:${NC}" + xbps-pkgdb -m list | grep held || printf '%b\n' "None found." + ;; + purge) + if [ $# -eq 0 ]; then exec "$0" help; fi + printf 'Finding reverse dependencies of %s...\n' "$1" + DEPS=$(xbps-query -Rx "$1" | awk '{print $2}' | grep -v "^$1$") + printf 'Removing: %s %s\n' "$1" "$DEPS" + run xbps-remove -R "$1" $DEPS + ;; + cleanup) + run xbps-remove -o + ;; + status) + printf 'Checking connection to Void repo...\n' + if ping -c 1 repo-default.voidlinux.org >/dev/null 2>&1; then + printf '%b\n' "${GREEN}Repository is online${NC}" + else + printf '%b\n' "${RED}Repository is unreachable${NC}" + fi + ;; + mirror) + subcmd="$1" + if [ -z "$subcmd" ]; then exec "$0" help; fi + shift + case "$subcmd" in + set) + url="$1" + if [ -z "$url" ]; then exec "$0" help; fi + run sh -c "echo 'repository=$url' > $MIRROR_CONF" + printf '%b\n' "${GREEN}Mirror set to: $url${NC}" + ;; + show) + printf '%b\n' "${YELLOW}Current mirror:${NC}" + cat "$MIRROR_CONF" + ;; + list) + printf '%b\n' "${YELLOW}Official mirrors:${NC}" + printf '%b\n' "https://repo-fi.voidlinux.org/" + printf '%b\n' "https://repo-de.voidlinux.org/" + printf '%b\n' "https://repo-fastly.voidlinux.org/" + printf '%b\n' "https://mirrors.servercentral.com/voidlinux/current" + ;; + *) + exec "$0" help + ;; + esac + ;; + help|--help|-h) + printf '%b\n\n' "${CYAN}Usage:${NC} svpm ${YELLOW}<command>${NC} ${CYAN}[args]${NC}" + printf '%b\n' "${GREEN}Basic Commands:${NC}" + printf ' %b\n' "${YELLOW}install <pkg>${NC} Install a package" + printf ' %b\n' "${YELLOW}remove <pkg>${NC} Remove a package" + printf ' %b\n' "${YELLOW}upgrade [--clean]${NC} Upgrade system (optionally clean orphans)" + printf ' %b\n\n' "${YELLOW}update${NC} Sync repositories" + + printf '%b\n' "${GREEN}Query Commands:${NC}" + printf ' %b\n' "${YELLOW}search <pattern>${NC} Search available packages" + printf ' %b\n' "${YELLOW}smart-search <pattern>${NC} Search installed and available packages" + printf ' %b\n' "${YELLOW}list${NC} List installed packages" + printf ' %b\n' "${YELLOW}info <pkg>${NC} Show package info" + printf ' %b\n' "${YELLOW}files <pkg>${NC} Show files installed by package" + printf ' %b\n' "${YELLOW}owns <file>${NC} Find what package owns a file" + printf ' %b\n' "${YELLOW}rdeps <pkg>${NC} Show reverse dependencies" + printf ' %b\n' "${YELLOW}held${NC} List held packages" + printf ' %b\n\n' "${YELLOW}list-files${NC} List files for all installed packages" + + printf '%b\n' "${GREEN}System:${NC}" + printf ' %b\n' "${YELLOW}reconfigure <pkg>${NC} Re-run postinstall for package" + printf ' %b\n' "${YELLOW}reconfigure-all${NC} Reconfigure all packages" + printf ' %b\n' "${YELLOW}purge <pkg>${NC} Remove package and reverse deps" + printf ' %b\n' "${YELLOW}mirror {set|show|list}${NC} Manage repo mirrors" + printf ' %b\n' "${YELLOW}status${NC} Check Void repo connection" + printf ' %b\n' "${YELLOW}cleanup${NC} Remove orphaned packages" + ;; + *) + printf '%b\n' "${RED}❌ Unknown command: $cmd${NC}" + printf 'Run '\''svpm help'\'' for a list of commands.\n' + exit 1 + ;; +esac |