34 lines
1.3 KiB
Bash
Executable File
34 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/apps/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
|
|
|
cmd-apps-rename() {
|
|
declare desc="renames an app"
|
|
declare cmd="apps:rename"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
declare OLD_APP="$1" NEW_APP="$2"
|
|
|
|
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
|
[[ -d "$DOKKU_ROOT/$NEW_APP" ]] && dokku_log_fail "Name is already taken"
|
|
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"
|
|
local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache"
|
|
|
|
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$OLD_APP"
|
|
|
|
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then
|
|
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
|
fi
|
|
rm -rf "$OLD_CACHE_DIR"
|
|
apps_create "$NEW_APP"
|
|
cp -a "$DOKKU_ROOT/$OLD_APP/." "$DOKKU_ROOT/$NEW_APP"
|
|
plugn trigger post-app-rename-setup "$OLD_APP" "$NEW_APP"
|
|
DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP"
|
|
plugn trigger post-app-rename "$OLD_APP" "$NEW_APP"
|
|
echo "Renaming $OLD_APP to $NEW_APP... done"
|
|
}
|
|
|
|
cmd-apps-rename "$@"
|