@@ -120,35 +120,52 @@ echo ""
120120
121121# 1. Create the admin account (tolerate "already exists")
122122if [ " $SKIP_ACCOUNT " != true ]; then
123- echo -e " \033[1;34m[1/4 ] Creating account $EMAIL ...\033[0m"
123+ echo -e " \033[1;34m[1/5 ] Creating account $EMAIL ...\033[0m"
124124 if ! ./run-tool.sh create-account " $EMAIL " -p " $PASSWORD " -f " $FIRST " -l " $LAST " ; then
125125 echo -e " \033[1;33mcreate-account failed - account may already exist. Continuing.\033[0m"
126126 echo -e " \033[1;33m(Use --skip-account to silence this, or -p to match the existing password.)\033[0m"
127127 GENERATED_PASSWORD=false
128128 fi
129129else
130- echo -e " \033[1;34m[1/4 ] Skipping account creation.\033[0m"
130+ echo -e " \033[1;34m[1/5 ] Skipping account creation.\033[0m"
131131fi
132132
133133# 2 + 3. Create the workspace and assign the admin to it
134+ WS_ID=" $WORKSPACE "
134135if [ " $SKIP_WORKSPACE " != true ]; then
135- echo -e " \n\033[1;34m[2/4] Creating workspace $WORKSPACE ...\033[0m"
136- if ! ./run-tool.sh create-workspace " $WORKSPACE " " email:$EMAIL " ; then
136+ echo -e " \n\033[1;34m[2/5] Creating workspace $WORKSPACE ...\033[0m"
137+ if ! CREATE_OUT=$( ./run-tool.sh create-workspace " $WORKSPACE " " email:$EMAIL " 2>&1 ) ; then
138+ echo " $CREATE_OUT "
137139 echo -e " \033[1;31mcreate-workspace failed. If it already exists, rerun with --skip-workspace.\033[0m"
138140 exit 1
139141 fi
140142
141- echo -e " \n\033[1;34m[3/4] Assigning $EMAIL to $WORKSPACE ...\033[0m"
142- if ! ./run-tool.sh assign-workspace " $WORKSPACE " " $EMAIL " ; then
143+ echo " $CREATE_OUT "
144+ EXTRACTED_ID=$( echo " $CREATE_OUT " | sed -n ' s/.*workspaceUuid="\([^"]*\)".*/\1/p' | head -n 1)
145+
146+ if [ -n " $EXTRACTED_ID " ]; then
147+ WS_ID=" $EXTRACTED_ID "
148+ echo -e " \033[1;32mCaptured new Workspace ID: $WS_ID \033[0m"
149+ else
150+ echo -e " \033[1;33mWarning: Could not extract workspace UUID. Falling back to $WORKSPACE .\033[0m"
151+ fi
152+
153+ echo -e " \n\033[1;34m[3/5] Assigning $EMAIL to $WS_ID ...\033[0m"
154+ if ! ./run-tool.sh assign-workspace " $EMAIL " " $WS_ID " ; then
143155 echo -e " \033[1;33massign-workspace failed - the owner may already be assigned. Continuing.\033[0m"
144156 fi
157+
158+ echo -e " \n\033[1;34m[4/5] Setting $EMAIL role to OWNER for $WS_ID ...\033[0m"
159+ if ! ./run-tool.sh set-user-role " $EMAIL " " $WS_ID " OWNER; then
160+ echo -e " \033[1;33mset-user-role failed - the owner may already have the role. Continuing.\033[0m"
161+ fi
145162else
146- echo -e " \n\033[1;34m[2/4 ] [3/4 ] Skipping workspace creation/ assignment.\033[0m"
163+ echo -e " \n\033[1;34m[2/5 ] [3/5] [4/5 ] Skipping workspace creation and owner assignment.\033[0m"
147164fi
148165
149166# 4. Restore the backup
150- echo -e " \n\033[1;34m[4/4 ] Restoring backup into $WORKSPACE ...\033[0m"
151- RESTORE_CMD=(./backup-restore.sh " $BACKUP_DIR " " $WORKSPACE " )
167+ echo -e " \n\033[1;34m[5/5 ] Restoring backup into $WS_ID ...\033[0m"
168+ RESTORE_CMD=(./backup-restore.sh " $BACKUP_DIR " " $WS_ID " )
152169[ -n " $DATE " ] && RESTORE_CMD+=(" $DATE " )
153170[ " $MERGE " == true ] && RESTORE_CMD+=(--merge) || RESTORE_CMD+=(--no-merge)
154171[ " $ASSUME_YES " == true ] && RESTORE_CMD+=(-y)
0 commit comments