Skip to content

Commit ef2a480

Browse files
committed
Directory permissions
1 parent c0ec565 commit ef2a480

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

src/scripts/utils.sh

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,21 @@ function CreateWriteableDir () {
291291
else
292292
mkdir -p "${path}" >/dev/null 2>/dev/null
293293
fi
294-
if [ $? -eq 0 ]; then
294+
dir_error=$?
295+
296+
if [ $dir_error = 1 ]; then
297+
if [ "${verbosity}" = "loud" ]; then
298+
sudo mkdir -p "${path}"
299+
else
300+
sudo mkdir -p "${path}" >/dev/null 2>/dev/null
301+
fi
302+
dir_error=$?
303+
fi
304+
305+
if [ $dir_error = 0 ]; then
295306
writeLine "done" $color_success
296307
else
297-
writeLine "Needs admin permission to create folder" $color_error
308+
writeLine "Needs admin permission to create folder (error $dir_error)" $color_error
298309
displayMacOSDirCreatePermissionError
299310
fi
300311
fi
@@ -304,10 +315,11 @@ function CreateWriteableDir () {
304315
if [ "$isAdmin" = true ]; then
305316
write "Setting permissions on ${desc} folder..." $color_primary
306317
sudo chmod a+w "${path}" >/dev/null 2>/dev/null
307-
if [ $? -eq 0 ]; then
318+
dir_error=$?
319+
if [ $dir_error = 0 ]; then
308320
writeLine "done" $color_success
309321
else
310-
writeLine "Needs admin permission to set folder permissions" $color_error
322+
writeLine "Needs admin permission to set folder permissions (error $dir_error)" $color_error
311323
fi
312324
fi
313325
fi
@@ -2725,6 +2737,47 @@ function getDisplaySize () {
27252737
echo "Rows=$(tput lines) Cols=$(tput cols)"
27262738
}
27272739

2740+
haveDisplayedMacOSDirCreatePermissionError=false
2741+
function displayMacOSDirCreatePermissionError () {
2742+
2743+
if [[ $OSTYPE == 'darwin'* ]] && [ "$haveDisplayedMacOSDirCreatePermissionError" = false ]; then
2744+
2745+
haveDisplayedMacOSDirCreatePermissionError=true
2746+
2747+
writeLine ''
2748+
writeLine ''
2749+
writeLine 'We may be able to suggest something:' $color_info
2750+
2751+
# if [ "$os_name" = "Sonoma" ]; then # macOS 14 / Kernal 23
2752+
if (( os_vers >= 13 )); then
2753+
# Note that  will appear as the Apple symbol on macOS, but probably not on Windows or Linux
2754+
writeLine '1. Pull down the  Apple menu and choose "System Settings"'
2755+
writeLine '2. Choose “Privacy & Security"'
2756+
writeLine '3. Scroll down to “Full Disk Access” and click the right arrow >'
2757+
writeLine '4. Click the [+] plus button, and in the popup, navigate to the'
2758+
writeLine ' /Applications/Utilities/ folder and choose "Terminal"'
2759+
writeLine '5. Relaunch Terminal. The “Operation not permitted” error messages should'
2760+
writeLine ' be gone'
2761+
else
2762+
writeLine '1. Pull down the  Apple menu and choose "System Preferences"'
2763+
writeLine '2. Choose “Security & Privacy” control panel'
2764+
writeLine '3. Now select the “Privacy” tab, then from the left-side menu select'
2765+
writeLine ' “Full Disk Access”'
2766+
writeLine '4. Click the lock icon in the lower left corner of the preference '
2767+
writeLine ' panel and authenticate with an admin level login'
2768+
writeLine '5. Now click the [+] plus button so we can full disk access to Terminal'
2769+
writeLine "6. Navigate to the /Applications/Utilities/ folder and choose 'Terminal'"
2770+
writeLine ' to grant Terminal Full Disk Access privileges'
2771+
writeLine '7. Relaunch Terminal, the “Operation not permitted” error messages should'
2772+
writeLine ' be gone'
2773+
fi
2774+
2775+
writeLine ''
2776+
fi
2777+
2778+
# quit 8 # unable to create file or directory
2779+
}
2780+
27282781
function needRosettaAndiBrew () {
27292782

27302783
writeLine

0 commit comments

Comments
 (0)