303 lines
9.9 KiB
Bash
303 lines
9.9 KiB
Bash
{
|
|
#!/usr/bin/env bash
|
|
|
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
|
command_exists() {
|
|
command -v "$@" >/dev/null 2>&1
|
|
}
|
|
|
|
# _arch() {
|
|
# local err
|
|
# # run _install docker docker-compose --noconfirm
|
|
#
|
|
# # spin blue bold "Executing arch.."
|
|
# # sleep 1.3
|
|
#
|
|
# spin bold grey "Executing arch.. installing $PACKAGE"
|
|
# if run --err err check-and-install "docker docker-compose"; then
|
|
# upclear
|
|
# check "Docker was installed"
|
|
# else
|
|
# throw "Could not install docker"
|
|
# echo_error "${err:-}"
|
|
# fi
|
|
# }
|
|
#
|
|
# _debian() {
|
|
# if ! $trixie; then
|
|
# spin bold blue "Executing debian.."
|
|
# if run $_sudo apt-get install -y ca-certificates curl;
|
|
# $_sudo install -m 0755 -d /etc/apt/keyrings
|
|
# $_sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
|
|
# $_sudo chmod a+r /etc/apt/keyrings/docker.asc
|
|
# fi
|
|
# sleep 0.5
|
|
# if [ "$VERSION_CODENAME" == "trixie" ]; then
|
|
# VERSION_CODENAME="bookworm"
|
|
# fi
|
|
# echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
|
|
# $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | $_sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
|
|
#
|
|
# echo_info "Addet repository. Updating and installing now.."
|
|
# sleep 1
|
|
# run $_sudo apt-get update
|
|
# run checkAndInstall "docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
|
# else
|
|
# echo_info "executing trixie.."
|
|
# run _install docker.io docker-compose
|
|
# fi
|
|
# }
|
|
|
|
source-script() {
|
|
local url="$1"
|
|
local import="$(mktemp)"
|
|
|
|
# ─< if $1 is a local file, source this one instead >─────────────────────────────────────
|
|
if [ -f "$url" ]; then
|
|
source "$url"
|
|
sleep 0.1
|
|
return 0
|
|
else
|
|
# ─< if $1 is a url, grab it and source it, also deletes afterwards >─────────────────────
|
|
if command_exists curl; then
|
|
curl -fsSL $url -o $import
|
|
elif command_exists wget; then
|
|
wget -o $import $url
|
|
else
|
|
echo "curl/wget is required, but missing.."
|
|
exit 69
|
|
fi
|
|
|
|
source "$import"
|
|
|
|
echo "${BLUE}Sourcing external script:${NC} $url"
|
|
line
|
|
sleep 0.1
|
|
rm -f "$import"
|
|
fi
|
|
}
|
|
|
|
setup-env() {
|
|
# WHY:
|
|
# This import will give you the following variables:
|
|
# _sudo="sudo -E" <- only if non root user
|
|
# distro = <distro name, like 'arch', 'debian', 'fedora'..>
|
|
# arch = bool
|
|
# fedora = bool
|
|
# opensuse = bool....
|
|
# You can then use it for, `if $arch; then`
|
|
# Also this gives you the _install command, which installs a package pased on the packagemanager/distro used.
|
|
#
|
|
# CAUTION:
|
|
# This only wokrs for generic package names, like neovim, or vim, or tmux etc..
|
|
# not every package packagemanager has the same packagenames for their packages..
|
|
#
|
|
# local beddu=https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh
|
|
# local pika=https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh
|
|
# dream ~= combined beddu and pika
|
|
local dream=https://git.k4li.de/scripts/imports/raw/branch/main/dream.sh
|
|
|
|
if ! command_exists pkg-install && ! command_exists check-and-install && ! command_exists pen; then
|
|
source-script $dream
|
|
fi
|
|
}
|
|
|
|
getDependencies() {
|
|
# INFO:
|
|
# ╭─────────────────────────────────────────────────────────────────────────╮
|
|
# │ You can define dependencies for various linux distros here. It will │
|
|
# │ automagically be pulled via the $pkgArray[$distro] variable │
|
|
# ╰─────────────────────────────────────────────────────────────────────────╯
|
|
if $debian; then
|
|
if $trixie; then
|
|
depsDebian=(docker.io docker-compose)
|
|
else
|
|
depsDebian=(ca-certificates curl)
|
|
fi
|
|
fi
|
|
depsUbuntu=(ca-certificates curl)
|
|
depsFedora=(dnf-plugins-core)
|
|
depsOpensuse=()
|
|
depsArch=(docker docker-compose)
|
|
depsAlpine=()
|
|
|
|
declare -A deps=(
|
|
[debian]="depsDebian"
|
|
[ubuntu]="depsUbuntu"
|
|
[fedora]="depsFedora"
|
|
[opensuse]="depsOpensuse"
|
|
[arch]="depsArch"
|
|
[alpine]="depsAlpine"
|
|
)
|
|
|
|
# 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)
|
|
check-and-install ${pkgArray[@]}
|
|
;;
|
|
*)
|
|
pen bold yellow "There are no dependencies to install for $distro"
|
|
return 69
|
|
;;
|
|
esac
|
|
}
|
|
|
|
#your-script-logic
|
|
init-docker() {
|
|
local USER="${USER:-$(whoami)}"
|
|
if command_exists docker; then
|
|
if confirm "Docker was installed correctly. Do you want to add $USER to the docker group?" </dev/tty; then
|
|
$_sudo usermod -aG docker "$USER"
|
|
fi
|
|
|
|
# spin and run
|
|
spin bold grey "Enabling docker service.."
|
|
if run --err err $_sudo systemctl enable --now docker; then
|
|
upclear
|
|
check "Docker service is enabled!"
|
|
else
|
|
upclear
|
|
throw "Could not setup the service.."
|
|
echo-error "${err:-}"
|
|
fi
|
|
|
|
pen bold gred "$USER is now part of the docker group. Restart your session to enable the changes. Also docker was addet as a service. Should autostart from now on."
|
|
else
|
|
echo-error "Something went wrong!"
|
|
fi
|
|
}
|
|
|
|
inst-docker() {
|
|
local err
|
|
|
|
case "$distro" in
|
|
debian) ;;
|
|
fedora)
|
|
# run $_sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
|
|
# run checkAndInstall "docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
|
;;
|
|
arch)
|
|
spin bold blue "Setting up docker with arch.. easy!"
|
|
if run --err err pkg-install "docker docker-compose"; then
|
|
upclear
|
|
check "Installed docker!"
|
|
else
|
|
upclear
|
|
throw "Error installing docker.."
|
|
fi
|
|
;;
|
|
ubuntu)
|
|
spin bold grey "Setting up $(pen bold blue 'docker-repo')"
|
|
|
|
if $plucky; then
|
|
UBUNTU_CODENAME=jammy
|
|
|
|
upclear
|
|
|
|
sleep 5
|
|
fi
|
|
|
|
if run $_sudo install -m 0755 -d /etc/apt/keyrings; then
|
|
run $_sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc || throw-err
|
|
run $_sudo chmod a+r /etc/apt/keyrings/docker.asc || throw-err
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
|
|
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | $_sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
|
|
|
|
# check "Setup done, going forward.."
|
|
check bold green "Addet repository"
|
|
sleep 2
|
|
upclear
|
|
spin "Installing docker now.."
|
|
if run --err err $_sudo apt-get update; then
|
|
upclear
|
|
|
|
check "Updated repositories.."
|
|
|
|
pen bold blue "Installing docker now.."
|
|
|
|
check-and-install "docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
|
else
|
|
upclear
|
|
throw "Did not install docker correctly.."
|
|
echo-error "${err:-}"
|
|
fi
|
|
fi
|
|
;;
|
|
*)
|
|
pen bold red "Currently not available for $distro!"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main() {
|
|
if $silent; then
|
|
pen yellow "ARG: Executing script silently!"
|
|
fi
|
|
|
|
if ! getDependencies; then
|
|
throw "Error when installing dependencies.."
|
|
fi
|
|
|
|
if inst-docker; then
|
|
init-docker
|
|
fi
|
|
# case "$distro" in
|
|
# arch)
|
|
# echo "arch"
|
|
# ;;
|
|
# debian)
|
|
# echo "debian"
|
|
# ;;
|
|
# ubuntu)
|
|
# echo "ubuntu"
|
|
# ;;
|
|
# fedora)
|
|
# echo "fedora"
|
|
# ;;
|
|
# alpine)
|
|
# echo "alpine"
|
|
# ;;
|
|
# opensuse)
|
|
# echo "opensuse"
|
|
# ;;
|
|
# *)
|
|
# echo "$distro is not supported by this script!"
|
|
# exit 1
|
|
# ;;
|
|
# esac
|
|
}
|
|
|
|
if setup-env; then
|
|
# ─< package variable >───────────────────────────────────────────────────────────────────
|
|
unset PACKAGE
|
|
|
|
# ─< argument list variables >────────────────────────────────────────────────────────────
|
|
silent=false
|
|
|
|
sleep 0.1
|
|
|
|
PACKAGE=packagename
|
|
if command_exists "$PACKAGE"; then
|
|
pen bold yellow "$PACKAGE is already installed!"
|
|
pen bold yellow "Exiting now!"
|
|
exit 69
|
|
fi
|
|
|
|
# ─< parse arguments and get variable contents >──────────────────────────────────────────
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--silent | -s)
|
|
export silent=true
|
|
;;
|
|
esac
|
|
done
|
|
|
|
main
|
|
fi
|
|
}
|