2022-12-22 20:29:31 +08:00
#!/bin/bash
DOCKER_TAG = " $1 "
2023-03-30 16:16:24 +08:00
# The logic needs the files in ./helm-chart
mv ./nextcloud-aio-helm-chart ./helm-chart
2022-12-22 20:29:31 +08:00
# Clean
rm -f ./helm-chart/values.yaml
rm -rf ./helm-chart/templates
# Install kompose
2023-09-26 21:03:09 +08:00
curl -L https://github.com/kubernetes/kompose/releases/latest/download/kompose-linux-amd64 -o kompose
2022-12-22 20:29:31 +08:00
chmod +x kompose
sudo mv ./kompose /usr/local/bin/kompose
2023-07-18 22:50:18 +08:00
# Install yq
snap install yq
2022-12-22 20:29:31 +08:00
set -ex
# Conversion of docker-compose
cd manual-install
cp latest.yml latest.yml.backup
cp sample.conf /tmp/
sed -i 's|^|export |' /tmp/sample.conf
# shellcheck disable=SC1091
source /tmp/sample.conf
rm /tmp/sample.conf
2023-02-17 00:38:45 +08:00
sed -i " s|:latest $|: $DOCKER_TAG -latest| " latest.yml
2023-02-03 22:50:15 +08:00
sed -i "s|\${APACHE_IP_BINDING}:||" latest.yml
2022-12-22 20:29:31 +08:00
sed -i " s|\${APACHE_PORT}:\${APACHE_PORT}/| $APACHE_PORT : $APACHE_PORT /| " latest.yml
sed -i " s|\${TALK_PORT}:\${TALK_PORT}/| $TALK_PORT : $TALK_PORT /|g " latest.yml
2023-02-02 22:22:36 +08:00
sed -i " s|- \${APACHE_PORT}|- $APACHE_PORT | " latest.yml
sed -i " s|- \${TALK_PORT}|- $TALK_PORT | " latest.yml
2022-12-22 20:29:31 +08:00
sed -i " s|\${NEXTCLOUD_DATADIR}| $NEXTCLOUD_DATADIR | " latest.yml
2023-05-11 16:57:19 +08:00
sed -i " /name: nextcloud-aio/, $ d " latest.yml
2022-12-22 20:29:31 +08:00
sed -i "/NEXTCLOUD_DATADIR/d" latest.yml
2023-01-29 07:02:18 +08:00
sed -i "/\${NEXTCLOUD_MOUNT}/d" latest.yml
2023-01-28 23:23:46 +08:00
sed -i "/^volumes:/a\ \ nextcloud_aio_nextcloud_trusted_cacerts:\n \ \ \ \ name: nextcloud_aio_nextcloud_trusted_cacerts" latest.yml
2022-12-22 20:29:31 +08:00
sed -i "s|\${NEXTCLOUD_TRUSTED_CACERTS_DIR}:|nextcloud_aio_nextcloud_trusted_cacerts:|g#" latest.yml
sed -i 's|\${|{{ .Values.|g' latest.yml
sed -i 's|}| }}|g' latest.yml
2023-07-18 22:50:18 +08:00
yq -i 'del(.services.[].profiles)' latest.yml
2022-12-22 20:29:31 +08:00
cat latest.yml
2023-07-18 22:50:18 +08:00
kompose convert -c -f latest.yml --namespace nextcloud-aio-namespace
2022-12-22 20:29:31 +08:00
cd latest
2023-07-18 22:50:18 +08:00
if [ -f ./templates/manual-install-nextcloud-aio-networkpolicy.yaml ] ; then
mv ./templates/manual-install-nextcloud-aio-networkpolicy.yaml ./templates/nextcloud-aio-networkpolicy.yaml
fi
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
2023-01-28 23:23:46 +08:00
find ./ -name '*networkpolicy.yaml' -exec sed -i "s|manual-install-nextcloud-aio|nextcloud-aio|" \{ } \;
2023-02-01 23:00:52 +08:00
cat << EOL > /tmp/initcontainers
initContainers:
- name: init-volumes
image: alpine
command:
- chmod
2023-02-02 01:51:40 +08:00
- "777"
2023-02-01 23:00:52 +08:00
volumeMountsInitContainer:
EOL
2023-02-02 20:06:26 +08:00
cat << EOL > /tmp/initcontainers.database
2023-02-03 00:37:19 +08:00
initContainers:
2023-05-11 17:47:36 +08:00
- name: init-subpath
2023-02-02 20:06:26 +08:00
image: alpine
command:
2023-05-03 18:21:46 +08:00
- mkdir
- "-p"
2023-05-03 23:22:55 +08:00
- /nextcloud-aio-database/data
volumeMountsInitContainer:
- name: init-volumes
image: alpine
command:
2023-02-02 20:06:26 +08:00
- chown
- 999:999
2023-05-03 02:12:57 +08:00
- "-R"
2023-02-02 20:06:26 +08:00
volumeMountsInitContainer:
EOL
2023-02-01 23:00:52 +08:00
# shellcheck disable=SC1083
DEPLOYMENTS = " $( find ./ -name '*deployment.yaml' ) "
mapfile -t DEPLOYMENTS <<< " $DEPLOYMENTS "
for variable in " ${ DEPLOYMENTS [@] } " ; do
if grep -q volumeMounts " $variable " ; then
2023-02-02 20:06:26 +08:00
if ! echo " $variable " | grep -q database; then
sed -i "/^ spec:/r /tmp/initcontainers" " $variable "
else
sed -i "/^ spec:/r /tmp/initcontainers.database" " $variable "
fi
2023-02-01 23:00:52 +08:00
volumeNames = " $( grep -A1 mountPath " $variable " | grep -v mountPath | sed 's|.*name: ||' | sed '/^--$/d' ) "
mapfile -t volumeNames <<< " $volumeNames "
for volumeName in " ${ volumeNames [@] } " ; do
2023-02-05 00:03:42 +08:00
# The Nextcloud container runs as root user and sets the correct permissions automatically for the data-dir if the www-data user cannot write to it
if [ " $volumeName " != "nextcloud-aio-nextcloud-data" ] ; then
sed -i " /^.*volumeMountsInitContainer:/i\ \ \ \ \ \ \ \ \ \ \ \ - / $volumeName " " $variable "
sed -i " /volumeMountsInitContainer:/a\ \ \ \ \ \ \ \ \ \ \ \ - name: $volumeName \n\ \ \ \ \ \ \ \ \ \ \ \ \ \ mountPath: / $volumeName " " $variable "
2023-05-03 02:12:57 +08:00
# Workaround for the database volume
if [ " $volumeName " = nextcloud-aio-database ] ; then
sed -i "/mountPath: \/var\/lib\/postgresql\/data/a\ \ \ \ \ \ \ \ \ \ \ \ \ \ subPath: data" " $variable "
fi
2023-02-05 00:03:42 +08:00
fi
2023-02-01 23:00:52 +08:00
done
sed -i "s|volumeMountsInitContainer|volumeMounts|" " $variable "
2023-02-02 19:49:26 +08:00
if grep -q claimName " $variable " ; then
claimNames = " $( grep claimName " $variable " ) "
mapfile -t claimNames <<< " $claimNames "
for claimName in " ${ claimNames [@] } " ; do
if grep -A1 " ^ $claimName $" " $variable " | grep -q "readOnly: true" ; then
sed -i " /^ $claimName $/{n;d} " " $variable "
fi
done
fi
2023-02-01 23:00:52 +08:00
fi
done
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
2023-08-10 06:56:57 +08:00
find ./ -name '*.yaml' -exec sed -i "s|nextcloud-aio-namespace|\{\{ .Values.NAMESPACE \}\}|" \{ } \;
2023-07-18 22:50:18 +08:00
# shellcheck disable=SC1083
2023-01-28 23:23:46 +08:00
find ./ -name '*service.yaml' -exec sed -i " /^status:/, $ d " \{ } \;
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
2023-01-28 23:23:46 +08:00
find ./ -name '*deployment.yaml' -exec sed -i "s|manual-install-nextcloud-aio|nextcloud-aio|" \{ } \;
# shellcheck disable=SC1083
2023-06-18 08:46:42 +08:00
find ./ -name '*deployment.yaml' -exec sed -i "/medium: Memory/d" \{ } \;
# shellcheck disable=SC1083
2023-06-19 23:49:08 +08:00
find ./ -name '*deployment.yaml' -exec sed -i "s|emptyDir:|emptyDir: \{\}|" \{ } \;
2023-06-18 08:46:42 +08:00
# shellcheck disable=SC1083
2023-01-28 23:23:46 +08:00
find ./ -name '*persistentvolumeclaim.yaml' -exec sed -i "s|ReadOnlyMany|ReadWriteOnce|" \{ } \;
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
find ./ -name '*persistentvolumeclaim.yaml' -exec sed -i "/accessModes:/i\ \ {{- if .Values.STORAGE_CLASS }}" \{ } \;
# shellcheck disable=SC1083
find ./ -name '*persistentvolumeclaim.yaml' -exec sed -i "/accessModes:/i\ \ storageClassName: {{ .Values.STORAGE_CLASS }}" \{ } \;
# shellcheck disable=SC1083
find ./ -name '*persistentvolumeclaim.yaml' -exec sed -i "/accessModes:/i\ \ {{- end }}" \{ } \;
# shellcheck disable=SC1083
2023-02-03 22:50:15 +08:00
find ./ -name '*deployment.yaml' -exec sed -i "/restartPolicy:/d" \{ } \;
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
2023-02-03 22:50:15 +08:00
find ./ -name '*apache*' -exec sed -i " s| $APACHE_PORT |{{ .Values.APACHE_PORT }}| " \{ } \;
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
2023-02-03 22:50:15 +08:00
find ./ -name '*talk*' -exec sed -i " s| $TALK_PORT |{{ .Values.TALK_PORT }}| " \{ } \;
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
2023-02-03 22:50:15 +08:00
find ./ -name '*apache-service.yaml' -exec sed -i "/^spec:/a\ \ type: LoadBalancer" \{ } \;
# shellcheck disable=SC1083
find ./ -name '*talk-service.yaml' -exec sed -i "/^spec:/a\ \ type: LoadBalancer" \{ } \;
2023-02-04 22:23:44 +08:00
echo '---' > /tmp/talk-service.copy
# shellcheck disable=SC1083
find ./ -name '*talk-service.yaml' -exec cat \{ } \; >> /tmp/talk-service.copy
sed -i 's|name: nextcloud-aio-talk|name: nextcloud-aio-talk-public|' /tmp/talk-service.copy
# shellcheck disable=SC1083
INTERNAL_TALK_PORTS = " $( find ./ -name '*talk-deployment.yaml' -exec grep -oP 'containerPort: [0-9]+' \{ } \; ) "
mapfile -t INTERNAL_TALK_PORTS <<< " $INTERNAL_TALK_PORTS "
for port in " ${ INTERNAL_TALK_PORTS [@] } " ; do
port = " $( echo " $port " | grep -oP '[0-9]+' ) "
sed -i " / $port /d " /tmp/talk-service.copy
done
echo '---' >> /tmp/talk-service.copy
# shellcheck disable=SC1083
2023-08-17 15:14:39 +08:00
find ./ -name '*talk-service.yaml' -exec grep -v '{{ .Values.TALK.*}}\|protocol: UDP\|type: LoadBalancer' \{ } \; >> /tmp/talk-service.copy
2023-02-04 22:23:44 +08:00
# shellcheck disable=SC1083
find ./ -name '*talk-service.yaml' -exec mv /tmp/talk-service.copy \{ } \;
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
find ./ -name '*.yaml' -exec sed -i "s|'{{|\"{{|g;s|}}'|}}\"|g" \{ } \;
# shellcheck disable=SC1083
find ./ -name '*.yaml' -exec sed -i "/type: Recreate/d" \{ } \;
# shellcheck disable=SC1083
find ./ -name '*.yaml' -exec sed -i "/strategy:/d" \{ } \;
# shellcheck disable=SC1083
find ./ \( -not -name '*service.yaml' -name '*.yaml' \) -exec sed -i "/^status:/d" \{ } \;
# shellcheck disable=SC1083
find ./ \( -not -name '*persistentvolumeclaim.yaml' -name '*.yaml' \) -exec sed -i "/resources:/d" \{ } \;
# shellcheck disable=SC1083
find ./ -name '*.yaml' -exec sed -i "/creationTimestamp: null/d" \{ } \;
2023-02-23 22:36:05 +08:00
VOLUMES = " $( find ./ -name '*persistentvolumeclaim.yaml' | sed 's|-persistentvolumeclaim.yaml||g;s|.*nextcloud-aio-||g' | sort) "
2023-02-01 19:35:40 +08:00
mapfile -t VOLUMES <<< " $VOLUMES "
for variable in " ${ VOLUMES [@] } " ; do
name = " $( echo " $variable " | sed 's|-|_|g' | tr '[:lower:]' '[:upper:]' ) _STORAGE_SIZE "
VOLUME_VARIABLE += ( " $name " )
# shellcheck disable=SC1083
find ./ -name " *nextcloud-aio- $variable -persistentvolumeclaim.yaml " -exec sed -i " s|storage: 100Mi|storage: {{ .Values. $name }}| " \{ } \;
done
2022-12-22 20:29:31 +08:00
cd ../
mkdir -p ../helm-chart/
rm latest/Chart.yaml
rm latest/README.md
mv latest/* ../helm-chart/
rm -r latest
rm latest.yml
mv latest.yml.backup latest.yml
# Get version of AIO
AIO_VERSION = " $( grep 'Nextcloud AIO ' ../php/templates/containers.twig | grep -oP '[0-9]+.[0-9]+.[0-9]+' ) "
sed -i " s|^version:.*|version: $AIO_VERSION | " ../helm-chart/Chart.yaml
# Conversion of sample.conf
cp sample.conf /tmp/
sed -i 's|"||g' /tmp/sample.conf
sed -i 's|=|: |' /tmp/sample.conf
sed -i 's|= |: |' /tmp/sample.conf
sed -i '/^NEXTCLOUD_DATADIR/d' /tmp/sample.conf
2023-02-03 22:50:15 +08:00
sed -i '/^APACHE_IP_BINDING/d' /tmp/sample.conf
2023-01-29 07:02:18 +08:00
sed -i '/^NEXTCLOUD_MOUNT/d' /tmp/sample.conf
2023-05-11 16:57:19 +08:00
sed -i '/^IPV6_NETWORK/d' /tmp/sample.conf
2023-02-02 19:05:09 +08:00
sed -i '/_ENABLED.*/s/ yes / "yes" /' /tmp/sample.conf
2023-02-10 20:58:23 +08:00
sed -i '/_ENABLED.*/s/ no / "no" /' /tmp/sample.conf
2022-12-22 20:29:31 +08:00
sed -i 's|^NEXTCLOUD_TRUSTED_CACERTS_DIR: .*|NEXTCLOUD_TRUSTED_CACERTS_DIR: # Setting this to any value allows to automatically import root certificates into the Nextcloud container|' /tmp/sample.conf
2023-04-19 05:44:07 +08:00
sed -i 's|10737418240|"10737418240"|' /tmp/sample.conf
2023-07-18 22:50:18 +08:00
# shellcheck disable=SC2129
2023-07-19 23:08:17 +08:00
echo "NAMESPACE: default # By changing this, you can adjust the namespace of the installation which allows to install multiple instances on one kubernetes cluster" >> /tmp/sample.conf
2023-07-18 22:50:18 +08:00
# shellcheck disable=SC2129
2023-06-17 05:55:43 +08:00
echo "" >> /tmp/sample.conf
2023-01-29 07:02:18 +08:00
# shellcheck disable=SC2129
2022-12-22 20:29:31 +08:00
echo 'STORAGE_CLASS: # By setting this, you can adjust the storage class for your volumes' >> /tmp/sample.conf
2023-02-01 19:35:40 +08:00
for variable in " ${ VOLUME_VARIABLE [@] } " ; do
echo " $variable : 1Gi # You can change the size of the $( echo " $variable " | sed 's|_STORAGE_SIZE||;s|_|-|g' | tr '[:upper:]' '[:lower:]' ) volume that default to 1Gi with this value " >> /tmp/sample.conf
done
2022-12-22 20:29:31 +08:00
mv /tmp/sample.conf ../helm-chart/values.yaml
2023-06-13 16:16:09 +08:00
ENABLED_VARIABLES = " $( grep -oP '^[A-Z_]+_ENABLED' ../helm-chart/values.yaml) "
2022-12-22 20:29:31 +08:00
mapfile -t ENABLED_VARIABLES <<< " $ENABLED_VARIABLES "
cd ../helm-chart/
for variable in " ${ ENABLED_VARIABLES [@] } " ; do
2023-06-13 16:16:09 +08:00
name = " $( echo " $variable " | sed 's|_ENABLED||g;s|_|-|g' | tr '[:upper:]' '[:lower:]' ) "
2022-12-22 20:29:31 +08:00
# shellcheck disable=SC1083
find ./ -name " *nextcloud-aio- $name -deployment.yaml " -exec sed -i " 1i\\{{- if eq .Values. $variable \"yes\" }} " \{ } \;
# shellcheck disable=SC1083
find ./ -name " *nextcloud-aio- $name -deployment.yaml " -exec sed -i " $ a {{- end }} " \{ } \;
# shellcheck disable=SC1083
find ./ -name " *nextcloud-aio- $name -service.yaml " -exec sed -i " 1i\\{{- if eq .Values. $variable \"yes\" }} " \{ } \;
# shellcheck disable=SC1083
find ./ -name " *nextcloud-aio- $name -service.yaml " -exec sed -i " $ a {{- end }} " \{ } \;
done
chmod 777 -R ./
2023-03-30 16:16:24 +08:00
# Seems like the dir needs to match the name of the chart
cd ../
rm -rf ./nextcloud-aio-helm-chart
mv ./helm-chart ./nextcloud-aio-helm-chart
2022-12-22 20:29:31 +08:00
set +ex