]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/initscripts/helper/azure-setup
cloud: Execute user-data scripts at the end of initialization
[people/pmueller/ipfire-2.x.git] / src / initscripts / helper / azure-setup
index 5157712fcd37939c1c7b07066c0cd24a922b22d7..7a4422a35320721640b43a9ecb3933b711af9bfa 100644 (file)
@@ -1,4 +1,23 @@
 #!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007-2022  IPFire Team  <info@ipfire.org>                     #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 . /etc/sysconfig/rc
 . ${rc_functions}
@@ -9,7 +28,7 @@ export PATH=/usr/local/sbin:/usr/local/bin:${PATH}
 get() {
        local file="${1}"
 
-       wget -qO - --header="Metadata:true" "http://169.254.169.254/metadata/instance/${file}?api-version=2019-06-01&format=text"
+       wget --timeout=3 --tries=3 -qO - --header="Metadata:true" "http://169.254.169.254/metadata/instance/${file}?api-version=2019-06-01&format=text"
 }
 
 format_mac() {
@@ -122,25 +141,6 @@ import_azure_configuration() {
                fi
        done
 
-       # Download the user-data script only on the first boot
-       if [ ! -e "/var/ipfire/main/firstsetup_ok" ]; then
-               # Download user-data
-               local user_data="$(get customData)"
-
-               # Save user-data script to be executed later
-               if [ "${user_data:0:2}" = "#!" ]; then
-                       echo "${user_data}" > /tmp/azure-user-data.script
-                       chmod 700 /tmp/azure-user-data.script
-
-                       # Run the user-data script
-                       local now="$(date -u +"%s")"
-                       /tmp/azure-user-data.script &>/var/log/user-data.log.${now}
-
-                       # Delete the script right away
-                       rm /tmp/azure-user-data.script
-               fi
-       fi
-
        # Import network configuration
        # After this, no network connectivity will be available from this script due to the
        # renaming of the network interfaces for which they have to be shut down
@@ -260,6 +260,22 @@ import_azure_configuration() {
                        echo "2,ACCEPT,INPUTFW,ON,std_net_src,ALL,ipfire,RED1,,TCP,,,ON,,,TGT_PORT,444,,,,,,,,,,,00:00,00:00,,AUTO,,dnat,,,,,second"
                ) >> /var/ipfire/firewall/input
 
+               # Download user-data
+               local user_data="$(get customData)"
+
+               # Save user-data script to be executed later
+               if [ "${user_data:0:2}" = "#!" ]; then
+                       echo "${user_data}" > /tmp/azure-user-data.script
+                       chmod 700 /tmp/azure-user-data.script
+
+                       # Run the user-data script
+                       local now="$(date -u +"%s")"
+                       /tmp/azure-user-data.script &>/var/log/user-data.log.${now}
+
+                       # Delete the script right away
+                       rm /tmp/azure-user-data.script
+               fi
+
                # This script has now completed the first steps of setup
                touch /var/ipfire/main/firstsetup_ok
        fi