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/10.0.0/build_chilkat_go.zip -o build_chilkat_go.zip
unzip build_chilkat_go.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/10.0.0/chilkatext-linux-x64-gcc.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 == *5f2c36808f48f1b6c2d1eacdaac8a9d07e5434b6005e5fb6c0485aa5d564e076* ]]; 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/10.0.0/chilkatext-linux-x86-gcc.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 == *ce46a0a6cc3aa9d6a605442669f7dfb48131071173f4f167bcf1e405587a7a86* ]]; 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/10.0.0/chilkatext-linux-aarch64-gcc.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 == *8755ea1b932ac2cba622332efb4d3362854c38b22063f8c49db50d2e4e93483c* ]]; 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/10.0.0/chilkatext-linux-armhf-clang.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 == *6cfa2106c2f5c5e4146fb80d9b7c31a6ac86c56c7f916fe3b0405c63e7d08e68* ]]; 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.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_go.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/10.0.0/chilkat_go.zip -o chilkat_go.zip
if [ $? -ne 0 ]; then
	echo "curl download of chilkat_go.zip failed."
	exit 1
fi

# Verify the SHA256 digest is correct.
digestSha256=`sha256sum chilkat_go.zip`
echo $digestSha256
if [[ $digestSha256 == *145a00b66fffd3ce5b521044c3e0ce15631ce3b1544613e5fb657134454ae24c* ]]; then
	echo "Good, the SHA256 digest of chilkat_go.zip is as expected."
else
	echo "Digest of chilkat_go.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_go.zip
if [ $? -ne 0 ]; then
	echo "unzipping chilkat_go.zip failed."
	exit 1
fi

rm -f chilkat_go.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 -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."