Adding a file to ~/.config

OSXCreative
New Contributor

New user - I'm not sure why this seems so obtuse/non-intuitive in all this searching.

I'm trying to have a single text file be added to every Mac in a specific place( ~/.config). The file is not dependent on anything weird, it's simply a .JSON file.

I tried doing this through composer but I am so confused. Do I have to make the file a DMG to drop it on all the computers or is there another way? Should I even be using Composer? I have tried asking others with them simply responding with vague, non-helpful responses that avoid the question. Can anyone help? Happy to expound upon anything else, but it's honestly as simple as that.

5 REPLIES 5

mvu
Valued Contributor

A few ways you could do this. I'd try Composer and see if that works. Something like...
1. Drag and drop the desired file into the correct location
2. Open Composer
3. Drag the desired into Composer's source window
4. With a snapshot, create a .DMG file
5. Upload to Jamf Admin
6. Ensure you select FUT/FEU
7. Save
8. Create a Policy in JSS
9. Push the .dmg like a normal package (Ensure you select FUT/FEU)

Can't remember all the gotchas with FUT/FEU because of the macOS changes. Worth a try.

Screen Shot 2022-06-30 at 7.14.23 AM.png

Thanks, MVU! This was super helpful! I keep running into a weird issue though, it keeps trying to add it to a home folder with my username name.

The goal here is to get it to add to the home folder of existing and new users to ~/.config/subfoldername/ but it keeps adding my username folder to the path. Is there a way to get it to not do this?

mvu
Valued Contributor

Do you have a local admin account you use in your Mac environment? If so, create the .dmg in this local account instead of your profile.

I will try this, but would it not just do the same thing and add that admin account name to the path? Also all users currently have admin access if that matters.

AJPinto
Valued Contributor

You can use a DMG package with FUT/FEU as @mvu  detailed. It will work perfectly fine. You can also do this through CLI if you wanted. I would probably do it though CLI myself and run this with a policy so its easier to edit.

 

Something like this will create the file, and write whatever you want to the file. 

#!/bin/sh
## postinstall
#*=============================================================================
#* Define logged in user
#*=============================================================================
DIV1='echo ####################################################################'
DIV2='echo --------------------------------------------------------------------'
DIV3='echo ....................................................................'
ActiveUser=`/bin/ls -l /dev/console \
| /usr/bin/awk '{ print $3 }' \
| tr "[a-z]" "[A-Z]"`
ActiveUserRealName=`dscl . -read /Users/$ActiveUser \
| grep RealName: \
| cut -c11-`
if [[ -z $ActiveUserRealName ]]; then
ActiveUserRealName=`dscl . -read /Users/$ActiveUser \
| awk '/^RealName:/,/^RecordName:/' \
|sed -n 2p | cut -c 2-`
fi

userInfo () {
echo; $DIV1
echo "User Information:"
if [[ "$ActiveUserRealName" == "$ActiveUser" ]]; then
echo "$ActiveUserRealName (Local Admin)"
else
echo "$ActiveUserRealName ($ActiveUser)"
fi
$DIV1
}
userInfo

#*=============================================================================
#* Relocate files
#*=============================================================================

if [ -d "/Users/$ActiveUser" ]
then
echo '/Users/$ActiveUser Valid. Writing Log'
sudo touch /Users/$ActiveUser/.config
echo "this is a line" > /Users/$ActiveUser/.config
exit 0

else
echo '/Users/$ActiveUser Not Valid. Do nothing'
exit 1
fi
 
exit 0 ## Success
exit 1 ## Failure

Something like this would be able to move a file. For example if you placed the file in a staging location with a policy, you could then move it to the users profile.

#!/bin/sh
## postinstall
#*=============================================================================
#* Define logged in user
#*=============================================================================
DIV1='echo ####################################################################'
DIV2='echo --------------------------------------------------------------------'
DIV3='echo ....................................................................'
ActiveUser=`/bin/ls -l /dev/console \
| /usr/bin/awk '{ print $3 }' \
| tr "[a-z]" "[A-Z]"`
ActiveUserRealName=`dscl . -read /Users/$ActiveUser \
| grep RealName: \
| cut -c11-`
if [[ -z $ActiveUserRealName ]]; then
ActiveUserRealName=`dscl . -read /Users/$ActiveUser \
| awk '/^RealName:/,/^RecordName:/' \
|sed -n 2p | cut -c 2-`
fi
 
userInfo () {
echo; $DIV1
echo "User Information:"
if [[ "$ActiveUserRealName" == "$ActiveUser" ]]; then
echo "$ActiveUserRealName (Local Admin)"
else
echo "$ActiveUserRealName ($ActiveUser)"
fi
$DIV1
}
userInfo
 
#*=============================================================================
#* Relocate files
#*=============================================================================
 
 
if [ -d "/Users/$ActiveUser" ]
then
echo '/Users/$ActiveUser Valid. Writing Log'
sudo mv /some/staging/file/path/.config /Users/$ActiveUser/.config
exit 0

else
echo '/Users/$ActiveUser Not Valid. Do nothing'
exit 1
fi
 
exit 0 ## Success
exit 1 ## Failure

 Both the scripts could be cleaned up a bit, but should get you going if you are interested. You may also want to add some chmod bits to set file permissions.