From b1fac05d57c562812c38681b3127852879bf94b1 Mon Sep 17 00:00:00 2001 From: Louis Chmn Date: Sat, 22 Aug 2026 21:36:58 +0200 Subject: [PATCH] feat(bootstrap): Make the bootsrap script idempotent Signed-off-by: Louis Chmn --- nix/image/bootstrap | 30 ++++++++++++++++++------------ nix/image/scripts/nc-auto-config | 4 ++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/nix/image/bootstrap b/nix/image/bootstrap index 1c675f5..cdcec3f 100755 --- a/nix/image/bootstrap +++ b/nix/image/bootstrap @@ -5,12 +5,14 @@ touch /var/log/nginx/error.log touch /var/log/cron/owncloud.log mkdir /config -echo "# Options in here overwrite the builtin php.ini\n" | save /config/php.ini -echo "# xdebug.mode = debug\n" | save -a /config/php.ini -echo "# xdebug.start_with_request = yes\n\n" | save -a /config/php.ini +if not ("/config/php.ini" | path exists) { + echo "# Options in here overwrite the builtin php.ini\n" | save /config/php.ini + echo "# xdebug.mode = debug\n" | save -a /config/php.ini + echo "# xdebug.start_with_request = yes\n\n" | save -a /config/php.ini +} chmod 0777 /config/php.ini let PHP_INI_DIR = php --ini | grep 'Scan' | cut -d ' ' -f7 | tr -d '"' -ln -s /config/php.ini $"($PHP_INI_DIR)/zz_extra.ini" +ln -sf /config/php.ini $"($PHP_INI_DIR)/zz_extra.ini" let HAZE_UID = $env.HAZE_UID | default "1000" let HAZE_GID = $env.HAZE_GID | default "1000" @@ -51,19 +53,23 @@ mkdir /var/log/nginx /tmp /var/run/blackfire touch /var/log/nginx/access.log touch /var/log/nginx/error.log -if ((getent group $HAZE_GID | length) > 0) { - groupadd haze - useradd -u $HAZE_UID -g $HAZE_GID -G haze haze -} else { - groupadd -g $HAZE_GID haze - useradd -u $HAZE_UID -g $HAZE_GID haze +if ((getent group "haze" | length) == 0) { + if ((getent group $HAZE_GID | length) > 0) { + groupadd haze + useradd -u $HAZE_UID -g $HAZE_GID -G haze haze + } else { + groupadd -g $HAZE_GID haze + useradd -u $HAZE_UID -g $HAZE_GID haze + } } chown -R $"haze:($HAZE_GID)" /home/haze -ls -af /etc/home | each {|file| ln -s $file.name $"/home/haze/($file.name | path basename)" } +ls -af /etc/home | each {|file| ln -sf $file.name $"/home/haze/($file.name | path basename)" } if ("/var/run/docker.sock" | path exists) { let dockerGid = stat --format "%g" /var/run/docker.sock - groupadd docker -g $dockerGid + if ((getent group "docker" | length) == 0) { + groupadd docker -g $dockerGid + } usermod -a -G docker haze } diff --git a/nix/image/scripts/nc-auto-config b/nix/image/scripts/nc-auto-config index b7a2c07..674baaa 100755 --- a/nix/image/scripts/nc-auto-config +++ b/nix/image/scripts/nc-auto-config @@ -4,6 +4,10 @@ touch /var/log/nginx/access.log touch /var/log/nginx/error.log touch /var/log/cron/owncloud.log +if ("/var/www/html/config/config.php" | path exists) { + exit 0 +} + cp /etc/nc/config.php /var/www/html/config/config.php chmod 0755 /var/www/html/config/config.php