begin with a new script for setup the basic structure of my servers, who tf needs ansible if we got sh
108 lines
No EOL
1.7 KiB
Bash
108 lines
No EOL
1.7 KiB
Bash
#! /usr/bin/env sh
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--dry-run)
|
|
DRY_RUN=1
|
|
shift
|
|
;;
|
|
--*)
|
|
echo "Illegal Operation"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
is_dry_run() {
|
|
if [ -z "$DRY_RUN" ]; then
|
|
return 1
|
|
else
|
|
return 0
|
|
fi
|
|
}
|
|
|
|
command_exists() {
|
|
command -v "$@" > /dev/null 2>&1
|
|
}
|
|
|
|
|
|
check_distro() {
|
|
distro=""
|
|
if [ -r /etc/os-release ]; then
|
|
distro="$(. /etc/os-release && echo "$ID")"
|
|
fi
|
|
echo "$distro"
|
|
}
|
|
|
|
detect_debian_version() {
|
|
version=""
|
|
vers_num="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
|
|
case "$vers_num" in
|
|
12 | trixie)
|
|
version="bookworm"
|
|
;;
|
|
11)
|
|
version="bullseye"
|
|
;;
|
|
10)
|
|
version="buster"
|
|
;;
|
|
9)
|
|
version="stretch"
|
|
;;
|
|
8)
|
|
version="jessie"
|
|
;;
|
|
esac
|
|
echo "$version"
|
|
}
|
|
|
|
exec_command() {
|
|
uid="$(id -u 2>/dev/null || true)"
|
|
sh_c="sh -c"
|
|
if [ "$uid" != 0 ]; then
|
|
if command_exists sudo; then
|
|
sh_c="sudo -E sh -c"
|
|
elif command_exists su; then
|
|
sh_c="su -c"
|
|
else
|
|
cat >&2 <<-'EOF'
|
|
Error: no method for command elevation found, but thats needed for this setup script
|
|
EOF
|
|
exit 1
|
|
fi
|
|
fi
|
|
if is_dry_run; then
|
|
sh_c="echo"
|
|
fi
|
|
echo $sh_c
|
|
}
|
|
|
|
install_apt() {
|
|
pre_reqs="apt-transport-https ca-certificates curl"
|
|
apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] $download_url/linux/$distro $version $channel"
|
|
(
|
|
if ! is_dry_run; then
|
|
set -x
|
|
fi
|
|
$sh_c 'apt-get update -qq >/dev/null'
|
|
)
|
|
}
|
|
|
|
install() {
|
|
sh_c="$(exec_command)"
|
|
distro="$( check_distro )"
|
|
version=""
|
|
channel="stable"
|
|
download_url="https://download.docker.com"
|
|
case "$distro" in
|
|
debian)
|
|
version="$( detect_debian_version )"
|
|
install_apt
|
|
;;
|
|
*)
|
|
echo "Sorry currently only debian is supported"
|
|
esac
|
|
|
|
}
|
|
|
|
install |