This commit is contained in:
2023-05-05 10:31:43 +00:00
parent f7308eb1d8
commit 8c05400697

View File

@@ -58,15 +58,15 @@ ask_envs() {
check_dirs_and_files() { check_dirs_and_files() {
if [ ! -d "/etc/user/config" ]; then if [ ! -d "/etc/user/config" ]; then
mkdir -p "/etc/user/config" $SUDO_CMD mkdir -p "/etc/user/config"
fi; fi;
if [ ! -d "/etc/system" ]; then if [ ! -d "/etc/system" ]; then
mkdir "/etc/system" $SUDO_CMD mkdir "/etc/system"
fi; fi;
if [ ! -f "/etc/user/config/system.json" ]; then if [ ! -f "/etc/user/config/system.json" ]; then
{ {
echo ' $SUDO_CMD echo '
{ {
"NETWORK": { "NETWORK": {
"IP_POOL_START": "172.19.0.0", "IP_POOL_START": "172.19.0.0",
@@ -79,7 +79,7 @@ check_dirs_and_files() {
fi; fi;
{ {
echo "alias service-debian='docker run --rm \ echo "alias service-debian='$SUDO_CMD docker run --rm \
-w /services/ \ -w /services/ \
-e DOCKER_REGISTRY_URL=registry.format.hu \ -e DOCKER_REGISTRY_URL=registry.format.hu \
-e USER_INIT_PATH=/etc/user/config \ -e USER_INIT_PATH=/etc/user/config \
@@ -96,7 +96,7 @@ check_dirs_and_files() {
-v /usr/bin/docker:/usr/bin/docker:ro \ -v /usr/bin/docker:/usr/bin/docker:ro \
registry.format.hu/setup'"; registry.format.hu/setup'";
echo "alias service-galaxis='docker run --rm \ echo "alias service-galaxis='$SUDO_CMD docker run --rm \
-w /services/ \ -w /services/ \
-e DOCKER_REGISTRY_URL=registry.galaxis.xyz \ -e DOCKER_REGISTRY_URL=registry.galaxis.xyz \
-e USER_INIT_PATH=/etc/user/data/galaxis \ -e USER_INIT_PATH=/etc/user/data/galaxis \
@@ -119,25 +119,25 @@ check_dirs_and_files() {
check_running() { check_running() {
DOCKERD_STATUS=$(systemctl status docker | grep running | wc -l) DOCKERD_STATUS=$($SUDO_CMD systemctl status docker | grep running | wc -l)
if [ "$DOCKERD_STATUS" == "0" ]; then if [ "$DOCKERD_STATUS" == "0" ]; then
systemctl start docker $SUDO_CMD systemctl start docker
sleep 5; sleep 5;
DOCKERD_STATUS=$(systemctl status docker | grep running | wc -l) DOCKERD_STATUS=$($SUDO_CMD systemctl status docker | grep running | wc -l)
if [ "$DOCKERD_STATUS" == "0" ]; then if [ "$DOCKERD_STATUS" == "0" ]; then
echo "Docker daemon not running, please check and execute again install script"; echo "Docker daemon not running, please check and execute again the install script";
exit; exit;
fi fi
fi fi
# bridge check # bridge check
BRIDGE_NUM=$(docker network ls | grep bridge | awk '{print $2":"$3}' | sort | uniq | wc -l); BRIDGE_NUM=$($SUDO_CMD docker network ls | grep bridge | awk '{print $2":"$3}' | sort | uniq | wc -l);
CONTAINER_NUM=$(docker ps -a | wc -l); CONTAINER_NUM=$($SUDO_CMD docker ps -a | wc -l);
if [ "$BRIDGE_NUM" != "1" ] && [ "$CONTAINER_NUM" != "1" ]; then if [ "$BRIDGE_NUM" != "1" ] && [ "$CONTAINER_NUM" != "1" ]; then
echo "There are existsing containers and/or networks."; echo "There are existing containers and/or networks.";
echo "Please select from the following options (1/2/3):"; echo "Please select from the following options (1/2/3):";
echo "1 - Delete all existing containers and networks before installation"; echo "1 - Delete all existing containers and networks before installation";
@@ -149,8 +149,8 @@ check_running() {
if [ "$ANSWER" == "1" ]; then if [ "$ANSWER" == "1" ]; then
echo "1 - Removing exising containers and networks"; echo "1 - Removing exising containers and networks";
# delete and continue # delete and continue
docker stop $(docker ps |grep Up | awk '{print $1}') $SUDO_CMD docker stop $($SUDO_CMD docker ps |grep Up | awk '{print $1}')
docker system prune -a $SUDO_CMD docker system prune -a
elif [ "$ANSWER" == "3" ]; then elif [ "$ANSWER" == "3" ]; then
echo "3 - You have chosen to continue installation process." echo "3 - You have chosen to continue installation process."
@@ -165,24 +165,24 @@ check_running() {
install_docker_apt() { install_docker_apt() {
echo exit 101 > /usr/sbin/policy-rc.d $SUDO_CMD echo exit 101 > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d $SUDO_CMD chmod +x /usr/sbin/policy-rc.d
apt-get update $SUDO_CMD apt-get update
apt-get install ca-certificates curl gnupg $SUDO_CMD apt-get install ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyrings $SUDO_CMD install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg $SUDO_CMD curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg $SUDO_CMD chmod a+r /etc/apt/keyrings/docker.gpg
. /etc/os-release; # set VERSION_CODENAME $SUDO_CMD . /etc/os-release; # set VERSION_CODENAME
DOCKER_SOURCE=$(cat /etc/apt/sources.list.d/docker.list | grep 'bullseye stable' | wc -l) DOCKER_SOURCE=$($SUDO_CMD cat /etc/apt/sources.list.d/docker.list | grep 'bullseye stable' | wc -l)
if [ "$DOCKER_SOURCE" == "0" ]; then if [ "$DOCKER_SOURCE" == "0" ]; then
# add docker source to the source list # add docker source to the source list
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$VERSION_CODENAME" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null $SUDO_CMD echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$VERSION_CODENAME" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
fi fi
apt-get -y install --no-install-recommends docker-ce docker-ce-cli containerd.io $SUDO_CMD apt-get -y install --no-install-recommends docker-ce docker-ce-cli containerd.io
} }
install_docker_deb() { install_docker_deb() {
@@ -239,14 +239,17 @@ install_docker_deb() {
} }
SUDO_CMD="";
if [ "$USER" != "root" ] ; then if [ "$USER" != "root" ] ; then
echo "You are not logged in as root." echo "You are not logged in as root."
echo "Do you want to continue and run install script as "$USER" user? (Y/n)"; echo "Do you want to continue and run install script as "$USER" user using sudo? (Y/n)";
read -r ANSWER; read -r ANSWER;
if [ "$ANSWER" == "n" ] || [ "$ANSWER" == "N" ]; then if [ "$ANSWER" == "n" ] || [ "$ANSWER" == "N" ]; then
echo "Bye." echo "Bye."
exit; exit;
else
SUDO_CMD="sudo ";
fi; fi;
fi; fi;
@@ -257,9 +260,9 @@ if [ "$ANSWER" == "y" ] || [ "$ANSWER" == "Y" ]; then
# install docker using apt-get # install docker using apt-get
install_docker_apt install_docker_apt
fi echo "Wait..."
sleep 5 sleep 5
fi
check_running; check_running;
@@ -267,7 +270,7 @@ check_dirs_and_files;
ask_envs; ask_envs;
docker run \ $SUDO_CMD docker run \
--volume $HOME/.ssh/installer:/root/.ssh/id_rsa \ --volume $HOME/.ssh/installer:/root/.ssh/id_rsa \
--env PUBLIC_PROXY=$PUBLIC_PROXY \ --env PUBLIC_PROXY=$PUBLIC_PROXY \
--env SMARTHOST_PROXY=$SMARTHOST_PROXY \ --env SMARTHOST_PROXY=$SMARTHOST_PROXY \
@@ -279,8 +282,8 @@ docker run \
--env LETSENCRYPT_MAIL=$LETSENCRYPT_MAIL registry.format.hu/proxy-deployment-tool --env LETSENCRYPT_MAIL=$LETSENCRYPT_MAIL registry.format.hu/proxy-deployment-tool
# test - alias doesn't work inside a function # test - alias doesn't work inside a function
shopt -s expand_aliases $SUDO_CMD shopt -s expand_aliases
source $HOME/.bash_aliases $SUDO_CMD source $HOME/.bash_aliases
service-debian core-dns start info service-debian core-dns start info