-
Notifications
You must be signed in to change notification settings - Fork 0
/
genSelfExtract.yaml
104 lines (93 loc) · 3.36 KB
/
genSelfExtract.yaml
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
# Author: Nuno Aguiar
help:
text : Produces a self-extracting shell script from a folder with a setup script file.
expects:
- name : path
desc : The folder path to include in the self-extracting shell script
example : mypack
mandatory: true
- name : file
desc : The self-extracting shell script filename to create
example : setup.sh
mandatory: false
- name : setup
desc : The shell script, on the folder path, that should be executed after extraction
example : setup
mandatory: true
- name : message
desc : The message to show will self-extracting
example : extracting...
mandatory: false
- name : tmppath
desc : If defined it will extract to the provided path and test, upon a second execution, if it exists and reuse it
example : /tmp/mystuff
mandatory: false
init:
script: |
#!/bin/sh
{{#if message}}echo "{{{message}}}"{{else}} {{/if}}
{{#if message}}echo{{else}} {{/if}}
export TMPDIR={{#if tmppath}}{{tmppath}}{{else}}`mktemp -d /tmp/extract.XXXXXX`{{/if}}
{{#if tmppath}}if [ ! -f {{tmppath}}/{{setup}} ]; then mkdir {{tmppath}} && {{/if}}$(tail -n+{{nlines}} $0 | tar xz -C $TMPDIR); fi
export CDIR=`pwd`
cd $TMPDIR
chmod u+x {{#if tmppath}}{{tmppath}}/{{/if}}{{setup}}
sh {{#if tmppath}}{{tmppath}}{{else}}.{{/if}}/{{setup}} "$@"
cd $CDIR
{{#if tmppath}}{{else}}rm -rf $TMPDIR{{/if}}
exit 0
todo:
- Compact folder
- Write the self-extracting script
ojob:
opacks :
- openaf: 20220515
catch : logErr(exception)
logToConsole: true # to change when finished
jobs:
# ---------------------
- name : Compact folder
check:
in:
path : isString
setup: isString.default("setup")
exec : |
if (!io.fileExists(args.path)) throw "path '" + args.path + "' doesn't exist"
if (!io.fileExists(args.path)) throw "setup script '" + args.path + "/" + args.setup + "' doesn't exist"
log("Ensuring that '" + args.path + "/" + args.setup + "' is executable...")
$sh("chmod u+x " + args.path + "/" + args.setup).exec()
log("Packing and compressing files...")
global.tmp = io.createTempFile("self", "extract.tgz")
io.writeFileTARStream(global.tmp, true, fn => {
listFilesRecursive(args.path, true).filter(r => r.isFile).forEach(f => {
var is = io.readFileStream(f.canonicalPath)
log(" packing " + f.filepath)
fn(f.filepath.replace(args.path + "/", ""), is, f)
is.close()
})
})
# ---------------------------------------
- name : Write the self-extracting script
deps : Compact folder
check:
in:
path : isString
setup : isString.default("setup")
message: isString.default(__)
tmppath: isString.default(__)
exec : |
var script = templify(args.init.script, {
setup : args.setup,
nlines : args.init.script.split("\n").length + 1,
message: args.message,
tmppath: args.tmppath
})
script += "\n"
var fscript = isDef(args.file) ? args.file : io.fileInfo(args.path).filename + ".sh"
log("Writing script " + fscript + "...")
io.writeFileString(fscript, script)
var os = io.writeFileStream(fscript, true)
var is = io.readFileStream(global.tmp)
ioStreamCopy(os, is)
$sh("chmod u+x " + fscript).exec()
log("Done. To execute './" + fscript + "'.")