|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +OVERRIDE_CONFIG=~/.mbs2/overrides.cfg |
| 4 | +if [ -f "$OVERRIDE_CONFIG" ]; then |
| 5 | + . $OVERRIDE_CONFIG |
| 6 | +fi |
| 7 | + |
| 8 | +# FIXME: Get this from a config file. |
| 9 | +JONCHKI_VERSION=0.0.12.1 |
| 10 | +JONCHKI_VERBOSE=debug |
| 11 | +JONCHKI_REPOSITORY=~/.mbs2 |
| 12 | +JONCHKI_SYSCFG=jonchki/jonchkisys.cfg |
| 13 | +JONCHKI_PRJCFG=jonchki/jonchkicfg.xml |
| 14 | +JONCHKI_DEPENDENCY_LOG=dependency-log.xml |
| 15 | +JONCHKI_LOG= |
| 16 | + |
| 17 | +# --------------------------------------------------------------------------- |
| 18 | +# |
| 19 | +# Get the host architecture. |
| 20 | +# |
| 21 | + |
| 22 | +# Get the CPU architecture with the "lscpu" command. |
| 23 | +CPUARCH=$(lscpu | awk -F'Architecture:' '{print $2}' | xargs) |
| 24 | +# Translate a few older CPUs to a (hopefully) compatible architecture. |
| 25 | +declare -A arch2bits=( |
| 26 | + ["i386"]="x86" |
| 27 | + ["i486"]="x86" |
| 28 | + ["i586"]="x86" |
| 29 | + ["i686"]="x86" |
| 30 | +) |
| 31 | +HOST_ARCHITECTURE="${arch2bits[$CPUARCH]}" |
| 32 | +if [ -z "${HOST_ARCHITECTURE}" ]; then |
| 33 | + HOST_ARCHITECTURE=$CPUARCH |
| 34 | +fi |
| 35 | + |
| 36 | +# Detect a 32 bit system running on a 64bit CPU. |
| 37 | +OSARCH=$(getconf LONG_BIT) |
| 38 | +if [ "$OSARCH" == "32" ]; then |
| 39 | + # This is an x86_64 CPU running a x86 OS. |
| 40 | + if [ "$HOST_ARCHITECTURE" == "x86_64" ]; then |
| 41 | + HOST_ARCHITECTURE="x86" |
| 42 | + fi |
| 43 | +fi |
| 44 | + |
| 45 | +if [ -z "${HOST_ARCHITECTURE}" ]; then |
| 46 | + echo "Failed to detect the host architecture." |
| 47 | + exit -1 |
| 48 | +fi |
| 49 | + |
| 50 | +# --------------------------------------------------------------------------- |
| 51 | +# |
| 52 | +# Get the OS. |
| 53 | +# |
| 54 | + |
| 55 | +if [ -f /etc/lsb-release ]; then |
| 56 | + HOST_DISTRIBUTION_ID=$(cat /etc/lsb-release | awk -F'DISTRIB_ID=' '{print $2}' | xargs | awk '{print tolower($0)}') |
| 57 | + HOST_DISTRIBUTION_VERSION=$(cat /etc/lsb-release | awk -F'DISTRIB_RELEASE=' '{print $2}' | xargs) |
| 58 | +fi |
| 59 | + |
| 60 | +if [ -z "${HOST_DISTRIBUTION_ID}" ]; then |
| 61 | + echo "Failed to detect the distribution ID." |
| 62 | + exit -1 |
| 63 | +fi |
| 64 | +if [ -z "${HOST_DISTRIBUTION_VERSION}" ]; then |
| 65 | + echo "Failed to detect the distribution version." |
| 66 | + exit -1 |
| 67 | +fi |
| 68 | + |
| 69 | +# --------------------------------------------------------------------------- |
| 70 | +# |
| 71 | +# Apply overrides. |
| 72 | +# |
| 73 | +if [ -n "$HOST_DISTRIBUTION_ID_OVERRIDE" ]; then |
| 74 | + echo "Overriding the host distribution ID for MBS from $HOST_DISTRIBUTION_ID to $HOST_DISTRIBUTION_ID_OVERRIDE ." |
| 75 | + HOST_DISTRIBUTION_ID=$HOST_DISTRIBUTION_ID_OVERRIDE |
| 76 | +fi |
| 77 | +if [ -n "$HOST_DISTRIBUTION_VERSION_OVERRIDE" ]; then |
| 78 | + echo "Overriding the host distribution version for MBS from $HOST_DISTRIBUTION_VERSION to $HOST_DISTRIBUTION_VERSION_OVERRIDE ." |
| 79 | + HOST_DISTRIBUTION_VERSION=$HOST_DISTRIBUTION_VERSION_OVERRIDE |
| 80 | +fi |
| 81 | +if [ -n "$HOST_ARCHITECTURE_OVERRIDE" ]; then |
| 82 | + echo "Overriding the host architecture for MBS from $HOST_ARCHITECTURE to $HOST_ARCHITECTURE_OVERRIDE ." |
| 83 | + HOST_ARCHITECTURE=$HOST_ARCHITECTURE_OVERRIDE |
| 84 | +fi |
| 85 | + |
| 86 | +# --------------------------------------------------------------------------- |
| 87 | +# |
| 88 | +# Get the standard archive format. |
| 89 | +# |
| 90 | + |
| 91 | +declare -A distribid2archformat=( |
| 92 | + ["ubuntu"]="tar.gz" |
| 93 | +) |
| 94 | +STANDARD_ARCHIVE_FORMAT="${distribid2archformat[$HOST_DISTRIBUTION_ID]}" |
| 95 | + |
| 96 | +if [ -z "${STANDARD_ARCHIVE_FORMAT}" ]; then |
| 97 | + echo "Failed to detect the standard archive format." |
| 98 | + exit -1 |
| 99 | +fi |
| 100 | + |
| 101 | +# --------------------------------------------------------------------------- |
| 102 | + |
| 103 | +ARTIFACT_FILE="jonchki-${JONCHKI_VERSION}-${HOST_DISTRIBUTION_ID}${HOST_DISTRIBUTION_VERSION}_${HOST_ARCHITECTURE}.${STANDARD_ARCHIVE_FORMAT}" |
| 104 | + |
| 105 | +# Get the path to the artifact download and depack folder. |
| 106 | +ARTIFACT_REPOSITORY_PATH=$(realpath ${JONCHKI_REPOSITORY})/repository/org/muhkuh/lua/jonchki/${JONCHKI_VERSION} |
| 107 | +ARTIFACT_INSTALL_PATH=$(realpath ${JONCHKI_REPOSITORY})/install/org/muhkuh/lua/jonchki |
| 108 | +JONCHKI_TOOL=${ARTIFACT_INSTALL_PATH}/jonchki-${JONCHKI_VERSION}/jonchki |
| 109 | + |
| 110 | +# Create the paths if they does not exist. |
| 111 | +mkdir -p ${ARTIFACT_REPOSITORY_PATH} |
| 112 | +if [ $? -ne 0 ]; then |
| 113 | + echo "Failed to create the repository path \"${ARTIFACT_REPOSITORY_PATH}\"." |
| 114 | + exit -1 |
| 115 | +fi |
| 116 | +mkdir -p ${ARTIFACT_INSTALL_PATH} |
| 117 | +if [ $? -ne 0 ]; then |
| 118 | + echo "Failed to create the install path \"${ARTIFACT_INSTALL_PATH}\"." |
| 119 | + exit -1 |
| 120 | +fi |
| 121 | + |
| 122 | +# Was the artifact already downloaded? |
| 123 | +if [ ! -f "${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE}" ]; then |
| 124 | + echo "Downloading the artifact..." |
| 125 | + curl --location --output ${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} https://github.com/muhkuh-sys/org.muhkuh.lua-jonchki/releases/download/v${JONCHKI_VERSION}/${ARTIFACT_FILE} |
| 126 | + if [ $? -ne 0 ]; then |
| 127 | + echo "Failed to download the artifact." |
| 128 | + exit -1 |
| 129 | + fi |
| 130 | +fi |
| 131 | + |
| 132 | +# Was the artifact already depacked? |
| 133 | +if [ ! -f "${JONCHKI_TOOL}" ]; then |
| 134 | + if [ "${STANDARD_ARCHIVE_FORMAT}" == "tar.gz" ]; then |
| 135 | + tar --directory=${ARTIFACT_INSTALL_PATH} --file=${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} --extract --gzip |
| 136 | + if [ $? -ne 0 ]; then |
| 137 | + echo "Failed to extract the artifact ${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} ." |
| 138 | + exit -1 |
| 139 | + fi |
| 140 | + else |
| 141 | + echo "Unknown archive format: ${STANDARD_ARCHIVE_FORMAT}" |
| 142 | + exit -1 |
| 143 | + fi |
| 144 | +fi |
| 145 | + |
| 146 | +# Get the version of the installed tool. |
| 147 | +INSTALLED_JONCHKI_VERSION=$(${JONCHKI_TOOL} --version | cut --delimiter=" " --fields=2 | awk '{print tolower($0)}') |
| 148 | +if [ "${INSTALLED_JONCHKI_VERSION}" != "v${JONCHKI_VERSION}" ]; then |
| 149 | + echo "Unexpected jonchki version in \"${JONCHKI_TOOL}\", expected \"v${JONCHKI_VERSION}\", found \"${INSTALLED_JONCHKI_VERSION}\"." |
| 150 | +fi |
| 151 | + |
| 152 | +# Run jonchki. |
| 153 | +${JONCHKI_TOOL} build |
| 154 | +if [ $? -ne 0 ]; then |
| 155 | + exit -1 |
| 156 | +fi |
0 commit comments