Skip to content

Instantly share code, notes, and snippets.

@tamld
Last active April 29, 2025 03:18
Show Gist options
  • Save tamld/c5e1bb403b6756e16e9e766fb2b6a95c to your computer and use it in GitHub Desktop.
Save tamld/c5e1bb403b6756e16e9e766fb2b6a95c to your computer and use it in GitHub Desktop.
Install Packages App
#!/usr/bin/env bash
set -euo pipefail
### === Detect Privilege === ###
if [[ "$(id -u)" -eq 0 ]]; then
CMD_PREFIX=""
else
CMD_PREFIX="sudo"
fi
APT_CMD="$CMD_PREFIX apt-get"
export DEBIAN_FRONTEND=noninteractive
### === Define Packages === ###
COMMON_PACKAGES=(
iperf3 openssh-server tree iperf rsync
curl nano bat neovim wget aria2
net-tools apache2-utils git jq neofetch
p7zip-full htop btop unzip fd-find ripgrep
duf tldr zoxide fzf micro
yq httpie glow
)
### === Install Common Packages === ###
echo "πŸ“¦ Installing base packages..."
$APT_CMD update -qq
for pkg in "${COMMON_PACKAGES[@]}"; do
if apt-cache show "$pkg" &>/dev/null; then
$APT_CMD install -y "$pkg"
else
echo "⚠️ Package '$pkg' not available in this distro version. Skipping."
fi
done
### === Function: Install SOPS === ###
install_sops() {
if command -v sops &>/dev/null; then
echo "πŸ” SOPS already installed at $(which sops)"
return
fi
echo "πŸ” Installing SOPS..."
SOPS_VERSION=$(curl -s https://api.github.com/repos/getsops/sops/releases/latest \
| grep tag_name | cut -d '"' -f 4)
TMP_DEB="/tmp/sops_${SOPS_VERSION#v}_amd64.deb"
curl -L -o "$TMP_DEB" "https://github.com/getsops/sops/releases/download/${SOPS_VERSION}/sops_${SOPS_VERSION#v}_amd64.deb"
$CMD_PREFIX dpkg -i "$TMP_DEB"
rm -f "$TMP_DEB"
if command -v sops &>/dev/null; then
echo "βœ… SOPS installed successfully: $(which sops)"
else
echo "⚠️ SOPS installation failed or not in PATH"
fi
}
### === Function: Install exa or eza depending on OS version === ###
get_latest_exa_url() {
local version
version=$(curl -s https://api.github.com/repos/ogham/exa/releases/latest \
| grep tag_name | cut -d '"' -f 4)
echo "https://github.com/ogham/exa/releases/download/${version}/exa-linux-x86_64-${version}.zip"
}
install_exa_or_eza() {
if command -v exa &>/dev/null || command -v eza &>/dev/null; then
echo "πŸ“¦ exa or eza already installed. Skipping."
return
fi
if [[ -f /etc/os-release ]]; then
. /etc/os-release
version="$VERSION_ID"
if [[ "$ID" == "ubuntu" ]]; then
if [[ "$version" < "22.10" ]]; then
EXA_URL=$(get_latest_exa_url)
echo "πŸ“¦ Downloading latest exa from: $EXA_URL"
wget -O /tmp/exa.zip "$EXA_URL"
unzip /tmp/exa.zip -d /tmp/
$CMD_PREFIX mv /tmp/bin/exa /usr/local/bin/exa || true
rm -rf /tmp/exa.zip /tmp/bin
echo "βœ… Installed exa (manual method)"
else
$APT_CMD install -y eza
fi
elif [[ "$ID" == "debian" ]]; then
$APT_CMD install -y exa
fi
fi
}
### === Main Install === ###
install_sops
install_exa_or_eza
echo "βœ… All installations completed successfully."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment