Installing the Go Chilkat Package on Linux

Prerequisites

The install script will first check to verify the following command are available on your Linux system: unzip, curl, sha256sum, and tar. If any of the commands are not available, the installChilkat.sh will exit with an error message prior to doing anything.

Installing

Run the following to download, build, and install. The install script (shown below) will download the required Chilkat native "C" library based on the CPU architecture, and also the Chilkat Go sources. It will validate the SHA256 checksums against the expected values. If all is OK, the downloads are extracted and the Chilkat Go module is built.

cd ~/temp
curl https://chilkatdownload.com/9.5.0.98/build_chilkat-golang-1.zip -o build_chilkat-golang-1.zip
unzip build_chilkat-golang-1.zip
cd build_on_linux
chmod a+x *.sh
./installChilkat.sh
./buildExample1.sh
./buildExample2.sh

The installChilkat.sh script contains the following:

#!/bin/bash

# Change to any desired directory.
installDir=~

#----------------------------------------
# Check if the "tar" command exists
which tar

# Check the exit status
if [ $? -ne 0 ]; then
    echo "tar command does not exist."
    exit 1
fi

#----------------------------------------
# Check if the "unzip" command exists
which unzip

# Check the exit status
if [ $? -ne 0 ]; then
    echo "unzip command does not exist."
    echo "see https://www.tecmint.com/install-zip-and-unzip-in-linux/"
    exit 1
fi

#----------------------------------------
# Check if the "curl" command exists
which curl

# Check the exit status
if [ $? -ne 0 ]; then
    echo "curl command does not exist."
    echo "to install, sudo apt-get install curl"
    exit 1
fi

#----------------------------------------
# Check if the "sha256sum" command exists
which sha256sum

# Check the exit status
if [ $? -ne 0 ]; then
    echo "sha256sum command does not exist."
    exit 1
fi

# ------------------------------
echo "Installing to $installDir"

# Create the install directory if needed.
if [ ! -d "$installDir" ]; then
	if mkdir $installDir; then
	    echo "Created $installDir"
	else
	    echo "Failed to create $installDir"
 	    exit 1
	fi
fi
cd $installDir

# -------------------------------------------------------------------------
# Create the "chilkatsoft.com" directory underneath the install directory.
if [ ! -d "chilkatsoft.com" ]; then
	if mkdir chilkatsoft.com; then
	    echo "Created chilkatsoft.com"
	else
	    echo "Failed to create chilkatsoft.com"
 	    exit 1
	fi
fi

cd chilkatsoft.com

# --------------------------------------------------------------------
# The native "C" library download is based on the machine architecture
# Download and verify the SHA256 digest of the download is a expected.

# Possible machine architectures are:
# armv7l
# aarch64
# x86_64
# i686
# If your machine architecture is different, please let Chilkat know.
machineArch=`uname -m`

if [ "$machineArch" = "x86_64" ]; then
	echo "x86_64"
	archSubdir=linux-x64-gcc
	curl https://chilkatdownload.com/9.5.0.98/chilkatext-9.5.0-linux-x64-gcc-1.tar.gz -o chilkat_native_c.tar.gz
	if [ $? -ne 0 ]; then
		echo "curl download of the Chilkat native "C" library failed."
		exit 1
	fi
	digestSha256=`sha256sum chilkat_native_c.tar.gz`
	echo $digestSha256
	if [[ $digestSha256 == *e0b340b25d0d7809dd655fe6fdb68cc52d8b694f91d4c1c1025e7b274a47dcc1* ]]; then
		echo "Good, the SHA256 digest of chilkat_native_c.tar.gz is as expected."
	else
		echo "Digest of Chilkat native C library is not the expected value."
		exit 1
	fi
elif [ "$machineArch" = "i686" ]; then
	echo "i686"
	archSubdir=linux-x86-gcc
	curl https://chilkatdownload.com/9.5.0.98/chilkatext-9.5.0-linux-x86-gcc-1.tar.gz -o chilkat_native_c.tar.gz
	if [ $? -ne 0 ]; then
		echo "curl download of the Chilkat native "C" library failed."
		exit 1
	fi
	digestSha256=`sha256sum chilkat_native_c.tar.gz`
	echo $digestSha256
	if [[ $digestSha256 == *12a7283e1b00f493dede688ff65bc0b5451ad88bac502b9cbec8dce659b10cf0* ]]; then
		echo "Good, the SHA256 digest of chilkat_native_c.tar.gz is as expected."
	else
		echo "Digest of Chilkat native C library is not the expected value."
		exit 1
	fi
