-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_feature.sh
executable file
·48 lines (39 loc) · 2.14 KB
/
build_feature.sh
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
#!/usr/bin/env -S bash --noprofile --norc -o errexit -o pipefail -o noclobber -o nounset
readonly makeSelfDownloadUrl='https://github.com/megastep/makeself/releases/download/release-2.5.0/makeself-2.5.0.run'
curl -fsSL --retry 3 "${makeSelfDownloadUrl}" -o makeself.run
chmod +x makeself.run
./makeself.run
readonly makeselfPath=$(find . -name makeself.sh)
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly srcDir="${SCRIPT_DIR}/precompile/features"
readonly featureName=$1
readonly featureSrcDir="${srcDir}/${featureName}"
readonly featureTargetDir="${SCRIPT_DIR}/src/${featureName}"
if [ ! -d "${featureSrcDir}" ]; then
echo "=== [ERROR] Feature source directory not found: ${featureSrcDir}"
exit 1
fi
# Create a temporary directory to build the feature
readonly tmpDir=$(mktemp -d -t "${featureName}.XXXXXXXXXX")
trap 'rm -rf "${tmpDir}"' EXIT
# Copy the feature source to the temporary directory
cp -r "${featureSrcDir}" "${tmpDir}"
# Remove `devcontainer-feature.json` from the temporary directory
rm -f "${tmpDir}/${featureName}/devcontainer-feature.json"
rm -f "${tmpDir}/${featureName}/NOTES.md" || true
# Add the entrypoint script to the temporary directory
echo '#!/usr/bin/env -S bash --noprofile --norc -o errexit -o pipefail -o noclobber -o nounset' > "${tmpDir}/entrypoint.sh"
echo '' >> "${tmpDir}/entrypoint.sh"
echo "echo '==== DEVCONTAINER.COM ===='" >> "${tmpDir}/entrypoint.sh"
echo "echo '=== Feature: ${featureName}'" >> "${tmpDir}/entrypoint.sh"
echo "echo '=========================='" >> "${tmpDir}/entrypoint.sh"
echo "cd \"${featureName}\"" >> "${tmpDir}/entrypoint.sh"
echo './install.sh' >> "${tmpDir}/entrypoint.sh"
chmod +x "${tmpDir}/entrypoint.sh"
# Create the feature archive
rm -rf ${featureTargetDir}
mkdir -p ${featureTargetDir}
${makeselfPath} --gzip --current --nox11 --sha256 "${tmpDir}/" "${featureTargetDir}/install.sh" "Devcontainer.com Feature: ${featureName}" "./entrypoint.sh"
# Copy the `devcontainer-feature.json` to the feature directory
cp "${featureSrcDir}/devcontainer-feature.json" "${featureTargetDir}/devcontainer-feature.json"
cp "${featureSrcDir}/NOTES.md" "${featureTargetDir}/NOTES.md" || true