Skip to content

Instantly share code, notes, and snippets.

@gboudreau
Created January 3, 2012 22:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gboudreau/1557265 to your computer and use it in GitHub Desktop.
Save gboudreau/1557265 to your computer and use it in GitHub Desktop.
smbln executable that allows the creation of symlinks on Samba shares mounted with the mfsymlinks option
#!/usr/bin/php
<?php
if ($argv[1] == '-s') {
$argv[1] = $argv[2];
$argv[2] = @$argv[3];
}
if (empty($argv[2])) {
$argv[2] = basename($argv[1]);
}
$target = $argv[1];
$symlink = $argv[2];
if (file_exists($symlink)) {
echo basename($argv[0]) . ": creating symbolic link `$symlink': File exists\n";
exit(1);
}
$md5 = trim(`echo -n $target | md5sum | awk '{print \$1}'`);
$symlink_data = sprintf("XSym\n%04d\n%s\n%s\n%s",
strlen($target),
$md5,
$target,
str_repeat(' ', 1024-1-strlen($target))
);
file_put_contents($symlink, $symlink_data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment