{{/* The chown at the end of init.sh used to be a hardcoded 1000:1000 while the uid it has to match was overridable through securityContext.pod - so an override made the two disagree in silence. Both now read the same null-safe helper, and with the chart defaults the rendered script is unchanged (1000:1000), so this does not move checksum/config and does not roll existing pods. */}} {{- $podCtx := fromYaml (include "minecraft-server.podSecurityContext" .Values.securityContext) -}} apiVersion: v1 kind: ConfigMap metadata: name: {{ .Release.Name }}-{{ .Chart.Name }}-configmap data: init.sh: | set -e echo "downloading serverpack" wget -O /modpacks/serverpack.zip {{ .Values.curseforgeServerpack.downloadUrl }} SERVERPACK_DIR="{{ .Values.curseforgeServerpack.workingDirectory }}" BACKUP_DIR="/data/serverpack-backup" if [ -d "$SERVERPACK_DIR" ]; then echo "found installed server. Migrating..." if [ -d "$BACKUP_DIR" ]; then echo "clearing old Backup" rm -rf $BACKUP_DIR fi echo "backing up old server-files" cp -r $SERVERPACK_DIR $BACKUP_DIR rm -rf $SERVERPACK_DIR mkdir $SERVERPACK_DIR echo "extracting new server-files" tar -xvf /modpacks/serverpack.zip -C $SERVERPACK_DIR echo "copying old configuration-data" cp -r $BACKUP_DIR/world $SERVERPACK_DIR/world cp $BACKUP_DIR/banned-ips.json $SERVERPACK_DIR/banned-ips.json cp $BACKUP_DIR/banned-players.json $SERVERPACK_DIR/banned-players.json cp $BACKUP_DIR/ops.json $SERVERPACK_DIR/ops.json cp $BACKUP_DIR/whitelist.json $SERVERPACK_DIR/whitelist.json # The init container runs as the same uid as the server (see # securityContext.pod) and cp creates the copies owned by that uid, so # this is a no-op in the normal case. It is kept for volumes whose files # still carry a foreign owner from an older chart version, and it must # not be fatal: an unprivileged process cannot chown foreign files, and # with "set -e" a failure here would keep the whole pod from starting. echo "change owner of files" chown -R {{ $podCtx.runAsUser }}:{{ $podCtx.runAsGroup }} $SERVERPACK_DIR || echo "chown skipped (not permitted); continuing" echo "successfully migrated server" # echo "deleting serverpack.zip" # rm /modpacks/serverpack.zip fi