]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
oci: user-data: Try to decode base64 content
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Feb 2022 17:24:56 +0000 (17:24 +0000)
committerPeter Müller <peter.mueller@ipfire.org>
Mon, 21 Feb 2022 21:35:03 +0000 (21:35 +0000)
Terraform only supports sending any shell scripts encoded in base64
which is however not required by Oracle. Therefore we have to test if
the script is encoded or not.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>
src/initscripts/helper/oci-setup

index 4dbc05ae3fab017f25f53966cfb9b9ea3296218c..782fde5a2b4fd607beb85891b7b839eb281db21b 100644 (file)
@@ -34,6 +34,24 @@ get() {
        wget -qO - "http://169.254.169.254/opc/v1/${file}"
 }
 
+try_base64_decode() {
+       local input="${1}"
+
+       local tmp="$(mktemp)"
+
+       # Try to decode this and return output if successful
+       if base64 -d <<< "${input}" > "${tmp}" 2>/dev/null; then
+               echo "$(<${tmp})"
+
+       # Otherwise just return the input
+       else
+               echo "${input}"
+       fi
+
+       # Cleanup
+       unlink "${tmp}"
+}
+
 to_address() {
        local n="${1}"
 
@@ -134,6 +152,9 @@ import_oci_configuration() {
                # Download a startup script
                local script="$(get instance/metadata/user_data)"
 
+               # Try to decode this
+               script="$(try_base64_decode "${script}")"
+
                # Execute the script
                if [ "${script:0:2}" = "#!" ]; then
                        echo "${script}" > /tmp/user-data.script