Sync home folders with OneDrive for Business

KyleEricson
Valued Contributor II

I have followed this guide and I want to script it.
I want to create a .app file where you can pick the user folder to move and create links for.
Also maybe a way to do it on the backend

Link

Read My Blog: https://www.ericsontech.com
4 REPLIES 4

mark_mahabir
Valued Contributor

Some of the content in this thread may help?

We've successfully used a modified version of the script included there in our shop.

KyleEricson
Valued Contributor II

This works, but I can't seem to get a variable to this script any ideas. I would either like to set the variable or do a pick your home folder display dialog.

#!/bin/sh

#!/bin/sh

#Change to the user
cd /Users/johdoe/

mv Desktop/ 'OneDrive - ACE Manufacturing/'
mv Documents/ 'OneDrive - ACE Manufacturing/'
mv Downloads/ 'OneDrive - ACE Manufacturing/'
mv Movies/ 'OneDrive - ACE Manufacturing/'
mv Music/ 'OneDrive - ACE Manufacturing/'
mv Pictures/ 'OneDrive - ACE Manufacturing/'

ln -s 'OneDrive - ACE Manufacturing/Desktop'
ln -s 'OneDrive - ACE Manufacturing/Documents'
ln -s 'OneDrive - ACE Manufacturing/Downloads'
ln -s 'OneDrive - ACE Manufacturing/Movies'
ln -s 'OneDrive - ACE Manufacturing/Music'
ln -s 'OneDrive - ACE Manufacturing/Pictures'
Read My Blog: https://www.ericsontech.com

KyleEricson
Valued Contributor II

Is there a way to do a popup box asking for the cd command?

Read My Blog: https://www.ericsontech.com

Martyn
New Contributor

This is what I've started using on Mojave 10.14.3 which seems to work

#!/bin/sh

grabConsoleUserAndHome(){

    # don't assume the home folder is equal to the user's name
    CURRENT_USER=""
    CURRENT_USER=$(stat -f %Su "/dev/console")
    HOME=$(dscl . read /Users/"$CURRENT_USER" NFSHomeDirectory | cut -d ':' -f2 | cut -d ' ' -f2)
    if [ "$HOME" == "" ]; then
        if [ -d "/Users/$CURRENT_USER" ]; then
            HOME="/Users/$CURRENT_USER"
        else
            HOME=$(eval echo "~$CURRENT_USER")
        fi
    fi
}
grabConsoleUserAndHome

oneDriveRoot=$(echo "$HOME/OneDrive - CompanyName")

#Create directory if doesnt exist, incase they havent signed into OneDrive, then users just adopt this location on sign in.
mkdir -p "$oneDriveRoot"
chown -R $CURRENT_USER:staff "$oneDriveRoot"
chmod -R 700 "$oneDriveRoot"

mv $HOME/Desktop "$oneDriveRoot/Desktop"
mv $HOME/Documents "$oneDriveRoot/Documents"

su $CURRENT_USER -c "ln -s '$oneDriveRoot/Desktop' $HOME/"
su $CURRENT_USER -c "ln -s '$oneDriveRoot/Documents' $HOME/"

killall cfprefsd