-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_deployer.R
179 lines (118 loc) · 4.81 KB
/
generate_deployer.R
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
msg <- "
Generate a RECON deployer to go.
This script will do the following:
1. attempt to upgrade provisioner and nomad
2. generate the deployer
3. split the deployer into 4 compressed files with md5sums that can be uploaded
to github for release
The files you end up with are:
| File name | Description |
|--------------------|------------------------------------------------|
|`<name>/` | Source Directory for the deployer |
|`<name>_base.tar` | source packages, cheat sheets, and instructions|
|`<name>_extra.tar` | binaries for R, git, Rtools, and RStudio |
|`<name>_macosx.tar` | binary packages built for macos |
|`<name>_windows.tar`| binary packages built for windows |
|`<name>_md5sums.txt`| summary of the above files |
|`<name>_release.md` | release page to be placed on github |
Once downloaded, these can be decompressed via R:
```r
untar('<name>_base.tar')
untar('<name>_extra.tar')
untar('<name>_macosx.tar')
untar('<name>_windows.tar')
```
Usage: Rscript generate_deployer.R [-h|--help] <name>
Arguments:
-h,--help print this message and exit
<name> the name of the new directory in which to create the deployer.
This defaults to deployer_yyyy_mm_dd
"
args <- commandArgs(trailingOnly = TRUE)
out_dir <- if (is.na(args[1])) {
sprintf("deployer_%s", gsub("-", "_", Sys.Date()))
} else if (args[1] == "-h" || args[1] == "--help") {
stop(msg)
} else {
args[1]
}
# Updating packages ------------------------------------------------------------
message("Updating provisionr and nomad...")
if (!require("remotes")) {
install.packages("remotes")
library("remotes")
}
remotes::install_github("mrc-ide/provisionr", upgrade = FALSE)
remotes::install_github("reconhub/nomad", upgrade = FALSE)
# Deployer creation ------------------------------------------------------------
message("Creating deployer...")
nomad::build("reconhub/deployer", out_dir)
# Generating README.html -------------------------------------------------------
message("Generating deployer README...")
# Using try here so that it will continue, even if things fail
try(rmarkdown::render(file.path(out_dir, "README.Rmd")))
# Compress deployers -----------------------------------------------------------
message("Compressing the deployers...")
sys_tar <- Sys.which("tar")
tar(sprintf("%s_extra.tar", out_dir), file.path(out_dir, "extra"),
extra_flags = "-v",
tar = sys_tar)
tar(sprintf("%s_base.tar", out_dir), out_dir,
extra_flags = sprintf("-v --exclude=%s/bin --exclude=%s/extra", out_dir, out_dir),
tar = sys_tar)
tar(sprintf("%s_windows.tar", out_dir), file.path(out_dir, "bin/windows"),
extra_flags = "-v",
tar = sys_tar)
tar(sprintf("%s_macosx.tar", out_dir), file.path(out_dir, "bin/macosx"),
extra_flags = "-v",
tar = sys_tar)
# Calculate md5 sums -----------------------------------------------------------
message("Calculating md5 sums and writing %s_md5sum.txt ...", out_dir)
the_tars <- tools::md5sum(dir(pattern = sprintf("^%s_(base|windows|macosx|extra)\\.tar$", out_dir)))
print.tar <- function(x, ...) cat(paste0(x, ' ', names(x)), sep = "\n", ...)
class(the_tars) <- "tar"
the_tars
print.tar(the_tars, file = sprintf("%s_md5sum.txt", out_dir))
# Creating release markdown document -------------------------------------------
message("Creating %s_release.md...", out_dir)
cat("
Produced by <GITHUB_NAME> via:
```sh
Rscript generate_deployer.R
```
## Installation
Download the *.tar files in this release.
Expected MD5 hash:
```",
paste0(the_tars, ' ', names(the_tars)),
"```
Please confirm to avoid issues with corrupted downloads. You can do this with
```r",
sprintf("md5file <- '%s_md5sum.txt'", out_dir),
"inlines <- readLines(md5file)
xx <- sub(\"^([0-9a-fA-F]*)(.*)\", \"\\\\1\", inlines)
nmxx <- names(xx) <- sub(\"^[0-9a-fA-F]* [ |*](.*)\", \"\\\\1\", inlines)
print.tar <- function(x, ...) cat(paste0(x, ' ', names(x)), sep = '\\n', ...)",
sprintf("the_tars <- tools::md5sum(dir(pattern = '^%s_(base|windows|macosx|extra)\\\\.tar$'))", out_dir),
"
class(the_tars) <- 'tar'
class(xx) <- 'tar'
the_tars
xx
identical(xx, the_tars)
```
(this will take several seconds to run)
To put back together, download these files and then run:
```r",
sprintf("untar('deployer_%s_base.tar')", out_dir),
sprintf("untar('deployer_%s_windows.tar')", out_dir),
sprintf("untar('deployer_%s_macosx.tar')", out_dir),
sprintf("untar('deployer_%s_extra.tar')", out_dir),
"```
", file = sprintf("%s_release.md", out_dir), sep = "\n")
cat("
Please upload the tar files and md5sums to the deployer github release
page:
https://github.com/reconhub/deployer/releases/new
Make sure you add the release notes and tag yourself in the release.
")