2024-09-13 09:38:30 +01:00
#!/bin/sh -e
. ../common-script.sh
# Function to prompt the user for installation choice
choose_installation( ) {
printf "%b\n" " ${ YELLOW } Choose what to install: ${ RC } "
printf "%b\n" " 1. ${ YELLOW } Docker ${ RC } "
printf "%b\n" " 2. ${ YELLOW } Docker Compose ${ RC } "
printf "%b\n" " 3. ${ YELLOW } Both ${ RC } "
2024-09-22 18:59:39 +01:00
printf "%b" "Enter your choice [1-3]: "
2024-09-19 01:02:52 +01:00
read -r CHOICE
2024-09-13 09:38:30 +01:00
case " $CHOICE " in
1) INSTALL_DOCKER = 1; INSTALL_COMPOSE = 0 ; ;
2) INSTALL_DOCKER = 0; INSTALL_COMPOSE = 1 ; ;
3) INSTALL_DOCKER = 1; INSTALL_COMPOSE = 1 ; ;
2024-09-19 01:40:05 +01:00
*) printf "%b\n" " ${ RED } Invalid choice. Exiting. ${ RC } " ; exit 1 ; ;
2024-09-13 09:38:30 +01:00
esac
}
install_docker( ) {
printf "%b\n" " ${ YELLOW } Installing Docker... ${ RC } "
2024-09-19 19:05:36 +01:00
case " $PACKAGER " in
2024-09-22 18:33:53 +01:00
apt-get| nala)
2024-09-13 09:38:30 +01:00
curl -fsSL https://get.docker.com | sh
; ;
zypper)
2024-09-19 19:05:36 +01:00
" $ESCALATION_TOOL " " $PACKAGER " --non-interactive install docker
" $ESCALATION_TOOL " systemctl enable docker
" $ESCALATION_TOOL " systemctl start docker
2024-09-13 09:38:30 +01:00
; ;
pacman)
2024-09-19 19:05:36 +01:00
" $ESCALATION_TOOL " " $PACKAGER " -S --noconfirm docker
" $ESCALATION_TOOL " systemctl enable docker
" $ESCALATION_TOOL " systemctl start docker
2024-09-13 09:38:30 +01:00
; ;
2024-10-05 12:29:31 +01:00
nix-env)
" $PACKAGER " -iA nixpkgs.docker
2024-10-05 12:45:20 +01:00
" $ESCALATION_TOOL " sed -i -E '/^[[:space:]]*virtualisation\.docker\.enable/!b; s/^([[:space:]]*)virtualisation\.docker\.enable.*/\1virtualisation.docker.enable = true;/' " $NIXOS_CONFIG " || echo 'virtualisation.docker.enable = true;' | " $ESCALATION_TOOL " tee -a " $NIXOS_CONFIG "
2024-10-05 12:29:31 +01:00
" $ESCALATION_TOOL " nixos-rebuild switch
; ;
2024-09-13 09:38:30 +01:00
*)
2024-09-22 17:01:10 +01:00
printf "%b\n" " ${ RED } Unsupported package manager: " " $PACKAGER " " ${ RC } "
2024-09-13 09:38:30 +01:00
exit 1
; ;
esac
}
install_docker_compose( ) {
printf "%b\n" " ${ YELLOW } Installing Docker Compose... ${ RC } "
2024-09-19 19:05:36 +01:00
case " $PACKAGER " in
2024-09-22 18:33:53 +01:00
apt-get| nala)
2024-09-19 19:05:36 +01:00
" $ESCALATION_TOOL " " $PACKAGER " install -y docker-compose-plugin
2024-09-13 09:38:30 +01:00
; ;
zypper)
2024-09-19 19:05:36 +01:00
" $ESCALATION_TOOL " " $PACKAGER " --non-interactive install docker-compose
2024-09-13 09:38:30 +01:00
; ;
pacman)
2024-09-21 15:19:41 +01:00
" $ESCALATION_TOOL " " $PACKAGER " -S --needed --noconfirm docker-compose
2024-09-13 09:38:30 +01:00
; ;
2024-10-05 12:29:31 +01:00
nix-env)
" $PACKAGER " -iA nixpkgs.docker-compose
; ;
2024-09-13 09:38:30 +01:00
*)
2024-09-22 17:01:10 +01:00
printf "%b\n" " ${ RED } Unsupported package manager: " " $PACKAGER " " ${ RC } "
2024-09-13 09:38:30 +01:00
exit 1
; ;
esac
}
install_components( ) {
choose_installation
if [ " $INSTALL_DOCKER " -eq 1 ] ; then
if ! command_exists docker; then
install_docker
else
printf "%b\n" " ${ GREEN } Docker is already installed. ${ RC } "
fi
fi
if [ " $INSTALL_COMPOSE " -eq 1 ] ; then
if ! command_exists docker-compose || ! command_exists docker compose version; then
install_docker_compose
else
printf "%b\n" " ${ GREEN } Docker Compose is already installed. ${ RC } "
fi
fi
}
checkEnv
checkEscalationTool
2024-10-05 12:29:31 +01:00
install_components