@@ -21,6 +21,7 @@ VERBOSE=false
2121HELP=false
2222UNINSTALL=false
2323SKIP_CHECKSUM=false
24+ NO_CREATE_DIR=false
2425
2526# Print a message to stdout
2627report () {
@@ -45,13 +46,15 @@ USAGE:
4546DESCRIPTION:
4647 Downloads and installs the latest version of ${fullAppName} to a specified location.
4748 By default, installs to ${defaultLocation} and adds it to PATH.
49+ Installation directories are created automatically if they don't exist.
4850
4951OPTIONS:
5052 -h, --help Show this help message
5153 -v, --verbose Enable verbose output
5254 -d, --dry-run Show what would be done without actually installing
5355 -u, --uninstall Uninstall ${fullAppName}
5456 --skip-checksum Skip checksum verification (not recommended)
57+ --no-create-dir Don't automatically create installation directory
5558 -l, --location PATH Install location (default: ${defaultLocation} )
5659 -V, --version VERSION Version to install (default: ${defaultVersion} )
5760
@@ -72,6 +75,9 @@ EXAMPLES:
7275 # Dry run to see what would happen
7376 ./install.sh --dry-run
7477
78+ # Install without auto-creating directories
79+ ./install.sh --location /opt/ferret --no-create-dir
80+
7581 # Uninstall
7682 ./install.sh --uninstall
7783
@@ -107,6 +113,10 @@ parse_args() {
107113 SKIP_CHECKSUM=true
108114 shift
109115 ;;
116+ --no-create-dir)
117+ NO_CREATE_DIR=true
118+ shift
119+ ;;
110120 -l|--location)
111121 LOCATION=" $2 "
112122 shift 2
@@ -185,10 +195,23 @@ validate_input() {
185195
186196 # Check if location exists
187197 if [ ! -d " $location " ]; then
188- report " Error: Directory does not exist: $location "
189- report " Please create the directory manually:"
190- report " mkdir -p \" $location \" "
191- exit 1
198+ if [ " $NO_CREATE_DIR " = true ]; then
199+ report " Error: Directory does not exist: $location "
200+ report " Please create the directory manually:"
201+ report " mkdir -p \" $location \" "
202+ exit 1
203+ else
204+ verbose " Creating directory: $location "
205+ if [ " $DRY_RUN " = false ]; then
206+ if ! mkdir -p " $location " ; then
207+ report " Error: Failed to create directory: $location "
208+ report " Please check permissions or create manually:"
209+ report " mkdir -p \" $location \" "
210+ exit 1
211+ fi
212+ verbose " Successfully created directory: $location "
213+ fi
214+ fi
192215 fi
193216
194217 # Check if location is writable (only if not dry run)
@@ -494,12 +517,22 @@ install() {
494517 if [ " $DRY_RUN " = true ]; then
495518 report " DRY RUN - Would perform the following actions:"
496519 report " 1. Create temporary directory"
497- report " 2. Download ${projectName} ${appName} ${version} "
498- report " 3. Verify checksum for security"
499- report " 4. Extract and install to: ${location} "
500- report " 5. Make executable: ${location} /${binName} "
501- report " 6. Update PATH in shell profile"
502- report " 7. Clean up temporary files"
520+ if [ ! -d " $location " ] && [ " $NO_CREATE_DIR " = false ]; then
521+ report " 2. Create installation directory: $location "
522+ report " 3. Download ${projectName} ${appName} ${version} "
523+ report " 4. Verify checksum for security"
524+ report " 5. Extract and install to: ${location} "
525+ report " 6. Make executable: ${location} /${binName} "
526+ report " 7. Update PATH in shell profile"
527+ report " 8. Clean up temporary files"
528+ else
529+ report " 2. Download ${projectName} ${appName} ${version} "
530+ report " 3. Verify checksum for security"
531+ report " 4. Extract and install to: ${location} "
532+ report " 5. Make executable: ${location} /${binName} "
533+ report " 6. Update PATH in shell profile"
534+ report " 7. Clean up temporary files"
535+ fi
503536 report " "
504537 report " To proceed with installation, run without --dry-run"
505538 return 0
0 commit comments