Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 64 additions & 27 deletions scripts/packages/install-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,102 @@ set -euo pipefail

show_help() {
cat <<'EOF'
Usage: $(basename "$0") [options] <package_name>
Usage: install-package.sh [options] <package_name>

Options:
-h Show this help message and exit
-y Automatically answer yes to any prompts (use with caution)
-h, --help Show this help message and exit
-y, --yes Automatically answer yes to any prompts
-n, --dry-run Show the command that would be run without installing

Installs the specified package using the detected package manager.
The script will prompt for confirmation unless -y is provided.
Description:
Installs the specified package using the detected package manager
(pacman, apt, dnf, zypper, apk). Prompts for confirmation unless
-y or --yes is provided.
EOF
exit 0
}

# Default values
AUTOYES=false
DRY_RUN=false
PACKAGE=""

# Parse options
while getopts "hy" opt; do
case "$opt" in
h) show_help ;;
y) AUTOYES=true ;;
*) show_help ;;
while (( "$#" )); do
case "$1" in
-h|--help)
show_help
;;
-y|--yes)
AUTOYES=true
;;
-n|--dry-run)
DRY_RUN=true
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*)
if [[ -z "$PACKAGE" ]]; then
PACKAGE="$1"
else
echo "Error: Unexpected additional argument: $1" >&2
exit 1
fi
;;
esac
shift
done

shift $((OPTIND -1))

if [[ $# -lt 1 ]]; then
echo "Error: package name required."
show_help
if [[ -z "$PACKAGE" ]]; then
echo "Error: package name required." >&2
echo "Run '$0 --help' for usage." >&2
exit 1
fi

PACKAGE="$1"
declare -a INSTALL_CMD=()
PM=""

# Detect package manager
if command -v pacman >/dev/null 2>&1; then
PM="pacman"
INSTALL_CMD="pacman -S --noconfirm"
INSTALL_CMD=(pacman -S --noconfirm)
elif command -v apt-get >/dev/null 2>&1; then
PM="apt"
INSTALL_CMD=(apt-get install -y)
elif command -v apt >/dev/null 2>&1; then
PM="apt"
INSTALL_CMD="apt install -y"
INSTALL_CMD=(apt install -y)
elif command -v dnf >/dev/null 2>&1; then
PM="dnf"
INSTALL_CMD="dnf install -y"
INSTALL_CMD=(dnf install -y)
elif command -v zypper >/dev/null 2>&1; then
PM="zypper"
INSTALL_CMD="zypper install -y"
INSTALL_CMD=(zypper install -y)
elif command -v apk >/dev/null 2>&1; then
PM="apk"
INSTALL_CMD=(apk add)
else
echo "Unsupported package manager."
echo "Error: Unsupported or no package manager detected." >&2
exit 1
fi

echo "Detected package manager: $PM"

if $DRY_RUN; then
echo "[DRY RUN] sudo ${INSTALL_CMD[*]} $PACKAGE"
exit 0
fi

if $AUTOYES; then
sudo "$INSTALL_CMD" "$PACKAGE"
sudo "${INSTALL_CMD[@]}" "$PACKAGE"
else
read -r -p "Proceed to install '$PACKAGE' using $PM? [y/N] " resp
case "$resp" in
y|Y|yes|YES) sudo "$INSTALL_CMD" "$PACKAGE" ;;
*) echo "Installation aborted."; exit 0 ;;
y|Y|yes|YES)
sudo "${INSTALL_CMD[@]}" "$PACKAGE"
;;
*)
echo "Installation aborted."
exit 0
;;
esac
fi
54 changes: 36 additions & 18 deletions scripts/packages/package-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,61 @@ set -euo pipefail

show_help() {
cat <<'EOF'
Usage: $(basename "$0") [options] <package_name>
Usage: package-info.sh [options] <package_name>

Options:
-h Show this help message and exit
-h, --help Show this help message and exit

Shows detailed information about the specified package using the detected
package manager. The script does not modify the system.
Description:
Shows detailed information about the specified package using the detected
package manager (pacman, apt, dnf, zypper, apk).
EOF
exit 0
}

# Parse options
while getopts "h" opt; do
case "$opt" in
h) show_help ;;
*) show_help ;;
PKG=""

while (( "$#" )); do
case "$1" in
-h|--help)
show_help
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*)
if [[ -z "$PKG" ]]; then
PKG="$1"
else
echo "Error: Unexpected additional argument: $1" >&2
exit 1
fi
;;
esac
shift
done

shift $((OPTIND-1))

if [[ $# -lt 1 ]]; then
echo "Error: package name required."
show_help
if [[ -z "$PKG" ]]; then
echo "Error: package name required." >&2
echo "Run '$0 --help' for usage." >&2
exit 1
fi

PKG="$1"

if command -v pacman >/dev/null 2>&1; then
pacman -Qi "$PKG"
# Try local query first, fallback to sync database if not installed
pacman -Qi "$PKG" 2>/dev/null || pacman -Si "$PKG"
elif command -v apt >/dev/null 2>&1; then
apt show "$PKG"
elif command -v apt-cache >/dev/null 2>&1; then
apt-cache show "$PKG"
elif command -v dnf >/dev/null 2>&1; then
dnf info "$PKG"
elif command -v zypper >/dev/null 2>&1; then
zypper info "$PKG"
elif command -v apk >/dev/null 2>&1; then
apk info -d "$PKG"
else
echo "Unsupported package manager."
echo "Error: Unsupported or no package manager detected." >&2
exit 1
fi
30 changes: 21 additions & 9 deletions scripts/packages/package-manager-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ set -euo pipefail

show_help() {
cat <<'EOF'
Usage: $(basename "$0") [options]
Usage: package-manager-info.sh [options]

Options:
-h Show this help message and exit
-h, --help Show this help message and exit

Detects the system's package manager (pacman, apt, dnf, zypper) and prints
basic information about it (name, version, and a brief description).
Description:
Detects the system's package manager (pacman, apt, dnf, zypper, apk)
and prints basic information about it (name and version).
EOF
exit 0
}

while getopts "h" opt; do
case "$opt" in
h) show_help ;;
*) show_help ;;
for arg in "$@"; do
case "$arg" in
-h|--help)
show_help
;;
*)
echo "Error: Unknown option: $arg" >&2
exit 1
;;
esac
done

