@@ -300,6 +300,32 @@ migrate_database() {
300300 rm -f " $TEMP_SQL_FILE "
301301}
302302
303+ # Find Ghost installations in /var/www/
304+ find_ghost_installations () {
305+ local installations=()
306+
307+ # Search one level deep in /var/www/
308+ if [[ -d " /var/www" ]]; then
309+ for dir in /var/www/* /; do
310+ # Skip if not a directory
311+ [[ ! -d " $dir " ]] && continue
312+
313+ # Remove trailing slash
314+ dir=" ${dir%/ } "
315+
316+ # Check if it's a valid Ghost installation
317+ if [[ -f " ${dir} /.ghost-cli" ]] && [[ -d " ${dir} /content" ]]; then
318+ # Additional validation - check if config file exists
319+ if [[ -f " ${dir} /config.production.json" ]]; then
320+ installations+=(" $dir " )
321+ fi
322+ fi
323+ done
324+ fi
325+
326+ printf ' %s\n' " ${installations[@]} "
327+ }
328+
303329# Main script starts here
304330main () {
305331 check_prerequisites
@@ -314,8 +340,54 @@ main() {
314340 exit 0
315341 fi
316342
343+ # Search for Ghost installations
344+ echo " "
345+ echo " Searching for Ghost installations in /var/www/..."
346+
347+ local ghost_installations=()
348+ while IFS= read -r line; do
349+ [[ -n " $line " ]] && ghost_installations+=(" $line " )
350+ done < <( find_ghost_installations)
351+
317352 # Get installation location
318- read -rp ' Enter your current Ghost installation path: ' current_location
353+ if [[ ${# ghost_installations[@]} -gt 0 ]]; then
354+ echo " "
355+ echo " Found ${# ghost_installations[@]} Ghost installation(s) in /var/www/:"
356+ echo " "
357+
358+ # Display found installations with numbers
359+ local i=1
360+ for installation in " ${ghost_installations[@]} " ; do
361+ local site_name
362+ site_name=$( basename " $installation " )
363+ echo " $i ) $site_name (${installation} )"
364+ (( i++ ))
365+ done
366+ echo " $i ) Enter a different path"
367+ echo " "
368+
369+ read -rp " Select an installation (1-$i ): " selection
370+
371+ # Validate selection
372+ if [[ " $selection " =~ ^[0-9]+$ ]] && [[ $selection -ge 1 ]] && [[ $selection -le $i ]]; then
373+ if [[ $selection -eq $i ]]; then
374+ # User wants to enter a different path
375+ read -rp ' Enter your current Ghost installation path: ' current_location
376+ else
377+ # User selected a found installation
378+ current_location=" ${ghost_installations[$((selection-1))]} "
379+ echo " Selected: $current_location "
380+ fi
381+ else
382+ echo " Invalid selection"
383+ exit 1
384+ fi
385+ else
386+ # No installations found, ask for path directly
387+ echo " "
388+ echo " No Ghost installations found in /var/www/"
389+ read -rp ' Enter your current Ghost installation path: ' current_location
390+ fi
319391
320392 if [[ -z " $current_location " ]]; then
321393 echo " ERROR: Installation path is required"
0 commit comments