The `post-app-rename-setup` trigger redirected `sed` output to the new app's VHOST file inside a loop over global vhosts, so each iteration clobbered the previous one and only the last global subdomain was rewritten. When no global vhost was set, the loop never ran and the new app's VHOST file was never written, leaving the renamed app with no domains. Copy the old app's VHOST file once as a baseline, then apply `sed -i` in place for each global vhost so substitutions accumulate. Guard against a missing global VHOST file and skip blank lines.
27 lines
678 B
Bash
Executable File
27 lines
678 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
trigger-domains-post-app-rename-setup() {
|
|
declare desc="updates VHOST files during rename"
|
|
declare trigger="post-app-rename-setup"
|
|
declare OLD_APP="$1" NEW_APP="$2"
|
|
|
|
if [[ ! -f "$DOKKU_ROOT/$OLD_APP/VHOST" ]]; then
|
|
return
|
|
fi
|
|
|
|
cp -f "$DOKKU_ROOT/$OLD_APP/VHOST" "$DOKKU_ROOT/$NEW_APP/VHOST"
|
|
|
|
if [[ ! -f "$DOKKU_ROOT/VHOST" ]]; then
|
|
return
|
|
fi
|
|
|
|
while read -r VHOST || [[ -n "$VHOST" ]]; do
|
|
[[ -z "$VHOST" ]] && continue
|
|
sed -i -e "s/${OLD_APP}\.${VHOST}/${NEW_APP}.${VHOST}/g" "$DOKKU_ROOT/$NEW_APP/VHOST"
|
|
done <"$DOKKU_ROOT/VHOST"
|
|
}
|
|
|
|
trigger-domains-post-app-rename-setup "$@"
|