-
Notifications
You must be signed in to change notification settings - Fork 0
/
box
executable file
·213 lines (170 loc) · 7.54 KB
/
box
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python2
# Author: Stefan Kombrink <stefan.kombrink@gmail.com>
# This file is exclusively licensed under GPL 3.0
# Please check the file gpl.txt in this directory
import tempfile
import shutil
import stat
import getpass
import sys
import subprocess
import os
import re
import hashlib
import datetime
import config as cfg
class Main(object):
requirementsScript="""#!/usr/bin/env python2
import os
import sys
if sys.version_info[:2] == (2, 7):
print("Found Python 2.7")
else:
print("Found Python "+sys.version+", let's hope dolmades will work!")
try:
import pycurl
has_pycurl=True
except:
has_pycurl=False
if has_pycurl or os.system('which curl')==0:
print("Found curl")
sys.exit(0)
else:
print("Could not find curl or pycurl!")
sys.exit(1)
"""
installScript="""#!/bin/sh
CURR_DIR="$PWD"
DOLMA_FNAME="$(ls *.dma|head -n1)"
DOLMA_NAME="$(echo $DOLMA_FNAME|sed 's/\.dma$//')"
INST_DIR="$HOME/Dolmades/"""+cfg.VERSION+"""/$DOLMA_NAME"
echo "Checking requirements..."
"$CURR_DIR/check_requirements"
if [ "$?" != "0" ]; then
echo "Requirements not fulfilled! Please install Python 2.7 and pycurl/curl!"
echo "Aborting installation!"
exit 1
else
echo "Good: requirements fulfilled!"
fi
export UDOCKER_TARBALL="$CURR_DIR/udocker-tarball.tar.gz"
echo "Installing $DOLMA_NAME into $INST_DIR..."
mkdir -p "$INST_DIR/cli"
cp -p "$CURR_DIR/cli/dolmades" "$INST_DIR/cli"
cp -p "$CURR_DIR/cli/udocker" "$INST_DIR/cli"
cp -p "$CURR_DIR/cli/bind.py" "$INST_DIR/cli"
cp -p "$CURR_DIR/cli/prettyprint.py" "$INST_DIR/cli"
cp -p "$CURR_DIR/cli/cook" "$INST_DIR/cli"
cp -p "$CURR_DIR/cli/box" "$INST_DIR/cli"
cp -p "$CURR_DIR/cli/goglizer" "$INST_DIR/cli"
cp -p "$CURR_DIR/license.txt" "$INST_DIR"
cp -p "$CURR_DIR/dolmades-runtime.tar" "$INST_DIR/cli"
# FIXME implement this more flexible!
cat "$CURR_DIR/cli/config.py" | sed "s#^DOLMADES_PATH = HOME + '/.dolmades-' + MAJOR_VERSION()#DOLMADES_PATH = '"$INST_DIR"/data'#" > "$INST_DIR/cli/config.py"
echo >> "$INST_DIR/cli/config.py"
echo "BOXED_PATH=\'$INST_DIR\'" >> "$INST_DIR/cli/config.py"
cd "$INST_DIR/cli"
./dolmades init
rm dolmades-runtime.tar
./dolmades import "$CURR_DIR/$DOLMA_FNAME" > /dev/null
./dolmades serve $DOLMA_NAME
./dolmades bind $DOLMA_NAME
# make sure we can uninstall later
chmod -R u+rw "$INST_DIR/data"
# we are done, clean up
rm -rf "$CURR_DIR"
echo "Installation completed!"
"""
dolmaLicense="""---===== END USER LICENSE AGREEMENT =====---
This Dolma contains installable Windows software and has been created
using Dolmades v"""+cfg.VERSION+""".
It ships bundled with the following software components licensed under the
following open source licenses:
* Dolmades - https://github.com/dolmades/dolmades-cli -- Apache 2.0
* UDocker - https://github.com/indigo-dc/udocker -- Apache 2.0
* Wine - https://winehq.org -- LGPL v2.1
* Proot - https://proot.me -- GPL v2.0
* makeself - https://github.com/megastep/makeself -- GPL v2.0
* Yad - https://github.com/v1cont/yad -- GPL v3.0
* Ubuntu
https://www.ubuntu.com/licensing
* Python 2.7
https://www.python.org/download/releases/2.7/license/
* ImageMagic
https://raw.githubusercontent.com/ImageMagick/ImageMagick/master/LICENSE
Furthermore, the Windows software shipping with this Dolma contains the
following licenses:
"""
def writeFile(self, content, filename, isExec=False):
f=open(filename,'w')
f.write(content)
f.close()
if isExec==True:
st=os.stat(filename)
os.chmod(filename, st.st_mode|stat.S_IEXEC)
def start(self):
try:
if (sys.argv[1]=="-h" or sys.argv[1]=="--help"):
print("Usage: "+sys.argv[0]+" dolmaname [licensefile]")
return
dolmaName = sys.argv[1]
except:
print("Usage: "+sys.argv[0]+" dolmaname [licensefile]")
return
tgtdir = "/tmp/dolmades---"+dolmaName
print("Target directory is "+tgtdir)
workdir = tempfile.mkdtemp()
metaDir=cfg.DOLMADES_PATH+"/containers/"+os.readlink(cfg.DOLMADES_PATH+'/containers/'+dolmaName)+"/ROOT/.dolmades/"
try:
licenseFile = sys.argv[2]
f2=open(licenseFile, 'r')
print("Using license file given as argument")
self.dolmaLicense=self.dolmaLicense+f2.read()
except:
print("No license file argument, trying to find the license in the meta data")
try:
f3=open(metaDir+"/license.txt", 'r')
print("Using license from meta data")
self.dolmaLicense=self.dolmaLicense+f3.read()
except:
print("Warning: no license found, we do not recommend boxing without a license!")
self.dolmaLicense=self.dolmaLicense+"\nNo custom license defined!"
cwd = os.getcwd()
os.chdir(workdir)
os.mkdir("./cli", 0755)
shutil.copy(cfg.SELF_PATH+"/dolmades","./cli/dolmades")
shutil.copy(cfg.SELF_PATH+"/udocker","./cli/udocker")
shutil.copy(cfg.SELF_PATH+"/config.py","./cli/config.py")
shutil.copy(cfg.SELF_PATH+"/bind.py","./cli/bind.py")
shutil.copy(cfg.SELF_PATH+"/box","./cli/box")
shutil.copy(cfg.SELF_PATH+"/cook","./cli/cook")
shutil.copy(cfg.SELF_PATH+"/goglizer","./cli/goglizer")
shutil.copy(cfg.SELF_PATH+"/prettyprint.py","./cli/prettyprint.py")
shutil.copy(cfg.SELF_PATH+"/resources/udocker-tarball.tar.gz","./udocker-tarball.tar.gz")
shutil.copy(cfg.SELF_PATH+"/makeself-header.sh", "./makeself-header.sh")
shutil.copy(cfg.SELF_PATH+"/makeself.sh", "./makeself.sh")
containerPath=cfg.DOLMADES_PATH+"/containers/"+os.readlink(cfg.DOLMADES_PATH+'/containers/'+dolmaName)
metaDir=containerPath+"/ROOT/.dolmades/"
cmd=cfg.SELF_PATH+"/dolmades export '"+dolmaName+"'"
print(cmd)
subprocess.call(cmd, shell=True, close_fds=True)
cmd=cfg.SELF_PATH+"/udocker export --clone -o "+cfg.SELF_PATH+"/dolmades-runtime.tar dolmades-runtime"
print(cmd)
subprocess.call(cmd, shell=True, close_fds=True)
shutil.copy(cfg.SELF_PATH+"/dolmades-runtime.tar","./dolmades-runtime.tar")
self.writeFile(self.dolmaLicense, "./license.txt")
self.writeFile(self.requirementsScript, "./check_requirements", True)
self.writeFile(self.installScript, "./install.sh", True)
modDate='-'.join( [str(i) for i in datetime.datetime.fromtimestamp(os.path.getmtime(metaDir)).isocalendar()] )
print("Last modification date is "+modDate)
#tar_extra="--numeric-owner --owner=0 --group=0 --format=pax --pax-option=exthdr.name=%d/PaxHeaders.0/%f --pax-option=delete=atime --pax-option=delete=ctime --pax-option=delete=mtime --mtime=@0"
tar_extra="--sort=name --mtime='@0' --format=gnu --owner=0 --group=0 --numeric-owner"
cmd="sh makeself.sh --target '"+tgtdir+"' --nocomp --packaging-date @0 --tar-extra '"+tar_extra+"' --license ./license.txt . "+cwd+"/"+dolmaName+".dma.sh '"+dolmaName+" packaged by Dolmades v"+cfg.VERSION+" -- https://dolmades.org' ./install.sh"
print(cmd)
subprocess.call(cmd, shell=True, close_fds=True)
print("Renaming archive to "+dolmaName+"_"+modDate+".dma.sh in order to reflect the packaging date")
shutil.move(cwd+"/"+dolmaName+".dma.sh", cwd+"/"+dolmaName+"_"+modDate+".dma.sh")
shutil.rmtree(workdir)
print("Done!")
if __name__ == "__main__":
sys.exit(Main().start())