-
Notifications
You must be signed in to change notification settings - Fork 6
/
sync
executable file
·86 lines (64 loc) · 1.51 KB
/
sync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env perl
use autodie;
use Modern::Perl;
use File::Basename;
use Getopt::Long;
my $site_bucket = "whycryptocurrencies.com";
my $help;
my $draft;
GetOptions(
'help|h' => \$help,
'draft' => \$draft,
);
# Fetch path to current directory
my $root = dirname(__FILE__);
my $site = "_site";
if ($help) {
help();
}
if ($draft) {
$site_bucket = "cryptobook.hietala.xyz";
say "DRAFT";
}
say "Publishing site...\n";
system("$root/generate");
say "Syncing site...\n";
# Sync media files (cache: 1 week)
say "Syncing images";
sync ($site_bucket, "$site/images", "max-age=604800");
# Sync fonts (cache: 10 weeks)
say "Syncing fonts";
sync ($site_bucket, "$site/fonts", "max-age=6048000");
# Sync css (cache: 1 hour)
say "Syncing css";
sync ($site_bucket, "$site/css", "max-age=3600", "-m text/css");
# Sync rest (cache: 1 hour)
say "Syncing rest";
sync ($site_bucket, "$site/", "max-age=3600, must-revalidate");
say "Removing deleted";
sync ($site_bucket, "$site/", "", "--delete-removed");
sub sync {
my $cmd = sync_cmd (@_);
system("$cmd 2>&1");
}
sub capture_sync {
my $cmd = sync_cmd (@_);
my @output = `$cmd`;
return @output;
}
sub sync_cmd {
my ($bucket, $dir, $cache, $option) = @_;
my $header = "";
$header = "--add-header=\"Cache-Control: $cache\"" if $cache;
$option = "" unless $option;
return "s3cmd sync -M $option --acl-public $header $dir s3://$bucket/";
}
sub help {
say "
$0 --draft
sync draft
$0 --help
help
";
exit;
}