@@ -485,6 +485,8 @@ motd_ssh() {
485485# - Creates /usr/bin/update script for easy application updates
486486# - Injects SSH authorized keys if SSH_AUTHORIZED_KEY variable is set
487487# - Sets proper permissions on SSH directories and key files
488+ # - Runs an optional user-supplied post-install script (POST_INSTALL_SCRIPT or
489+ # var_post_install_script in *.vars) at the very end of the install
488490# ------------------------------------------------------------------------------
489491customize() {
490492 if [[ "$PASSWORD" == "" ]]; then
509511 chmod 700 /root/.ssh
510512 chmod 600 /root/.ssh/authorized_keys
511513 fi
514+
515+ # Optional user-supplied post-install script.
516+ # Either POST_INSTALL_SCRIPT (env / install-script) or var_post_install_script
517+ # (defaults.vars / mydefaults) may point to a path or URL of a shell script
518+ # that will be executed at the very end of the install.
519+ local _post_script="${POST_INSTALL_SCRIPT:-${var_post_install_script:-}}"
520+ if [[ -n "$_post_script" ]]; then
521+ msg_info "Running post-install script"
522+ local _post_local=""
523+ if [[ "$_post_script" =~ ^https?:// ]]; then
524+ _post_local="$(mktemp --suffix=.sh)"
525+ if ! curl -fsSL "$_post_script" -o "$_post_local"; then
526+ msg_error "Failed to download post-install script: $_post_script"
527+ rm -f "$_post_local"
528+ else
529+ bash "$_post_local" || msg_error "Post-install script exited with non-zero status"
530+ rm -f "$_post_local"
531+ msg_ok "Ran post-install script"
532+ fi
533+ elif [[ -f "$_post_script" ]]; then
534+ bash "$_post_script" || msg_error "Post-install script exited with non-zero status"
535+ msg_ok "Ran post-install script"
536+ else
537+ msg_error "Post-install script not found: $_post_script"
538+ fi
539+ fi
540+
512541 post_progress_to_api
513542}
0 commit comments