| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
pake_desc('synchronise project with another machine'); |
|---|
| 12 |
pake_task('sync', 'project_exists'); |
|---|
| 13 |
|
|---|
| 14 |
function run_sync($task, $args) |
|---|
| 15 |
{ |
|---|
| 16 |
if (!count($args)) |
|---|
| 17 |
{ |
|---|
| 18 |
throw new Exception('You must provide an environment to synchronize.'); |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
$env = $args[0]; |
|---|
| 22 |
|
|---|
| 23 |
$dryrun = isset($args[1]) ? $args[1] : false; |
|---|
| 24 |
|
|---|
| 25 |
if (!file_exists('config/rsync_exclude.txt')) |
|---|
| 26 |
{ |
|---|
| 27 |
throw new Exception('You must create a rsync_exclude file for your project.'); |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
$host = $task->get_property('host', $env); |
|---|
| 31 |
$dir = $task->get_property('dir', $env); |
|---|
| 32 |
try |
|---|
| 33 |
{ |
|---|
| 34 |
$user = $task->get_property('user', $env).'@'; |
|---|
| 35 |
} |
|---|
| 36 |
catch (pakeException $e) |
|---|
| 37 |
{ |
|---|
| 38 |
$user = ''; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
if (substr($dir, -1) != '/') |
|---|
| 42 |
{ |
|---|
| 43 |
$dir .= '/'; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
$ssh = 'ssh'; |
|---|
| 47 |
|
|---|
| 48 |
try |
|---|
| 49 |
{ |
|---|
| 50 |
$port = $task->get_property('port', $env); |
|---|
| 51 |
$ssh = '"ssh -p'.$port.'"'; |
|---|
| 52 |
} |
|---|
| 53 |
catch (pakeException $e) {} |
|---|
| 54 |
|
|---|
| 55 |
try |
|---|
| 56 |
{ |
|---|
| 57 |
$parameters = $task->get_property('parameters', $env); |
|---|
| 58 |
} |
|---|
| 59 |
catch (pakeException $e) |
|---|
| 60 |
{ |
|---|
| 61 |
$parameters = '-azC --force --delete'; |
|---|
| 62 |
if (file_exists('config/rsync_exclude.txt')) |
|---|
| 63 |
{ |
|---|
| 64 |
$parameters .= ' --exclude-from=config/rsync_exclude.txt'; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
if (file_exists('config/rsync_include.txt')) |
|---|
| 68 |
{ |
|---|
| 69 |
$parameters .= ' --include-from=config/rsync_include.txt'; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
if (file_exists('config/rsync.txt')) |
|---|
| 73 |
{ |
|---|
| 74 |
$parameters .= ' --files-from=config/rsync.txt'; |
|---|
| 75 |
} |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
$dry_run = ($dryrun == 'go' || $dryrun == 'ok') ? '' : '--dry-run'; |
|---|
| 79 |
$cmd = "rsync --progress $dry_run $parameters -e $ssh ./ $user$host:$dir"; |
|---|
| 80 |
|
|---|
| 81 |
echo pake_sh($cmd); |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|