2023-01-23 15:44:23 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-02-02 12:16:56 +01:00
|
|
|
INSTALL_DIR="/usr/local"
|
|
|
|
OBITOOLS_PREFIX=""
|
|
|
|
# default values
|
2023-01-23 15:44:23 +01:00
|
|
|
URL="https://go.dev/dl/"
|
2024-07-29 14:35:21 +02:00
|
|
|
OBIURL4="https://github.com/metabarcoding/obitools4/archive/refs/heads/master.zip"
|
2023-02-02 12:16:56 +01:00
|
|
|
INSTALL_DIR="/usr/local"
|
|
|
|
OBITOOLS_PREFIX=""
|
|
|
|
|
|
|
|
# help message
|
|
|
|
function display_help {
|
|
|
|
echo "Usage: $0 [OPTIONS]"
|
|
|
|
echo ""
|
|
|
|
echo "Options:"
|
|
|
|
echo " -i, --install-dir Directory where obitools are installed "
|
|
|
|
echo " (as example use /usr/local not /usr/local/bin)."
|
|
|
|
echo " -p, --obitools-prefix Prefix added to the obitools command names if you"
|
|
|
|
echo " want to have several versions of obitools at the"
|
|
|
|
echo " same time on your system (as example -p g will produce "
|
|
|
|
echo " gobigrep command instead of obigrep)."
|
|
|
|
echo " -h, --help Display this help message."
|
|
|
|
}
|
|
|
|
|
|
|
|
while [ "$#" -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
-i|--install-dir)
|
|
|
|
INSTALL_DIR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-p|--obitools-prefix)
|
|
|
|
OBITOOLS_PREFIX="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-h|--help)
|
2023-06-06 09:21:16 +02:00
|
|
|
display_help 1>&2
|
2023-02-02 12:16:56 +01:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
2023-06-06 09:21:16 +02:00
|
|
|
echo "Error: Unsupported option $1" 1>&2
|
2023-02-02 12:16:56 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# the directory from where the script is run
|
|
|
|
DIR="$(pwd)"
|
2023-01-23 15:44:23 +01:00
|
|
|
|
|
|
|
# the temp directory used, within $DIR
|
|
|
|
# omit the -p parameter to create a temporal directory in the default location
|
2023-02-02 12:16:56 +01:00
|
|
|
# WORK_DIR=$(mktemp -d -p "$DIR" "obitools4.XXXXXX" 2> /dev/null || \
|
|
|
|
# mktemp -d -t "$DIR" "obitools4.XXXXXX")
|
|
|
|
|
|
|
|
WORK_DIR=$(mktemp -d "obitools4.XXXXXX")
|
2023-01-23 15:44:23 +01:00
|
|
|
|
|
|
|
# check if tmp dir was created
|
|
|
|
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
|
2023-06-06 09:21:16 +02:00
|
|
|
echo "Could not create temp dir" 1>&2
|
2023-01-23 15:44:23 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-02-02 13:15:59 +01:00
|
|
|
mkdir -p "${INSTALL_DIR}/bin" 2> /dev/null \
|
2023-06-06 09:21:16 +02:00
|
|
|
|| (echo "Please enter your password for installing obitools in ${INSTALL_DIR}" 1>&2
|
2023-02-02 12:21:49 +01:00
|
|
|
sudo mkdir -p "${INSTALL_DIR}/bin")
|
|
|
|
|
2023-06-07 17:54:02 +02:00
|
|
|
if [[ ! -d "${INSTALL_DIR}/bin" ]]; then
|
2023-06-06 09:21:16 +02:00
|
|
|
echo "Could not create ${INSTALL_DIR}/bin directory for installing obitools" 1>&2
|
2023-02-02 12:21:49 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2025-03-27 16:45:02 +01:00
|
|
|
INSTALL_DIR="$(cd ${INSTALL_DIR} && pwd)"
|
2023-02-02 12:16:56 +01:00
|
|
|
|
2025-03-27 16:45:02 +01:00
|
|
|
echo "WORK_DIR=$WORK_DIR" 1>&2
|
|
|
|
echo "INSTALL_DIR=$INSTALL_DIR" 1>&2
|
|
|
|
echo "OBITOOLS_PREFIX=$OBITOOLS_PREFIX" 1>&2
|
2023-02-02 12:16:56 +01:00
|
|
|
|
2023-05-23 10:09:42 +02:00
|
|
|
pushd "$WORK_DIR"|| exit
|
2023-01-23 15:44:23 +01:00
|
|
|
|
|
|
|
OS=$(uname -a | awk '{print $1}')
|
|
|
|
ARCH=$(uname -m)
|
|
|
|
|
|
|
|
if [[ "$ARCH" == "x86_64" ]] ; then
|
|
|
|
ARCH="amd64"
|
|
|
|
fi
|
|
|
|
|
2023-06-06 10:02:24 +02:00
|
|
|
if [[ "$ARCH" == "aarch64" ]] ; then
|
|
|
|
ARCH="arm64"
|
|
|
|
fi
|
|
|
|
|
2023-01-23 15:44:23 +01:00
|
|
|
GOFILE=$(curl "$URL" \
|
|
|
|
| grep 'class="download"' \
|
|
|
|
| grep "\.tar\.gz" \
|
|
|
|
| sed -E 's@^.*/dl/(go[1-9].+\.tar\.gz)".*$@\1@' \
|
|
|
|
| grep -i "$OS" \
|
|
|
|
| grep -i "$ARCH" \
|
|
|
|
| head -1)
|
|
|
|
|
|
|
|
GOURL=$(curl "${URL}${GOFILE}" \
|
|
|
|
| sed -E 's@^.*href="(.*\.tar\.gz)".*$@\1@')
|
2023-06-06 09:21:16 +02:00
|
|
|
|
|
|
|
echo "Install GO from : $GOURL" 1>&2
|
2023-01-23 15:44:23 +01:00
|
|
|
|
|
|
|
curl "$GOURL" \
|
|
|
|
| tar zxf -
|
|
|
|
|
2023-06-06 10:11:37 +02:00
|
|
|
PATH="$(pwd)/go/bin:$PATH"
|
2023-06-06 10:13:13 +02:00
|
|
|
export PATH
|
2025-03-12 13:28:52 +01:00
|
|
|
GOPATH="$(pwd)/go"
|
|
|
|
export GOPATH
|
|
|
|
|
2025-05-01 11:45:46 +02:00
|
|
|
export GOCACHE="$(cd ${WORK_DIR}/cache && pwd)"
|
|
|
|
echo "GOCACHE=$GOCACHE" 1>&2@
|
|
|
|
mkdir -p "$GOCACHE"
|
2025-03-12 13:28:52 +01:00
|
|
|
|
2023-01-23 15:44:23 +01:00
|
|
|
|
2024-07-29 14:35:21 +02:00
|
|
|
curl -L "$OBIURL4" > master.zip
|
|
|
|
unzip master.zip
|
|
|
|
|
|
|
|
echo "Install OBITOOLS from : $OBIURL4"
|
2023-01-23 15:44:23 +01:00
|
|
|
|
2023-06-07 17:54:02 +02:00
|
|
|
cd obitools4-master || exit
|
2025-03-12 13:28:52 +01:00
|
|
|
mkdir vendor
|
2023-02-02 12:16:56 +01:00
|
|
|
|
|
|
|
if [[ -z "$OBITOOLS_PREFIX" ]] ; then
|
2025-03-12 13:28:52 +01:00
|
|
|
make GOFLAGS="-buildvcs=false"
|
2023-02-02 12:16:56 +01:00
|
|
|
else
|
2025-03-12 13:28:52 +01:00
|
|
|
make GOFLAGS="-buildvcs=false" OBITOOLS_PREFIX="${OBITOOLS_PREFIX}"
|
2023-02-02 12:16:56 +01:00
|
|
|
fi
|
2023-01-23 15:44:23 +01:00
|
|
|
|
2023-02-02 13:23:16 +01:00
|
|
|
(cp build/* "${INSTALL_DIR}/bin" 2> /dev/null) \
|
2023-02-02 13:37:27 +01:00
|
|
|
|| (echo "Please enter your password for installing obitools in ${INSTALL_DIR}"
|
|
|
|
sudo cp build/* "${INSTALL_DIR}/bin")
|
2023-01-27 14:50:45 +01:00
|
|
|
|
2023-06-07 17:54:02 +02:00
|
|
|
popd || exit
|
2023-01-27 14:50:45 +01:00
|
|
|
|
2025-03-12 13:28:52 +01:00
|
|
|
chmod -R +w "$WORK_DIR"
|
2023-06-07 17:54:02 +02:00
|
|
|
rm -rf "$WORK_DIR"
|
2023-01-27 14:50:45 +01:00
|
|
|
|