elif [ "$machineArch" = "aarch64" ]; then
	echo "aarch64"
	archSubdir=linux-aarch64-gcc
	curl https://chilkatdownload.com/9.5.0.98/chilkatext-9.5.0-linux-aarch64-gcc-1.tar.gz -o chilkat_native_c.tar.gz
	if [ $? -ne 0 ]; then
		echo "curl download of the Chilkat native "C" library failed."
		exit 1
	fi
	digestSha256=`sha256sum chilkat_native_c.tar.gz`
	echo $digestSha256
	if [[ $digestSha256 == *f7a0232629f5f804063286767526b9b048e57527117d830537b64eaf9f368052* ]]; then
		echo "Good, the SHA256 digest of chilkat_native_c.tar.gz is as expected."
	else
		echo "Digest of Chilkat native C library is not the expected value."
		exit 1
	fi
elif [ "$machineArch" = "armv7l" ]; then
	echo "armv7l"
	archSubdir=linux-armhf-clang
	curl https://chilkatdownload.com/9.5.0.98/chilkatext-9.5.0-linux-armhf-clang-1.tar.gz -o chilkat_native_c.tar.gz
	if [ $? -ne 0 ]; then
		echo "curl download of the Chilkat native "C" library failed."
		exit 1
	fi
	digestSha256=`sha256sum chilkat_native_c.tar.gz`
	echo $digestSha256
	if [[ $digestSha256 == *d2ac5e3a95f9c95e4dbb3277d21b3df19ab7ead8cd466354dee21387f986533c* ]]; then
		echo "Good, the SHA256 digest of chilkat_native_c.tar.gz is as expected."
	else
		echo "Digest of Chilkat native C library is not the expected value."
		exit 1
	fi
else
	echo "Unsupported architecture: $machineArch"
	exit 1
fi


# ---------------------------------------------------------
# Extract and rename the subdirectory to "native_c_lib"
#
# the resulting Chilkat native "C" static library is $installDir/chilkatsoft.com/native_c_lib/libchilkatext-9.5.0.a

if [ -d "native_c_lib" ]; then
	rm -rf native_c_lib
fi

if [ -d "$archSubdir" ]; then
	rm -rf $archSubdir
fi

tar xvf chilkat_native_c.tar.gz
if [ $? -ne 0 ]; then
	echo "extracting from .tar.gz failed."
	exit 1
fi

mv $archSubdir native_c_lib
rm -f chilkat_native_c.tar.gz

# --------------------------------------------------------
# Delete the "chilkat", "chilkat_example1", and "chilkat_example2" subdirectories
# from previous install attempts if they exist.

# (at this point, we are in the $installDir/chilkatsoft.com directory)
if [ -d "chilkat" ]; then
	rm -rf chilkat
fi
if [ -d "chilkat_example1" ]; then
	rm -rf chilkat_example1
fi
if [ -d "chilkat_example2" ]; then
	rm -rf chilkat_example2
fi
# also check for any previously downloaded "license.pdf"
if [ -e "license.pdf" ]; then
	rm -f license.pdf
fi

# --------------------------------------------------------
# Download the chilkat-golang-1.zip containing the Go source files that implement the Chilkat module, 
# which do so by calling into the Chilkat native "C" lib.

curl https://chilkatdownload.com/9.5.0.98/chilkat-golang-1.zip -o chilkat-golang-1.zip
if [ $? -ne 0 ]; then
	echo "curl download of chilkat-golang-1.zip failed."
	exit 1
fi

# Verify the SHA256 digest is correct.
digestSha256=`sha256sum chilkat-golang-1.zip`
echo $digestSha256
if [[ $digestSha256 == *46a7e7cf00c8ae4c723af90a255ad80fd38ad1396ef7bcaa2d16ad97fb2f8954* ]]; then
	echo "Good, the SHA256 digest of chilkat-golang-1.zip is as expected."
else
	echo "Digest of chilkat-golang-1.zip is not the expected value."
	exit 1
fi

# Unzip to create three subdirectories under $installDir/chilkatsoft.com:
# chilkat
# chilkat_example1
# chilkat_example2

unzip -q chilkat-golang-1.zip
if [ $? -ne 0 ]; then
	echo "unzipping chilkat-golang-1.zip failed."
	exit 1
fi

rm -f chilkat-golang-1.zip

# --------------------------------------------------------
echo "Let's build the Chilkat module..."
echo "This can take a minute or two, or three..."

CGO_LDFLAGS="-L$installDir/chilkatsoft.com/native_c_lib -lchilkatext-9.5.0 -lresolv -lpthread -ldl -lstdc++"

cd chilkat
go mod init chilkatsoft.com/chilkat
go build
if [ $? -ne 0 ]; then
	echo "go build failed."
	exit 1
fi

echo "Successfully built the Chilkat Go module."