postinstall.sh
This commit is contained in:
parent
61f8e6d43c
commit
4d111f7a94
2 changed files with 497 additions and 337 deletions
477
postinstall.sh
477
postinstall.sh
|
@ -1,92 +1,135 @@
|
||||||
{
|
#!/usr/bin/env bash
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# ╭──────────────╮
|
PACKAGE=postinstallation
|
||||||
# │ dependencies │
|
|
||||||
# ╰──────────────╯
|
|
||||||
deps="7zip bc btop exa fzf gawk gdu git make pv ripgrep rsync stow tmux trash-cli unzip zoxide zsh"
|
|
||||||
|
|
||||||
# ╭─────────────╮
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||||
# │ ENVIRONMENT │
|
command_exists() {
|
||||||
# ╰─────────────╯
|
command -v "$@" >/dev/null 2>&1
|
||||||
# ANSI color codes
|
}
|
||||||
RED='\033[0;31m'
|
|
||||||
CYAN='\033[0;36m'
|
|
||||||
YELLOW='\033[0;33m'
|
|
||||||
LIGHT_GREEN='\033[0;92m'
|
|
||||||
BOLD='\033[1m'
|
|
||||||
NC='\033[0m'
|
|
||||||
|
|
||||||
# Initialize storage variables
|
# if command_exists "$PACKAGE"; then
|
||||||
_STORED_ERRORS=""
|
# echo_warning "$PACKAGE is already installed!"
|
||||||
_STORED_WARNINGS=""
|
# echo_warning "Exiting now!"
|
||||||
_STORED_INFOS=""
|
# exit 69
|
||||||
_STORED_NOTES=""
|
# fi
|
||||||
|
|
||||||
# Modified echo functions that store and display messages
|
# WHY:
|
||||||
echo_error() {
|
# This import will give you the following variables:
|
||||||
message="${RED}$1${NC}\n"
|
# _sudo="sudo -E" <- only if non root user
|
||||||
printf "$message" >&2
|
# distro = <distro name, like 'arch', 'debian', 'fedora'..>
|
||||||
_STORED_ERRORS="${_STORED_ERRORS}${message}"
|
# arch = bool
|
||||||
}
|
# fedora = bool
|
||||||
|
# opensuse = bool....
|
||||||
echo_warning() {
|
# You can then use it for, `if $arch; then`
|
||||||
message="${YELLOW}$1${NC}\n"
|
# Also this gives you the _install and _remove command, which installs/removes a package pased on the packagemanager/distro used.
|
||||||
printf "$message"
|
# CAUTION:
|
||||||
_STORED_WARNINGS="${_STORED_WARNINGS}${message}"
|
# This only works for generic package names, like neovim, or vim, or tmux etc..
|
||||||
}
|
# not every package packagemanager has the same packagenames for their packages..
|
||||||
|
getImports() {
|
||||||
echo_info() {
|
local url="https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh"
|
||||||
message="${CYAN}$1${NC}\n"
|
local import="$(mktemp)"
|
||||||
printf "$message"
|
if command_exists curl; then
|
||||||
_STORED_INFOS="${_STORED_INFOS}${message}"
|
curl -fsSL $url -o $import
|
||||||
}
|
elif command_exists wget; then
|
||||||
|
wget -o $import $url
|
||||||
echo_note() {
|
|
||||||
message="${LIGHT_GREEN}$1${NC}\n"
|
|
||||||
printf "$message"
|
|
||||||
_STORED_NOTES="${_STORED_NOTES}${message}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
|
||||||
command_exists() {
|
|
||||||
command -v "$@" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
# ─────────────────────────────────────< get packager >─────────────────────────────────────
|
|
||||||
checkPkg() {
|
|
||||||
pkger=""
|
|
||||||
for pkg in apt-get dnf pacman apk zypper; do
|
|
||||||
if command_exists $pkg; then
|
|
||||||
printf "Using ${RED}${pkg}${NC} method.."
|
|
||||||
pkger="$pkg"
|
|
||||||
|
|
||||||
# break
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# ─────────────────────────────────< check for root/sudo >───────────────────────────────
|
|
||||||
# checkRoot() {
|
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
|
||||||
if command_exists sudo; then
|
|
||||||
echo_info "User is not root. Using sudo for privileged operations."
|
|
||||||
_sudo="sudo -E"
|
|
||||||
else
|
|
||||||
echo_error "No sudo found and you're not root! Can't install packages."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo_info "Root access confirmed."
|
echo "curl/wget is required, but missing.."
|
||||||
_sudo=""
|
exit 69
|
||||||
fi
|
fi
|
||||||
# }
|
|
||||||
|
|
||||||
# ╭─────╮
|
source "$import"
|
||||||
# │ apt │
|
sleep 0.2
|
||||||
# ╰─────╯
|
rm "$import"
|
||||||
aptCommentCDinSources() {
|
}
|
||||||
|
|
||||||
|
getDependencies() {
|
||||||
|
echo_info "Checking build dependencies.."
|
||||||
|
|
||||||
|
# INFO:
|
||||||
|
# ╭─────────────────────────────────────────────────────────────────────────╮
|
||||||
|
# │ You can define dependencies for various linux distros here. It will │
|
||||||
|
# │ automagically be pulled via the $pkgArray[$distro] variable │
|
||||||
|
# ╰─────────────────────────────────────────────────────────────────────────╯
|
||||||
|
generalDeps=(
|
||||||
|
"awk"
|
||||||
|
"7zip"
|
||||||
|
"bc"
|
||||||
|
"btop"
|
||||||
|
"curl"
|
||||||
|
"fzf"
|
||||||
|
"gawk"
|
||||||
|
"git"
|
||||||
|
"keychain"
|
||||||
|
"make"
|
||||||
|
"pv"
|
||||||
|
"ripgrep"
|
||||||
|
"rsync"
|
||||||
|
"stow"
|
||||||
|
"sudo"
|
||||||
|
"unzip"
|
||||||
|
"vi"
|
||||||
|
"zsh"
|
||||||
|
"zoxide"
|
||||||
|
)
|
||||||
|
|
||||||
|
generalBloat=(
|
||||||
|
"nano"
|
||||||
|
)
|
||||||
|
|
||||||
|
depsDebian=()
|
||||||
|
depsFedora=()
|
||||||
|
depsOpensuse=()
|
||||||
|
depsArch=(
|
||||||
|
"tldr"
|
||||||
|
"oh-my-posh"
|
||||||
|
)
|
||||||
|
depsAlpine=()
|
||||||
|
|
||||||
|
declare -A deps=(
|
||||||
|
[debian]="depsDebian"
|
||||||
|
[ubuntu]="depsUbuntu"
|
||||||
|
[fedora]="depsFedora"
|
||||||
|
[arch]="depsArch"
|
||||||
|
[alpine]="depsAlpine"
|
||||||
|
[opensuse]="depsOpensuse"
|
||||||
|
)
|
||||||
|
|
||||||
|
# INFO:
|
||||||
|
# ╭────────────────────────────────────────────────────────────────╮
|
||||||
|
# │ This variable stores the packages you provided for each distro │
|
||||||
|
# ╰────────────────────────────────────────────────────────────────╯
|
||||||
|
declare -n pkgArray="${deps[$distro]}"
|
||||||
|
|
||||||
|
case "$distro" in
|
||||||
|
debian | ubuntu | arch | fedora | alpine | opensuse)
|
||||||
|
|
||||||
|
echo_info "Installing base packages.."
|
||||||
|
checkAndInstall "${pkgArray[@]}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo_error "There are no dependencies to install for $distro"
|
||||||
|
return 69
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
removeBloat() {
|
||||||
|
if ! $arch; then
|
||||||
|
echo_info "Removing bloat.."
|
||||||
|
_remove "${generalBloat[@]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
|
||||||
|
# Getting general dependencies
|
||||||
|
getDependencies
|
||||||
|
|
||||||
|
# removing 'bloat'
|
||||||
|
removeBloat
|
||||||
|
|
||||||
|
case "$distro" in
|
||||||
|
debian)
|
||||||
# Path to sources.list
|
# Path to sources.list
|
||||||
sources_file="/etc/apt/sources.list"
|
sources_file="/etc/apt/sources.list"
|
||||||
|
|
||||||
|
@ -99,259 +142,19 @@
|
||||||
# Comment out CD-ROM entries using sudo
|
# Comment out CD-ROM entries using sudo
|
||||||
$_sudo sed -i 's/^[[:space:]]*deb[[:space:]]\+cdrom:/#&/' "$sources_file"
|
$_sudo sed -i 's/^[[:space:]]*deb[[:space:]]\+cdrom:/#&/' "$sources_file"
|
||||||
echo_info "CD-ROM entries have been commented out in $sources_file"
|
echo_info "CD-ROM entries have been commented out in $sources_file"
|
||||||
}
|
;;
|
||||||
|
esac
|
||||||
aptBase() {
|
|
||||||
aptCommentCDinSources
|
|
||||||
echo_info "Updating sources.."
|
|
||||||
$_sudo apt update
|
|
||||||
|
|
||||||
if ! command_exists sudo; then
|
|
||||||
echo_note "Installing sudo"
|
|
||||||
apt install sudo --assume-yes
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo_note "Installing base packages: $deps"
|
|
||||||
|
|
||||||
for _deps in $deps; do
|
|
||||||
if ! command_exists "$_deps"; then
|
|
||||||
echo_info "Installing $_deps.."
|
|
||||||
if ! $_sudo apt install "$_deps" --assume-yes; then
|
|
||||||
echo_error "$_deps - failed to install!"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo_note "$_deps - was already installed!"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
aptOptimize() {
|
|
||||||
if command_exists nala; then
|
|
||||||
echo_info "Nala is already present, fetching mirros now! (This might take a minute or two, depending on your internet speed)"
|
|
||||||
$_sudo nala fetch --auto --assume-yes --https-only
|
|
||||||
else
|
|
||||||
echo_note "Nala is not installed on the system, do you want to install it now? (Y/n): "
|
|
||||||
read -r inst_nala </dev/tty
|
|
||||||
case "$inst_nala" in
|
|
||||||
N | n)
|
|
||||||
echo_warning "All right, continue without nala!"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo_note "Installing nala.."
|
|
||||||
$_sudo apt install nala --assume-yes &&
|
|
||||||
echo_info "Fetching best mirrors"
|
|
||||||
$_sudo nala fetch --auto --assume-yes --https-only
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭────────╮
|
|
||||||
# │ pacman │
|
|
||||||
# ╰────────╯
|
|
||||||
|
|
||||||
pacmanBase() {
|
|
||||||
if command_exists nano; then
|
|
||||||
if command_exists vim; then
|
|
||||||
echo_note "Removing nano, vim is backup"
|
|
||||||
$_sudo pacman -R nano --noconfirm
|
|
||||||
else
|
|
||||||
echo_note "Removing nano and installing vim as a backup"
|
|
||||||
$_sudo pacman -S vim --noconfirm
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
$_sudo pacman -S base-devel --noconfirm
|
|
||||||
|
|
||||||
echo_note "Installing base packages: $deps"
|
|
||||||
|
|
||||||
for _deps in $deps; do
|
|
||||||
if ! command_exists "$_deps"; then
|
|
||||||
if ! $_sudo pacman -S "$_deps" --noconfirm; then
|
|
||||||
echo_error "$_deps - failed to install"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo_note "$_deps - was already installed"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭─────╮
|
|
||||||
# │ dnf │
|
|
||||||
# ╰─────╯
|
|
||||||
dnfBase() {
|
|
||||||
echo_info "Updating sources.."
|
|
||||||
if ! $_sudo dnf update; then
|
|
||||||
echo_error "Maybe you need a proxy?"
|
|
||||||
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo_note "Installing base packages: $deps"
|
|
||||||
|
|
||||||
for _deps in $deps; do
|
|
||||||
if ! command_exists "$_deps"; then
|
|
||||||
echo_info "Installing $_deps.."
|
|
||||||
if ! $_sudo dnf install "$_deps"; then
|
|
||||||
echo_error "$_deps - failed to install!"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo_note "$_deps - was already installed!"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭────────╮
|
|
||||||
# │ zypper │
|
|
||||||
# ╰────────╯
|
|
||||||
zypperBase() {
|
|
||||||
echo_info "Updating sources.."
|
|
||||||
if ! $_sudo zypper ref; then
|
|
||||||
echo_error "Maybe you need a proxy?"
|
|
||||||
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo_note "Installing base packages: $deps"
|
|
||||||
|
|
||||||
for _deps in $deps; do
|
|
||||||
if ! command_exists "$_deps"; then
|
|
||||||
echo_info "Installing $_deps.."
|
|
||||||
if ! $_sudo zypper in "$_deps"; then
|
|
||||||
echo_error "$_deps - failed to install!"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo_note "$_deps - was already installed!"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭───────────╮
|
|
||||||
# │ FUNCTIONS │
|
|
||||||
# ╰───────────╯
|
|
||||||
|
|
||||||
# envCheck() {
|
|
||||||
# checkRoot
|
|
||||||
# checkPkg
|
|
||||||
# }
|
|
||||||
|
|
||||||
install_base() {
|
|
||||||
if ! checkPkg; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo_info "Installing base packages..."
|
|
||||||
case "$pkger" in
|
|
||||||
apt-get)
|
|
||||||
echo_info "apt-get"
|
|
||||||
aptBase
|
|
||||||
;;
|
|
||||||
dnf)
|
|
||||||
echo_info "dnf"
|
|
||||||
dnfBase
|
|
||||||
;;
|
|
||||||
pacman)
|
|
||||||
echo_info "pacman"
|
|
||||||
pacmanBase
|
|
||||||
;;
|
|
||||||
zypper)
|
|
||||||
echo_info "zypper"
|
|
||||||
zypperBase
|
|
||||||
;;
|
|
||||||
apk) ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
optimize_os() {
|
|
||||||
if ! checkPkg; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo_info "Running OS optimizations..."
|
|
||||||
|
|
||||||
# debug
|
|
||||||
echo_error "PCK=$pkg PKGER=$pkger"
|
|
||||||
case "$pkg" in
|
|
||||||
apt-get)
|
|
||||||
aptOptimize
|
|
||||||
;;
|
|
||||||
dnf)
|
|
||||||
echo_warning "Currently, there are no optimizations for the fedora distribution."
|
|
||||||
;;
|
|
||||||
pacman)
|
|
||||||
echo_warning "Currently, there are no optimizations for the arch distribution."
|
|
||||||
;;
|
|
||||||
zypper)
|
|
||||||
echo_warning "Currently, there are no optimizations for the openSUSE distribution."
|
|
||||||
;;
|
|
||||||
apk)
|
|
||||||
echo_warning "Currently, there are no optimizations for the Alpine distribution."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# setup_vpn() {
|
|
||||||
# echo_info "Setting up VPN..."
|
|
||||||
# # Add VPN setup logic here
|
|
||||||
# }
|
|
||||||
|
|
||||||
# ╭──────────╮
|
|
||||||
# │ ARGUMENTS │
|
|
||||||
# ╰──────────╯
|
|
||||||
show_help() {
|
|
||||||
echo "Usage: $0 [OPTIONS]"
|
|
||||||
echo " --install-base Install base packages"
|
|
||||||
echo " --optimize-os Optimize the OS"
|
|
||||||
echo " --all Uses all flags together"
|
|
||||||
# echo " --setup-vpn Setup VPN"
|
|
||||||
echo " --help Show this help message"
|
|
||||||
echo ""
|
|
||||||
echo "If you 'curl | sh' this script, then replace 'sh' with 'sh -s -- [OPTIONS]'"
|
|
||||||
printf "So for example ${CYAN} curl https://path/to/postinstall.sh | sh -s -- --all ${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Default to no options
|
|
||||||
INSTALL_BASE=false
|
|
||||||
OPTIMIZE_OS=false
|
|
||||||
# SETUP_VPN=false
|
|
||||||
|
|
||||||
# Parse command-line arguments
|
|
||||||
while [ "$#" -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
--install-base)
|
|
||||||
INSTALL_BASE=true
|
|
||||||
;;
|
|
||||||
--optimize-os)
|
|
||||||
OPTIMIZE_OS=true
|
|
||||||
;;
|
|
||||||
--all)
|
|
||||||
OPTIMIZE_OS=true
|
|
||||||
INSTALL_BASE=true
|
|
||||||
;;
|
|
||||||
# --setup-vpn)
|
|
||||||
# SETUP_VPN=true
|
|
||||||
# ;;
|
|
||||||
--help)
|
|
||||||
show_help
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo_error "Unknown option: $1"
|
|
||||||
show_help
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
# Execute selected options
|
|
||||||
$OPTIMIZE_OS && optimize_os
|
|
||||||
$INSTALL_BASE && install_base
|
|
||||||
# $SETUP_VPN && setup_vpn
|
|
||||||
|
|
||||||
# If no options were provided, show help
|
|
||||||
if [ "$INSTALL_BASE" = false ] && [ "$OPTIMIZE_OS" = false ]; then # && [ "$SETUP_VPN" = false ]; then
|
|
||||||
show_help
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if getImports; then
|
||||||
|
case "$@" in
|
||||||
|
--silent | -s)
|
||||||
|
silent=true
|
||||||
|
echo_warning "Running script silently!"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
silent=false
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
main
|
||||||
|
fi
|
||||||
|
|
357
postinstall2.sh
Normal file
357
postinstall2.sh
Normal file
|
@ -0,0 +1,357 @@
|
||||||
|
{
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# ╭──────────────╮
|
||||||
|
# │ dependencies │
|
||||||
|
# ╰──────────────╯
|
||||||
|
deps="7zip bc btop exa fzf gawk gdu git make pv ripgrep rsync stow tmux trash-cli unzip zoxide zsh"
|
||||||
|
|
||||||
|
# ╭─────────────╮
|
||||||
|
# │ ENVIRONMENT │
|
||||||
|
# ╰─────────────╯
|
||||||
|
# ANSI color codes
|
||||||
|
RED='\033[0;31m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
YELLOW='\033[0;33m'
|
||||||
|
LIGHT_GREEN='\033[0;92m'
|
||||||
|
BOLD='\033[1m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Initialize storage variables
|
||||||
|
_STORED_ERRORS=""
|
||||||
|
_STORED_WARNINGS=""
|
||||||
|
_STORED_INFOS=""
|
||||||
|
_STORED_NOTES=""
|
||||||
|
|
||||||
|
# Modified echo functions that store and display messages
|
||||||
|
echo_error() {
|
||||||
|
message="${RED}$1${NC}\n"
|
||||||
|
printf "$message" >&2
|
||||||
|
_STORED_ERRORS="${_STORED_ERRORS}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_warning() {
|
||||||
|
message="${YELLOW}$1${NC}\n"
|
||||||
|
printf "$message"
|
||||||
|
_STORED_WARNINGS="${_STORED_WARNINGS}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_info() {
|
||||||
|
message="${CYAN}$1${NC}\n"
|
||||||
|
printf "$message"
|
||||||
|
_STORED_INFOS="${_STORED_INFOS}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_note() {
|
||||||
|
message="${LIGHT_GREEN}$1${NC}\n"
|
||||||
|
printf "$message"
|
||||||
|
_STORED_NOTES="${_STORED_NOTES}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||||
|
command_exists() {
|
||||||
|
command -v "$@" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# ─────────────────────────────────────< get packager >─────────────────────────────────────
|
||||||
|
checkPkg() {
|
||||||
|
pkger=""
|
||||||
|
for pkg in apt-get dnf pacman apk zypper; do
|
||||||
|
if command_exists $pkg; then
|
||||||
|
printf "Using ${RED}${pkg}${NC} method.."
|
||||||
|
pkger="$pkg"
|
||||||
|
|
||||||
|
# break
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# ─────────────────────────────────< check for root/sudo >───────────────────────────────
|
||||||
|
# checkRoot() {
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
if command_exists sudo; then
|
||||||
|
echo_info "User is not root. Using sudo for privileged operations."
|
||||||
|
_sudo="sudo -E"
|
||||||
|
else
|
||||||
|
echo_error "No sudo found and you're not root! Can't install packages."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_info "Root access confirmed."
|
||||||
|
_sudo=""
|
||||||
|
fi
|
||||||
|
# }
|
||||||
|
|
||||||
|
# ╭─────╮
|
||||||
|
# │ apt │
|
||||||
|
# ╰─────╯
|
||||||
|
aptCommentCDinSources() {
|
||||||
|
# Path to sources.list
|
||||||
|
sources_file="/etc/apt/sources.list"
|
||||||
|
|
||||||
|
# Check if file exists
|
||||||
|
if [ ! -f "$sources_file" ]; then
|
||||||
|
echo_error "Error: $sources_file not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Comment out CD-ROM entries using sudo
|
||||||
|
$_sudo sed -i 's/^[[:space:]]*deb[[:space:]]\+cdrom:/#&/' "$sources_file"
|
||||||
|
echo_info "CD-ROM entries have been commented out in $sources_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
aptBase() {
|
||||||
|
aptCommentCDinSources
|
||||||
|
echo_info "Updating sources.."
|
||||||
|
$_sudo apt update
|
||||||
|
|
||||||
|
if ! command_exists sudo; then
|
||||||
|
echo_note "Installing sudo"
|
||||||
|
apt install sudo --assume-yes
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo_note "Installing base packages: $deps"
|
||||||
|
|
||||||
|
for _deps in $deps; do
|
||||||
|
if ! command_exists "$_deps"; then
|
||||||
|
echo_info "Installing $_deps.."
|
||||||
|
if ! $_sudo apt install "$_deps" --assume-yes; then
|
||||||
|
echo_error "$_deps - failed to install!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_note "$_deps - was already installed!"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
aptOptimize() {
|
||||||
|
if command_exists nala; then
|
||||||
|
echo_info "Nala is already present, fetching mirros now! (This might take a minute or two, depending on your internet speed)"
|
||||||
|
$_sudo nala fetch --auto --assume-yes --https-only
|
||||||
|
else
|
||||||
|
echo_note "Nala is not installed on the system, do you want to install it now? (Y/n): "
|
||||||
|
read -r inst_nala </dev/tty
|
||||||
|
case "$inst_nala" in
|
||||||
|
N | n)
|
||||||
|
echo_warning "All right, continue without nala!"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo_note "Installing nala.."
|
||||||
|
$_sudo apt install nala --assume-yes &&
|
||||||
|
echo_info "Fetching best mirrors"
|
||||||
|
$_sudo nala fetch --auto --assume-yes --https-only
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ╭────────╮
|
||||||
|
# │ pacman │
|
||||||
|
# ╰────────╯
|
||||||
|
|
||||||
|
pacmanBase() {
|
||||||
|
if command_exists nano; then
|
||||||
|
if command_exists vim; then
|
||||||
|
echo_note "Removing nano, vim is backup"
|
||||||
|
$_sudo pacman -R nano --noconfirm
|
||||||
|
else
|
||||||
|
echo_note "Removing nano and installing vim as a backup"
|
||||||
|
$_sudo pacman -S vim --noconfirm
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
$_sudo pacman -S base-devel --noconfirm
|
||||||
|
|
||||||
|
echo_note "Installing base packages: $deps"
|
||||||
|
|
||||||
|
for _deps in $deps; do
|
||||||
|
if ! command_exists "$_deps"; then
|
||||||
|
if ! $_sudo pacman -S "$_deps" --noconfirm; then
|
||||||
|
echo_error "$_deps - failed to install"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_note "$_deps - was already installed"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# ╭─────╮
|
||||||
|
# │ dnf │
|
||||||
|
# ╰─────╯
|
||||||
|
dnfBase() {
|
||||||
|
echo_info "Updating sources.."
|
||||||
|
if ! $_sudo dnf update; then
|
||||||
|
echo_error "Maybe you need a proxy?"
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo_note "Installing base packages: $deps"
|
||||||
|
|
||||||
|
for _deps in $deps; do
|
||||||
|
if ! command_exists "$_deps"; then
|
||||||
|
echo_info "Installing $_deps.."
|
||||||
|
if ! $_sudo dnf install "$_deps"; then
|
||||||
|
echo_error "$_deps - failed to install!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_note "$_deps - was already installed!"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# ╭────────╮
|
||||||
|
# │ zypper │
|
||||||
|
# ╰────────╯
|
||||||
|
zypperBase() {
|
||||||
|
echo_info "Updating sources.."
|
||||||
|
if ! $_sudo zypper ref; then
|
||||||
|
echo_error "Maybe you need a proxy?"
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo_note "Installing base packages: $deps"
|
||||||
|
|
||||||
|
for _deps in $deps; do
|
||||||
|
if ! command_exists "$_deps"; then
|
||||||
|
echo_info "Installing $_deps.."
|
||||||
|
if ! $_sudo zypper in "$_deps"; then
|
||||||
|
echo_error "$_deps - failed to install!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_note "$_deps - was already installed!"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# ╭───────────╮
|
||||||
|
# │ FUNCTIONS │
|
||||||
|
# ╰───────────╯
|
||||||
|
|
||||||
|
# envCheck() {
|
||||||
|
# checkRoot
|
||||||
|
# checkPkg
|
||||||
|
# }
|
||||||
|
|
||||||
|
install_base() {
|
||||||
|
if ! checkPkg; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo_info "Installing base packages..."
|
||||||
|
case "$pkger" in
|
||||||
|
apt-get)
|
||||||
|
echo_info "apt-get"
|
||||||
|
aptBase
|
||||||
|
;;
|
||||||
|
dnf)
|
||||||
|
echo_info "dnf"
|
||||||
|
dnfBase
|
||||||
|
;;
|
||||||
|
pacman)
|
||||||
|
echo_info "pacman"
|
||||||
|
pacmanBase
|
||||||
|
;;
|
||||||
|
zypper)
|
||||||
|
echo_info "zypper"
|
||||||
|
zypperBase
|
||||||
|
;;
|
||||||
|
apk) ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
optimize_os() {
|
||||||
|
if ! checkPkg; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo_info "Running OS optimizations..."
|
||||||
|
|
||||||
|
# debug
|
||||||
|
echo_error "PCK=$pkg PKGER=$pkger"
|
||||||
|
case "$pkg" in
|
||||||
|
apt-get)
|
||||||
|
aptOptimize
|
||||||
|
;;
|
||||||
|
dnf)
|
||||||
|
echo_warning "Currently, there are no optimizations for the fedora distribution."
|
||||||
|
;;
|
||||||
|
pacman)
|
||||||
|
echo_warning "Currently, there are no optimizations for the arch distribution."
|
||||||
|
;;
|
||||||
|
zypper)
|
||||||
|
echo_warning "Currently, there are no optimizations for the openSUSE distribution."
|
||||||
|
;;
|
||||||
|
apk)
|
||||||
|
echo_warning "Currently, there are no optimizations for the Alpine distribution."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# setup_vpn() {
|
||||||
|
# echo_info "Setting up VPN..."
|
||||||
|
# # Add VPN setup logic here
|
||||||
|
# }
|
||||||
|
|
||||||
|
# ╭──────────╮
|
||||||
|
# │ ARGUMENTS │
|
||||||
|
# ╰──────────╯
|
||||||
|
show_help() {
|
||||||
|
echo "Usage: $0 [OPTIONS]"
|
||||||
|
echo " --install-base Install base packages"
|
||||||
|
echo " --optimize-os Optimize the OS"
|
||||||
|
echo " --all Uses all flags together"
|
||||||
|
# echo " --setup-vpn Setup VPN"
|
||||||
|
echo " --help Show this help message"
|
||||||
|
echo ""
|
||||||
|
echo "If you 'curl | sh' this script, then replace 'sh' with 'sh -s -- [OPTIONS]'"
|
||||||
|
printf "So for example ${CYAN} curl https://path/to/postinstall.sh | sh -s -- --all ${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Default to no options
|
||||||
|
INSTALL_BASE=false
|
||||||
|
OPTIMIZE_OS=false
|
||||||
|
# SETUP_VPN=false
|
||||||
|
|
||||||
|
# Parse command-line arguments
|
||||||
|
while [ "$#" -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--install-base)
|
||||||
|
INSTALL_BASE=true
|
||||||
|
;;
|
||||||
|
--optimize-os)
|
||||||
|
OPTIMIZE_OS=true
|
||||||
|
;;
|
||||||
|
--all)
|
||||||
|
OPTIMIZE_OS=true
|
||||||
|
INSTALL_BASE=true
|
||||||
|
;;
|
||||||
|
# --setup-vpn)
|
||||||
|
# SETUP_VPN=true
|
||||||
|
# ;;
|
||||||
|
--help)
|
||||||
|
show_help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo_error "Unknown option: $1"
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# Execute selected options
|
||||||
|
$OPTIMIZE_OS && optimize_os
|
||||||
|
$INSTALL_BASE && install_base
|
||||||
|
# $SETUP_VPN && setup_vpn
|
||||||
|
|
||||||
|
# If no options were provided, show help
|
||||||
|
if [ "$INSTALL_BASE" = false ] && [ "$OPTIMIZE_OS" = false ]; then # && [ "$SETUP_VPN" = false ]; then
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue