Mapping AFP with Applescript for student macs

DrunkMunki

Registered
i have spent the past 2 weeks searching google and have also searched these forums and have found standard responses using Automator and drag drive into login items...

But i need to do this for 100+ macs with over 500 Users who will be logging in using a Microsoft ADS bound to a Mac Snow Leopard Server in the city.local forest.

We will be rolling out a single mac student image and need help to create a login script on login that will:

1) mount network drive "cty-mac-stu/Users" using AFP on login

2) create a folder (on login if it doesnt exist already) under cty-mac-stu/Users with their username (using "whoami") e.g mount the folder afp://cty-mac-stu/Users/bob

3)make a desktop link of afp://cty-mac-stu/Users/[username] to /Volumes/[username] (using ln -s doesnt work) (is it possible to remove link on logoff???)

4) change/check the permissions of afp://cty-mac-stu/Users/[username] folder so only that user or an admin can access it on the AFP share

what I have so far and need help with all 3 items listed above

1)
Code:
set MyName to do shell script "whoami"
tell application "Finder"
try
mount volume "afp://" & MyName & "@cty-mac-stu/" & MyName & "/ /Volumes/" & MyName & "/"
on error
display dialog  "There was an error mounting the Volume " & MyName & return & return & "Please inform the support staff if the problem continues after a reboot." buttons {"Okay"} default button 1
end try
end tell
2) no idea how to do this [Frown]

3) no idea [Frown]

4) no idea [Frown]

any help on this would greatly reduce my stress levels [Smile] and i'm sure would help a lot of people
 

DrunkMunki

Registered
i have fixed some issues;
i can now login and it mounts after the user inputs their login details
i can create a link to the desktop to their user folder

at the moment i cannot find a way to change the permissions of the folder upon creation, e.g since we wipe the share folder every friday at 10pm the users would need to recreate their folders upon next login automatically, at this point i would like the permissions set to only allow the current user access (and admins)

also looking into LogoutHook to remove the mounted drives+volumes

any ideas and hints/links are welcome

what i have so far, the first script works when run manually, but when i look closer i find that it stalls if a folder exists on the /Users/ network share, but runs fine if that folder is missing.

is there a way to suppress that error, or skip it if the folder exists?

Login Script
Code:
set MyName to do shell script "whoami"
set MountFolder to POSIX file "Volumes/Users/"

tell application "Finder"
   try
       mount volume "afp://" & MyName & "@cty-mac-stu/Users/ /Volumes/Users/" & MyName & "/"
       delay 5
       if (exists folder MyName of MountFolder) is true then
           make new folder at MountFolder with properties {name:MyName}
       end if
       delay 5
       do shell script "ln -s /Volumes/Users/" & MyName & " ~/Desktop"
       delay 3
       do shell script "/bin/chmod 0700 /Volumes/Users/" & MyName & ""
   end try
end tell
Logout Script
Code:
set MyName to do shell script "whoami"
try
   do shell script "/bin/chmod 0700 /Volumes/Users/" & MyName & ""
   do shell script "rm ~/Desktop/" & MyName & ""
   delay 3
   do shell script "hdiutil eject -force /Volumes/Users "
end try
 

DrunkMunki

Registered
ok i have managed to do it on my own, i will post the scripts here to help anyone that may need it in the future.

I firstly used a program called Login Logout tasks which loads on startup and executes the login scpt file, and when it closes it executes the logout scpt file.



Login Script

Code:
set MyName to do shell script "whoami"
set MountFolder to POSIX file "/Volumes/Users/"
tell application "Finder"
    try
        mount volume "afp://" & MyName & "@cty-mac-stu/Users/ /Volumes/Users/" & MyName & "/"
        mount volume "afp://" & MyName & "@cty-mac-stu/common/ /Volumes/common/"
        delay 2
        if (exists folder MyName of MountFolder) is false then
            make new folder at MountFolder with properties {name:MyName}
            delay 3
            do shell script "ln -s /Volumes/Users/" & MyName & " ~/Desktop"
            do shell script "ln -s /Volumes/common ~/Desktop"
            delay 1
            do shell script "/bin/chmod 0774 /Volumes/Users/" & MyName & ""
            do shell script "/bin/chmod 444 ~/Documents"
            do shell script "/bin/chmod 444 ~/Movies"
            do shell script "/bin/chmod 444 ~/Music"
            do shell script "/bin/chmod 444 ~/Pictures"
            do shell script "/bin/chmod 444 ~/Public"
            do shell script "/bin/chmod 444 ~/Sites"
        end if
    on error
        delay 3
        do shell script "ln -s /Volumes/Users/" & MyName & " ~/Desktop"
        do shell script "ln -s /Volumes/common ~/Desktop"
        delay 1
        do shell script "/bin/chmod 0774 /Volumes/Users/" & MyName & ""
        do shell script "/bin/chmod 444 ~/Documents"
        do shell script "/bin/chmod 444 ~/Movies"
        do shell script "/bin/chmod 444 ~/Music"
        do shell script "/bin/chmod 444 ~/Pictures"
        do shell script "/bin/chmod 444 ~/Public"
        do shell script "/bin/chmod 444 ~/Sites"
    end try
end tell

Logout Script

Code:
set MyName to do shell script "whoami"
do shell script "/bin/chmod 0774 /Volumes/Users/" & MyName & " > dev/null 2>&1 &"
do shell script "rm ~/Desktop/" & MyName & " > dev/null 2>&1 &"
do shell script "rm ~/Desktop/common > dev/null 2>&1 &"
delay 3
do shell script "hdiutil eject -force /Volumes/Users"
do shell script "hdiutil eject -force /Volumes/common"
 
Top