2021-11-30 18:20:42 +08:00
#!/bin/bash
# Function to show text in green
print_green( ) {
local TEXT = " $1 "
printf "%b%s%b\n" "\e[0;92m" " $TEXT " "\e[0m"
}
# Check if socket is available and readable
if ! [ -a "/var/run/docker.sock" ] ; then
echo "Docker socket is not available. Cannot continue."
exit 1
2021-12-04 18:01:38 +08:00
elif ! mountpoint -q "/mnt/docker-aio-config" ; then
echo "/mnt/docker-aio-config is not a mountpoint. Cannot proceed!"
exit 1
2021-12-03 20:13:51 +08:00
elif ! sudo -u www-data test -r /var/run/docker.sock; then
2021-12-03 19:14:39 +08:00
echo "Trying to fix docker.sock permissions internally..."
2021-12-06 20:18:09 +08:00
DOCKER_GROUP = $( stat -c '%G' /var/run/docker.sock)
DOCKER_GROUP_ID = $( stat -c '%g' /var/run/docker.sock)
2021-12-06 23:38:19 +08:00
# Check if a group with the same group id of /var/run/docker.socket already exists in the container
2021-12-06 20:18:09 +08:00
if grep -q " ^ $DOCKER_GROUP : " /etc/group; then
2021-12-06 23:38:19 +08:00
# If yes, add www-data to that group
echo " Adding internal www-data to group $DOCKER_GROUP "
usermod -aG " $DOCKER_GROUP " www-data
else
# If the group doesn't exist, create it
echo " Creating docker group internally with id $DOCKER_GROUP_ID "
groupadd -g " $DOCKER_GROUP_ID " docker
usermod -aG docker www-data
2021-12-06 20:18:09 +08:00
fi
2021-12-03 20:13:51 +08:00
if ! sudo -u www-data test -r /var/run/docker.sock; then
echo "Docker socket is not readable by the www-data user. Cannot continue."
2021-12-01 19:40:51 +08:00
exit 1
fi
2021-11-30 18:20:42 +08:00
fi
# Check if api version is supported
2022-01-21 21:02:35 +08:00
if ! docker info & >/dev/null; then
echo "Cannot connect to the docker socket. Cannot proceed."
exit 1
fi
2021-11-30 18:20:42 +08:00
API_VERSION_FILE = " $( find ./ -name DockerActionManager.php | head -1) "
2022-02-11 18:37:05 +08:00
API_VERSION = " $( grep -oP 'const API_VERSION.*\;' " $API_VERSION_FILE " | grep -oP '[0-9]+.[0-9]+' | head -1) "
# shellcheck disable=SC2001
2021-11-30 18:20:42 +08:00
API_VERSION_NUMB = " $( echo " $API_VERSION " | sed 's/\.//' ) "
2022-02-11 18:37:05 +08:00
LOCAL_API_VERSION_NUMB = " $( docker version | grep -i "api version" | grep -oP '[0-9]+.[0-9]+' | head -1 | sed 's/\.//' ) "
2021-11-30 18:20:42 +08:00
if [ -n " $LOCAL_API_VERSION_NUMB " ] && [ -n " $API_VERSION_NUMB " ] ; then
if ! [ " $LOCAL_API_VERSION_NUMB " -ge " $API_VERSION_NUMB " ] ; then
echo " Docker v $API_VERSION is not supported by your docker engine. Cannot proceed. "
exit 1
fi
else
echo "LOCAL_API_VERSION_NUMB or API_VERSION_NUMB are not set correctly. Cannot check if the API version is supported."
sleep 10
fi
2021-12-03 19:14:39 +08:00
# Add important folders
2021-11-30 18:20:42 +08:00
mkdir -p /mnt/docker-aio-config/data/
mkdir -p /mnt/docker-aio-config/session/
mkdir -p /mnt/docker-aio-config/caddy/
2021-12-03 20:13:51 +08:00
mkdir -p /mnt/docker-aio-config/certs/
# Adjust permissions for all instances
chmod 770 -R /mnt/docker-aio-config
2021-12-03 22:23:55 +08:00
chmod 777 /mnt/docker-aio-config
2021-12-03 20:13:51 +08:00
chown www-data:www-data -R /mnt/docker-aio-config/data/
chown www-data:www-data -R /mnt/docker-aio-config/session/
chown root:root -R /mnt/docker-aio-config/caddy/
chown root:root -R /mnt/docker-aio-config/certs/
2021-11-30 18:20:42 +08:00
# Adjust certs
GENERATED_CERTS = "/mnt/docker-aio-config/certs"
TMP_CERTS = "/etc/apache2/certs"
mkdir -p " $GENERATED_CERTS "
2022-02-11 18:37:05 +08:00
cd " $GENERATED_CERTS " || exit 1
2021-11-30 18:20:42 +08:00
if ! [ -f ./ssl.crt ] && ! [ -f ./ssl.key ] ; then
openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "/C=DE/ST=BE/L=Local/O=Dev/CN=nextcloud.local" -keyout ./ssl.key -out ./ssl.crt
fi
if [ -f ./ssl.crt ] && [ -f ./ssl.key ] ; then
2022-02-11 18:37:05 +08:00
cd " $TMP_CERTS " || exit 1
2021-11-30 18:20:42 +08:00
rm ./ssl.crt
rm ./ssl.key
cp " $GENERATED_CERTS /ssl.crt " ./
cp " $GENERATED_CERTS /ssl.key " ./
fi
2021-12-03 19:14:39 +08:00
2021-11-30 18:20:42 +08:00
print_green " Initial startup of Nextcloud All In One complete!
You should be able to open the Nextcloud AIO Interface now on port 8080 of this server!
E.g. https://internal.ip.of.this.server:8080
If your server has port 80 and 8443 open and you point a domain to your server, you can get a valid certificate automatially by opening the Nextcloud AIO Interface via:
https://your-domain-that-points-to-this-server.tld:8443"
2021-12-03 22:23:55 +08:00
exec " $@ "