summaryrefslogtreecommitdiff
path: root/branding/templates/osx/cross-quickpkg
blob: a940889c7547997e383f20d6134799fac61b1aa3 (plain)
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
#!/bin/bash
# ---------------------------------------------------------
# Creates a OSX flat installer package from a Linux
# environment. You need xar and bomutils in your $PATH
# ---------------------------------------------------------
#
# kudos to SchizoDuckie for putting this gist together
#
# https://gist.github.com/SchizoDuckie/2a1a1cc71284e6463b9a
# https://krypted.com/mac-os-x/inspecting-creating-mac-installer-packages-linux/
# ----------------------------------------------------------


# The following variables need to be overriden by environment vars

: "${VERSION:=0.0.1}"
: "${APPNAME:=TestApp}"
: "${IDENTIFIER:=se.leap.bitmask.installer}"

# ----------------------------------------------------------

BUILD_DIR="../dist"
BASE_DIR="../build/osx"
BACKGROUND="../assets/osx-background.png"

# ----------------------------------------------------------

initialize () {
  rm -rf "$BASE_DIR/darwin"
  mkdir -p "$BASE_DIR/darwin/flat/Resources/en.lproj"
  mkdir -p "$BASE_DIR/darwin/flat/base.pkg/"
  mkdir -p "$BASE_DIR/darwin/root/Applications"
  mkdir -p "$BASE_DIR/darwin/scripts"
  cp -R $BUILD_DIR/*.app $BASE_DIR/darwin/root/Applications
  cp -R scripts/* $BASE_DIR/darwin/scripts/
  cp $BACKGROUND $BASE_DIR/darwin/flat/Resources/en.lproj/background.png
  NUM_FILES=$(find ${BASE_DIR}/darwin/root | wc -l)
  INSTALL_KB_SIZE=$(du -k -s ${BASE_DIR}/darwin/root | awk "{print $1}")
}

# TODO for localization, these files should be taken from transifex, etc.
# TODO hardcoding a foundation for now.
writeInstallerDocs () {
  cat <<EOF > ${BASE_DIR}/darwin/flat/Resources/en.lproj/welcome.html
<html>
<body>
<font face="helvetica">
<h1>${APPNAME} installer</h1>
This will guide you through the steps needed to install ${APPNAME} in your computer.

<hr/>

<p>
<b>${APPNAME}</b> is a <i>simple, fast and secure VPN</i> developed by the Bitmask team. This app is configured to connect to a single trusted VPN provider.
</p>

<hr/>
<p>The service is expensive to run. Please donate at <a href="https://riseup.net/vpn/donate">https://riseup.net/vpn/donate</a></p>

</font>
</body>
</html>
EOF

}

writePackageInfo () {
  cat <<EOF > ${BASE_DIR}/darwin/flat/base.pkg/PackageInfo
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<pkg-info overwrite-permissions="true" relocatable="false" identifier="${IDENTIFIER}" postinstall-action="none" version="${VERSION}" format-version="2" generator-version="InstallCmds-502 (14B25)" auth="root">
 <payload numberOfFiles="${NUM_FILES}" installKBytes="${INSTALL_KB_SIZE}"/>
 <bundle-version>
 <bundle id="${IDENTIFIER}" CFBundleIdentifier="${IDENTIFIER}" path="./Applications/${APPNAME}.app" CFBundleVersion="1.3.0"/>
 </bundle-version>
 <update-bundle/>
 <atomic-update-bundle/>
 <strict-identifier/>
 <relocate/>
 <scripts>
   <preinstall file="preinstall"/>
   <postinstall file="postinstall"/>
 </scripts>
</pkg-info>
EOF
}

writeDistribution () {
  cat <<EOF > ${BASE_DIR}/darwin/flat/Distribution
<?xml version="1.0" encoding="utf-8"?>
<installer-gui-script minSpecVersion="1">
 <title>${APPNAME} ${VERSION}</title>
 <options customize="never" allow-external-scripts="no"/>
 <domains enable_anywhere="true"/>
 <background file="background.png" mime-type="image/png" scaling="tofit" />
 <background-darkAqua file="background.png" mime-type="image/png" scaling="tofit" />
 <welcome file="welcome.html" mime-type="text/html"/>
 <installation-check script="pm_install_check();"/>
 <script>function pm_install_check() {
 if(!(system.compareVersions(system.version.ProductVersion,'10.5') >= 0)) {
 my.result.title = "Failure";
 my.result.message = "You need at least Mac OS X 10.5 to install ${APPNAME}.";
 my.result.type = "Fatal";
 return false;
 }
 return true;
 }
 </script>
 <choices-outline>
 <line choice="choice1"/>
 </choices-outline>
 <choice id="choice1" title="base">
 <pkg-ref id="${IDENTIFIER}.base.pkg"/>
 </choice>
 <pkg-ref id="${IDENTIFIER}.base.pkg" installKBytes="${INSTALL_KB_SIZE}" version="${VERSION}" auth="Root">#base.pkg</pkg-ref>
</installer-gui-script>
EOF
}

createPackage () {
 PKG_NAME="${APPNAME}-${VERSION}_unsigned.pkg"
 PKG_LOCATION="../../${PKG_NAME}"
 PKG_LOCATION_REL="${BASE_DIR}/${PKG_NAME}"
 PKG_FINAL="${BUILD_DIR}/${PKG_NAME}"
 ( cd ${BASE_DIR}/darwin/root && find . | cpio -o --format odc --owner 0:80 | gzip -c ) > ${BASE_DIR}/darwin/flat/base.pkg/Payload
 ( cd ${BASE_DIR}/darwin/scripts && find . | cpio -o --format odc --owner 0:80 | gzip -c ) > ${BASE_DIR}/darwin/flat/base.pkg/Scripts
 mkbom -u 0 -g 80 ${BASE_DIR}/darwin/root ${BASE_DIR}/darwin/flat/base.pkg/Bom
 ( cd ${BASE_DIR}/darwin/flat/ && xar --compression none -cf "${PKG_LOCATION}" * )
 cp ${PKG_LOCATION_REL} ${PKG_FINAL}
 echo "[+] OSX package has been built: ${PKG_FINAL}"
}

initialize
writeInstallerDocs
writePackageInfo
writeDistribution
createPackage