feat(shell): first version of perpare-server
finished first version of prepare server for debian
This commit is contained in:
parent
e24d9fa729
commit
4ad3a58af5
1 changed files with 91 additions and 5 deletions
|
@ -24,6 +24,10 @@ command_exists() {
|
|||
command -v "$@" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
to_lower() {
|
||||
echo "$@" | tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
|
||||
check_distro() {
|
||||
distro=""
|
||||
|
@ -77,32 +81,114 @@ exec_command() {
|
|||
echo $sh_c
|
||||
}
|
||||
|
||||
install_apt() {
|
||||
install_docker_apt() {
|
||||
pre_reqs="apt-transport-https ca-certificates curl"
|
||||
rem_pkgs="docker.io docker-doc docker-compose podman-docker containerd runc"
|
||||
inst_pkgs="docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
||||
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'
|
||||
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get remove -y -qq $rem_pkgs >/dev/null"
|
||||
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pre_reqs >/dev/null"
|
||||
$sh_c 'install -m 0755 -d /etc/apt/keyrings'
|
||||
$sh_c "curl -fsSL \"$download_url/linux/$distro/gpg\" -o /etc/apt/keyrings/docker.asc"
|
||||
$sh_c "chmod a+r /etc/apt/keyrings/docker.asc"
|
||||
$sh_c "echo \"$apt_repo\" > /etc/apt/sources.list.d/docker.list"
|
||||
$sh_c 'apt-get update -qq >/dev/null'
|
||||
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $inst_pkgs >/dev/null"
|
||||
)
|
||||
}
|
||||
|
||||
install_acl_apt() {
|
||||
inst_pkgs="acl"
|
||||
(
|
||||
if ! is_dry_run; then
|
||||
set -x
|
||||
fi
|
||||
$sh_c 'apt-get update -qq >/dev/null'
|
||||
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $inst_pkgs >/dev/null"
|
||||
)
|
||||
}
|
||||
|
||||
group_add_docker() {
|
||||
sh_c="$( exec_command )"
|
||||
if command_exists usermod; then
|
||||
$sh_c "usermod -aG docker $(id -un)"
|
||||
else
|
||||
cat >&2 <<-'EOF'
|
||||
Error: no command for group editing found
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
start_docker_boot() {
|
||||
sh_c="$( exec_command )"
|
||||
if command_exists systemctl; then
|
||||
$sh_c 'systemctl enable --now docker.service'
|
||||
else
|
||||
cat >&2 <<-'EOF'
|
||||
Error: no supported init system found
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
mk_docker_dir() {
|
||||
docker_root="/opt"
|
||||
sh_c="$( exec_command )"
|
||||
if ! command_exists setfacl; then
|
||||
install_acl_apt
|
||||
fi
|
||||
(
|
||||
if ! is_dry_run; then
|
||||
set -x
|
||||
fi
|
||||
$sh_c "mkdir -p $docker_root/docker/ $docker_root/docker/compose $docker_root/docker/data"
|
||||
$sh_c "chgrp docker $docker_root/docker"
|
||||
$sh_c "chmod g+s $docker_root/docker"
|
||||
$sh_c "setfactl -R -m u::rwx,g::rwx $docker_root/docker"
|
||||
$sh_c "setfacl -d --set u::rwx,g::rwx,o::r-x $docker_root/docker"
|
||||
)
|
||||
}
|
||||
|
||||
install() {
|
||||
sh_c="$(exec_command)"
|
||||
sh_c="$( exec_command )"
|
||||
distro="$( check_distro )"
|
||||
version=""
|
||||
channel="stable"
|
||||
download_url="https://download.docker.com"
|
||||
case "$distro" in
|
||||
debian)
|
||||
echo " Debian detected"
|
||||
version="$( detect_debian_version )"
|
||||
install_apt
|
||||
install_docker_apt
|
||||
echo " Docker successfully installed"
|
||||
;;
|
||||
*)
|
||||
echo "Sorry currently only debian is supported"
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
install
|
||||
read -p "Add $(id -un) to docker group? (y/N) " if_docker_group
|
||||
case $(to_lower $if_docker_group) in
|
||||
"yes" | "y" | "yeah" | 1)
|
||||
group_add_docker
|
||||
;;
|
||||
esac
|
||||
read -p "Start Docker at boot? (y/N)" if_start_docker_boot
|
||||
case $(to_lower $if_start_docker_boot) in
|
||||
"yes" | "y" | "yeah" | 1)
|
||||
start_docker_boot
|
||||
;;
|
||||
esac
|
||||
read -p "Create Docker dir with ACL permissions? (y/N)" if_mk_docker_dir
|
||||
case $(to_lower $if_mk_docker_dir) in
|
||||
"yes" | "y" | "yeah" | 1)
|
||||
mk_docker_dir
|
||||
;;
|
||||
esac
|
Loading…
Reference in a new issue