wip
This commit is contained in:
parent
053ba09a15
commit
43d3f6458f
1 changed files with 65 additions and 155 deletions
220
docker.sh
220
docker.sh
|
@ -1,151 +1,16 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# ─< ANSI color codes >───────────────────────────────────────────────────────────────────
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||||
RED='\033[0;31m'
|
command_exists() {
|
||||||
CYAN='\033[0;36m'
|
command -v "$@" >/dev/null 2>&1
|
||||||
YELLOW='\033[0;33m'
|
|
||||||
LIGHT_GREEN='\033[0;92m'
|
|
||||||
BOLD='\033[1m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
echo_error() {
|
|
||||||
printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_info() {
|
if command_exists curl; then
|
||||||
printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1"
|
eval "$(curl -fsSL https://git.k4li.de/scripts/imports/raw/branch/main/distro.sh)"
|
||||||
}
|
else
|
||||||
|
echo "curl is required, but not installed"
|
||||||
echo_warning() {
|
exit 1
|
||||||
printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1"
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
echo_note() {
|
|
||||||
printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
check_sudo() {
|
|
||||||
# check for $su
|
|
||||||
if [ "$USER" != "root" ]; then
|
|
||||||
if command -v sudo >/dev/null 2>&1; then
|
|
||||||
su="sudo"
|
|
||||||
else
|
|
||||||
echo "Are you sure you can handle this? You're not root and sudo cannot be found.. [y/n]"
|
|
||||||
read -r sud </dev/tty
|
|
||||||
case $sud in
|
|
||||||
[Yy]) echo "All right, if anything breaks, it's on you" ;;
|
|
||||||
[Nn])
|
|
||||||
echo "All right, you're good. Try to install 'sudo'"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Invalid choice. Exiting."
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
su=""
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
su=""
|
|
||||||
fi
|
|
||||||
echo "--- check_sudo done --- echo '$su' |"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ─< Distribution detection and installation >────────────────────────────────────────
|
|
||||||
check_dist() {
|
|
||||||
if [ -e /etc/os-release ]; then
|
|
||||||
echo_info "Detecting distribution..."
|
|
||||||
. /etc/os-release
|
|
||||||
|
|
||||||
# ─< Convert $ID and $ID_LIKE to lowercase >──────────────────────────────────────────────
|
|
||||||
ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]')
|
|
||||||
ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]')
|
|
||||||
|
|
||||||
case "$ID" in
|
|
||||||
ubuntu | pop) _ubuntu ;;
|
|
||||||
debian) _debian ;;
|
|
||||||
fedora) _fedora ;;
|
|
||||||
# alpine) _alpine ;;
|
|
||||||
arch | manjaro | garuda | endeavour) _arch ;;
|
|
||||||
opensuse*) inst_opensuse ;;
|
|
||||||
*)
|
|
||||||
if [ "${ID_LIKE#*debian}" != "$ID_LIKE" ]; then
|
|
||||||
_debian
|
|
||||||
elif [ "${ID_LIKE#*ubuntu}" != "$ID_LIKE" ]; then
|
|
||||||
_ubuntu
|
|
||||||
elif [ "${ID_LIKE#*arch}" != "$ID_LIKE" ]; then
|
|
||||||
_arch
|
|
||||||
elif [ "${ID_LIKE#*fedora}" != "$ID_LIKE" ]; then
|
|
||||||
_fedora
|
|
||||||
# elif [ "${ID_LIKE#*suse}" != "$ID_LIKE" ]; then
|
|
||||||
# _opensuse
|
|
||||||
else
|
|
||||||
echo_error "Unsupported distribution: $ID"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
echo_error "Unable to detect distribution. /etc/os-release not found."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
_debian() {
|
|
||||||
clear
|
|
||||||
echo_info "executing debian"
|
|
||||||
sleep 2
|
|
||||||
$su apt-get update &&
|
|
||||||
$su apt-get install -y ca-certificates curl &&
|
|
||||||
$su install -m 0755 -d /etc/apt/keyrings &&
|
|
||||||
$su curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc &&
|
|
||||||
$su chmod a+r /etc/apt/keyrings/docker.asc &&
|
|
||||||
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" | $su tee /etc/apt/sources.list.d/docker.list >/dev/null
|
|
||||||
clear &&
|
|
||||||
echo_info "Addet repository. Updating and installing now.."
|
|
||||||
sleep 1
|
|
||||||
$su apt-get update
|
|
||||||
$su apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
|
||||||
}
|
|
||||||
|
|
||||||
_ubuntu() {
|
|
||||||
clear
|
|
||||||
echo_info "executing ubuntu"
|
|
||||||
sleep 2
|
|
||||||
$su apt-get update &&
|
|
||||||
$su apt-get install -y ca-certificates curl &&
|
|
||||||
$su install -m 0755 -d /etc/apt/keyrings &&
|
|
||||||
$su curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc &&
|
|
||||||
$su chmod a+r /etc/apt/keyrings/docker.asc
|
|
||||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
|
|
||||||
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | $su tee /etc/apt/sources.list.d/docker.list >/dev/null
|
|
||||||
clear &&
|
|
||||||
echo_info "Addet repository. Updating and installing now.."
|
|
||||||
sleep 0.5
|
|
||||||
$su apt-get update
|
|
||||||
$su apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
|
||||||
}
|
|
||||||
|
|
||||||
_fedora() {
|
|
||||||
clear
|
|
||||||
echo_info "executing fedora"
|
|
||||||
sleep 2
|
|
||||||
$su dnf -y install dnf-plugins-core
|
|
||||||
$su dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
|
|
||||||
$su dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
|
||||||
}
|
|
||||||
|
|
||||||
_arch() {
|
|
||||||
clear
|
|
||||||
echo_info "executing arch"
|
|
||||||
sleep 2
|
|
||||||
$su pacman -S docker docker-compose --noconfirm
|
|
||||||
}
|
|
||||||
|
|
||||||
init_docker() {
|
init_docker() {
|
||||||
if command -v docker >/dev/null 2>&1; then
|
if command -v docker >/dev/null 2>&1; then
|
||||||
|
@ -165,16 +30,61 @@ init_docker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
if check_sudo; then
|
case "$distro" in
|
||||||
# if check_dist; then
|
arch)
|
||||||
# init_docker
|
clear
|
||||||
# else
|
echo_info "executing arch"
|
||||||
# echo_error "No distro found.. At least thats what the error says.."
|
sleep 2
|
||||||
# fi
|
$su pacman -S docker docker-compose --noconfirm
|
||||||
check_dist && init_docker
|
;;
|
||||||
else
|
debian)
|
||||||
echo_error "Sudo check was failing hard..!"
|
clear
|
||||||
fi
|
echo_info "executing debian"
|
||||||
|
sleep 2
|
||||||
|
$su apt-get update &&
|
||||||
|
$su apt-get install -y ca-certificates curl &&
|
||||||
|
$su install -m 0755 -d /etc/apt/keyrings &&
|
||||||
|
$su curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc &&
|
||||||
|
$su chmod a+r /etc/apt/keyrings/docker.asc &&
|
||||||
|
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" | $su tee /etc/apt/sources.list.d/docker.list >/dev/null
|
||||||
|
clear &&
|
||||||
|
echo_info "Addet repository. Updating and installing now.."
|
||||||
|
sleep 1
|
||||||
|
$su apt-get update
|
||||||
|
$su apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||||
|
;;
|
||||||
|
ubuntu)
|
||||||
|
clear
|
||||||
|
echo_info "executing ubuntu"
|
||||||
|
sleep 2
|
||||||
|
$su apt-get update &&
|
||||||
|
$su apt-get install -y ca-certificates curl &&
|
||||||
|
$su install -m 0755 -d /etc/apt/keyrings &&
|
||||||
|
$su curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc &&
|
||||||
|
$su chmod a+r /etc/apt/keyrings/docker.asc
|
||||||
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
|
||||||
|
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | $su tee /etc/apt/sources.list.d/docker.list >/dev/null
|
||||||
|
clear &&
|
||||||
|
echo_info "Addet repository. Updating and installing now.."
|
||||||
|
sleep 0.5
|
||||||
|
$su apt-get update
|
||||||
|
$su apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||||
|
;;
|
||||||
|
fedora)
|
||||||
|
clear
|
||||||
|
echo_info "executing fedora"
|
||||||
|
sleep 2
|
||||||
|
$su dnf -y install dnf-plugins-core
|
||||||
|
$su dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
|
||||||
|
$su dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||||
|
;;
|
||||||
|
*) echo "$distro is not supported by this script" ;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
main </dev/tty
|
main </dev/tty
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue