Best proper way to copy applications to /Applications
Hi all,
in addition to
this topic, I thought maybe I should post this in the programming topic as well.
I'm working on a 'autoUpdate' tool, that will mount an hidden folder (located in the public folder of every user, if not it will be created) to one of our internal windows fileshares.
Then based on the type of file, .app, .pkg, or any other
it determines if it needs to be copied to /Applications, installed, or just copied to the users desktop. Meanwhile an little check to compare last edited datetime with the small .plist 'database' to see if it needs to be updated or not.
Something is going wrong at the moment of copying files to /Applications.
For the current user where the autoupdater copied applications to the /Applications folder, the apps work fine. However when an different user logs in (LDAP), these applications, are marked as 'Zero bytes' and can't be opened. However when the user copies the application to its desktop, its working fine.
(Looks like an 'hardcopy')
I think I can change the rsync command for cp. (I thought rsync takes over permissions and owner), but this still does not fixes my problem.
Down here a stripped down snippet of my code.
Code:
for(int a=0; a<[appFiles count]; a++) {
NSString *curApp = [NSString stringWithFormat: @"%@.%@", [appFiles objectAtIndex: a], [appTypes objectAtIndex: a]]];
//Some checks if current file already is in 'db'
if([[appTypes objectAtIndex: a] isEqualToString: @"app") {
//Check if app is running, if so, kill process (If its not this tool)
[self killRunningApp: [appFiles objectAtIndex: a]];
NSString *theScript = runApplescript([NSString stringWithFormat: @"set tFile to \"/Users/%@/Public/.autoupdate/%@/%@\"\n\
do shell script \"sudo rsync -ardv \" & (quoted form of tFile) & \" /Applications/\" user name \"adminUser\" password \"adminPass\" with administrator privileges", NSUserName(), [appFolders objectAtIndex: a], curApp]);
//[appFolders objectAtIndex: a] ? Whats that? That's the subfolder determined by IP of current user, which department, which apps needed
if(theScript == nil) {
//If succeed, set permissions
runApplescript([NSString stringWithFormat: @"set tFile to \"/Applications/%@\"\n\
do shell script \"sudo chmod 0775 \" & (quoted form of tFile) user name \"adminUser\" password \"adminPass\" with administrator privileges", curApp]);
runApplescript([NSString stringWithFormat: @"set tFile to \"/Applications/%@\"\n\
do shell script \"sudo chown root:admin \" & (quoted form of tFile) user name \"adminUser\" password \"adminPass\" with administrator privileges", curApp]);
//Mark in tableview as installed.
} else {
//Mark in tableview as failed.
}
} else if([[appTypes objectAtIndex: a] isEqualToString: @"pkg") {
//Copy to public folder, and install,remove install file from public folder
} else {
//Copy to current user desktop
}
}
Hopefully someone can help me out here, this is an pain for more than a week now