-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·158 lines (137 loc) · 5.13 KB
/
build.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
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
#! /bin/bash
OVERRIDE_CONFIG=~/.mbs2/overrides.cfg
if [ -f "$OVERRIDE_CONFIG" ]; then
. $OVERRIDE_CONFIG
fi
# FIXME: Get this from a config file.
JONCHKI_VERSION=0.0.12.1
JONCHKI_VERBOSE=debug
JONCHKI_REPOSITORY=~/.mbs2
JONCHKI_SYSCFG=jonchki/jonchkisys.cfg
JONCHKI_PRJCFG=jonchki/jonchkicfg.xml
JONCHKI_DEPENDENCY_LOG=dependency-log.xml
JONCHKI_LOG=
# ---------------------------------------------------------------------------
#
# Get the host architecture.
#
# Get the CPU architecture with the "lscpu" command.
CPUARCH=$(lscpu | awk -F'Architecture:' '{print $2}' | xargs)
# Translate a few older CPUs to a (hopefully) compatible architecture.
declare -A arch2bits=(
["i386"]="x86"
["i486"]="x86"
["i586"]="x86"
["i686"]="x86"
)
HOST_ARCHITECTURE="${arch2bits[$CPUARCH]}"
if [ -z "${HOST_ARCHITECTURE}" ]; then
HOST_ARCHITECTURE=$CPUARCH
fi
# Detect a 32 bit system running on a 64bit CPU.
OSARCH=$(getconf LONG_BIT)
if [ "$OSARCH" == "32" ]; then
# This is an x86_64 CPU running a x86 OS.
if [ "$HOST_ARCHITECTURE" == "x86_64" ]; then
HOST_ARCHITECTURE="x86"
fi
fi
if [ -z "${HOST_ARCHITECTURE}" ]; then
echo "Failed to detect the host architecture."
exit -1
fi
# ---------------------------------------------------------------------------
#
# Get the OS.
#
if [ -f /etc/lsb-release ]; then
HOST_DISTRIBUTION_ID=$(cat /etc/lsb-release | awk -F'DISTRIB_ID=' '{print $2}' | xargs | awk '{print tolower($0)}')
HOST_DISTRIBUTION_VERSION=$(cat /etc/lsb-release | awk -F'DISTRIB_RELEASE=' '{print $2}' | xargs)
fi
if [ -z "${HOST_DISTRIBUTION_ID}" ]; then
echo "Failed to detect the distribution ID."
exit -1
fi
if [ -z "${HOST_DISTRIBUTION_VERSION}" ]; then
echo "Failed to detect the distribution version."
exit -1
fi
# ---------------------------------------------------------------------------
#
# Apply overrides.
#
if [ -n "$HOST_DISTRIBUTION_ID_OVERRIDE" ]; then
echo "Overriding the host distribution ID for MBS from $HOST_DISTRIBUTION_ID to $HOST_DISTRIBUTION_ID_OVERRIDE ."
HOST_DISTRIBUTION_ID=$HOST_DISTRIBUTION_ID_OVERRIDE
fi
if [ -n "$HOST_DISTRIBUTION_VERSION_OVERRIDE" ]; then
echo "Overriding the host distribution version for MBS from $HOST_DISTRIBUTION_VERSION to $HOST_DISTRIBUTION_VERSION_OVERRIDE ."
HOST_DISTRIBUTION_VERSION=$HOST_DISTRIBUTION_VERSION_OVERRIDE
fi
if [ -n "$HOST_ARCHITECTURE_OVERRIDE" ]; then
echo "Overriding the host architecture for MBS from $HOST_ARCHITECTURE to $HOST_ARCHITECTURE_OVERRIDE ."
HOST_ARCHITECTURE=$HOST_ARCHITECTURE_OVERRIDE
fi
# ---------------------------------------------------------------------------
#
# Get the standard archive format.
#
declare -A distribid2archformat=(
["ubuntu"]="tar.gz"
)
STANDARD_ARCHIVE_FORMAT="${distribid2archformat[$HOST_DISTRIBUTION_ID]}"
if [ -z "${STANDARD_ARCHIVE_FORMAT}" ]; then
echo "Failed to detect the standard archive format."
exit -1
fi
# ---------------------------------------------------------------------------
ARTIFACT_FILE="jonchki-${JONCHKI_VERSION}-${HOST_DISTRIBUTION_ID}${HOST_DISTRIBUTION_VERSION}_${HOST_ARCHITECTURE}.${STANDARD_ARCHIVE_FORMAT}"
# Get the path to the artifact download and depack folder.
ARTIFACT_REPOSITORY_PATH=$(realpath ${JONCHKI_REPOSITORY})/repository/org/muhkuh/lua/jonchki/${JONCHKI_VERSION}
ARTIFACT_INSTALL_PATH=$(realpath ${JONCHKI_REPOSITORY})/install/org/muhkuh/lua/jonchki
JONCHKI_TOOL=${ARTIFACT_INSTALL_PATH}/jonchki-${JONCHKI_VERSION}/jonchki
# Create the paths if they does not exist.
mkdir -p ${ARTIFACT_REPOSITORY_PATH}
if [ $? -ne 0 ]; then
echo "Failed to create the repository path \"${ARTIFACT_REPOSITORY_PATH}\"."
exit -1
fi
mkdir -p ${ARTIFACT_INSTALL_PATH}
if [ $? -ne 0 ]; then
echo "Failed to create the install path \"${ARTIFACT_INSTALL_PATH}\"."
exit -1
fi
# Was the artifact already downloaded?
if [ ! -f "${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE}" ]; then
echo "The Jonchki archive ${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} does not exist yet."
DLURL=https://github.com/muhkuh-sys/org.muhkuh.lua-jonchki/releases/download/v${JONCHKI_VERSION}/${ARTIFACT_FILE}
echo "Downloading Jonchki from ${DLURL}"
curl --location --output ${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} ${DLURL}
if [ $? -ne 0 ]; then
echo "Failed to download the artifact."
exit -1
fi
fi
# Was the artifact already depacked?
if [ ! -f "${JONCHKI_TOOL}" ]; then
if [ "${STANDARD_ARCHIVE_FORMAT}" == "tar.gz" ]; then
tar --directory=${ARTIFACT_INSTALL_PATH} --file=${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} --extract --gzip
if [ $? -ne 0 ]; then
echo "Failed to extract the artifact ${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} ."
exit -1
fi
else
echo "Unknown archive format: ${STANDARD_ARCHIVE_FORMAT}"
exit -1
fi
fi
# Get the version of the installed tool.
INSTALLED_JONCHKI_VERSION=$(${JONCHKI_TOOL} --version | cut --delimiter=" " --fields=2 | awk '{print tolower($0)}')
if [ "${INSTALLED_JONCHKI_VERSION}" != "v${JONCHKI_VERSION}" ]; then
echo "Unexpected jonchki version in \"${JONCHKI_TOOL}\", expected \"v${JONCHKI_VERSION}\", found \"${INSTALLED_JONCHKI_VERSION}\"."
fi
# Run jonchki.
${JONCHKI_TOOL} build
if [ $? -ne 0 ]; then
exit -1
fi