Expand All @@ -27,13 +33,19 @@ if command -v pacman >/dev/null 2>&1; then
elif command -v apt >/dev/null 2>&1; then
echo "Package manager: apt (Debian/Ubuntu)"
apt --version | head -n1
elif command -v apt-get >/dev/null 2>&1; then
echo "Package manager: apt-get (Debian/Ubuntu)"
apt-get --version | head -n1
elif command -v dnf >/dev/null 2>&1; then
echo "Package manager: dnf (Fedora/RHEL)"
dnf --version | head -n1
elif command -v zypper >/dev/null 2>&1; then
echo "Package manager: zypper (openSUSE)"
zypper --version | head -n1
elif command -v apk >/dev/null 2>&1; then
echo "Package manager: apk (Alpine Linux)"
apk --version | head -n1
else
echo "No supported package manager detected."
echo "Error: No supported package manager detected." >&2
exit 1
fi
91 changes: 64 additions & 27 deletions scripts/packages/remove-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,102 @@ set -euo pipefail

show_help() {
cat <<'EOF'
Usage: $(basename "$0") [options] <package_name>
Usage: remove-package.sh [options] <package_name>

Options:
-h Show this help message and exit
-y Automatically answer yes to any prompts (use with caution)
-h, --help Show this help message and exit
-y, --yes Automatically answer yes to any prompts
-n, --dry-run Show the command that would be run without removing

Removes the specified package using the detected package manager.
The script will prompt for confirmation unless -y is provided.
Description:
Removes the specified package using the detected package manager
(pacman, apt, dnf, zypper, apk). Prompts for confirmation unless
-y or --yes is provided.
EOF
exit 0
}

# Default values
AUTOYES=false
DRY_RUN=false
PACKAGE=""

# Parse options
while getopts "hy" opt; do
case "$opt" in
h) show_help ;;
y) AUTOYES=true ;;
*) show_help ;;
while (( "$#" )); do
case "$1" in
-h|--help)
show_help
;;
-y|--yes)
AUTOYES=true
;;
-n|--dry-run)
DRY_RUN=true
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*)
if [[ -z "$PACKAGE" ]]; then
PACKAGE="$1"
else
echo "Error: Unexpected additional argument: $1" >&2
exit 1
fi
;;
esac
shift
done

shift $((OPTIND -1))

if [[ $# -lt 1 ]]; then
echo "Error: package name required."
show_help
if [[ -z "$PACKAGE" ]]; then
echo "Error: package name required." >&2
echo "Run '$0 --help' for usage." >&2
exit 1
fi

PACKAGE="$1"
declare -a REMOVE_CMD=()
PM=""

# Detect package manager
if command -v pacman >/dev/null 2>&1; then
PM="pacman"
REMOVE_CMD="pacman -R --noconfirm"
REMOVE_CMD=(pacman -R --noconfirm)
elif command -v apt-get >/dev/null 2>&1; then
PM="apt"
REMOVE_CMD=(apt-get remove -y)
elif command -v apt >/dev/null 2>&1; then
PM="apt"
REMOVE_CMD="apt remove -y"
REMOVE_CMD=(apt remove -y)
elif command -v dnf >/dev/null 2>&1; then
PM="dnf"
REMOVE_CMD="dnf remove -y"
REMOVE_CMD=(dnf remove -y)
elif command -v zypper >/dev/null 2>&1; then
PM="zypper"
REMOVE_CMD="zypper remove -y"
REMOVE_CMD=(zypper remove -y)
elif command -v apk >/dev/null 2>&1; then
PM="apk"
REMOVE_CMD=(apk del)
else
echo "Unsupported package manager."
echo "Error: Unsupported or no package manager detected." >&2
exit 1
fi

echo "Detected package manager: $PM"

if $DRY_RUN; then
echo "[DRY RUN] sudo ${REMOVE_CMD[*]} $PACKAGE"
exit 0
fi

if $AUTOYES; then
sudo "$REMOVE_CMD" "$PACKAGE"
sudo "${REMOVE_CMD[@]}" "$PACKAGE"
else
read -r -p "Proceed to remove '$PACKAGE' using $PM? [y/N] " resp
case "$resp" in
y|Y|yes|YES) sudo "$REMOVE_CMD" "$PACKAGE" ;;
*) echo "Removal aborted."; exit 0 ;;
y|Y|yes|YES)
sudo "${REMOVE_CMD[@]}" "$PACKAGE"
;;
*)
echo "Removal aborted."
exit 0
;;
esac
fi
Loading
Loading