-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup-ghc
executable file
·110 lines (99 loc) · 3.37 KB
/
setup-ghc
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
#!/bin/bash
#
# Setup GHC environment to build Ganeti
set -euo pipefail
SCRIPT_DIR=$(dirname $(readlink -f $0))
CACHE_DIR="${SCRIPT_DIR}/cache"
GHC_PREFIX="${HOME}/local"
if [[ ${EUID:-${UID}} = 0 ]]; then
GHC_PREFIX="/usr/local"
fi
# RPM macros
RPM_MACROS=/usr/lib/rpm/macros.d/macros.dist
if [[ -f /etc/rpm/macros.dist ]]; then
# el7 and el8
RPM_MACROS=/etc/rpm/macros.dist
fi
RPM_DIST=.$(egrep -o "^%el[0-9]*" "${RPM_MACROS}" | tr -d '%')
echo "RPM_DIST: ${RPM_DIST} (${RPM_MACROS})"
# Setup cache directory
if [[ ! -d "${CACHE_DIR}" ]]; then
mkdir -p "${CACHE_DIR}"
fi
# Install dependencies
echo "# Install dependencies for GHC"
if [[ -f /usr/bin/dnf ]]; then
if [[ "${RPM_DIST}" = ".el8" ]]; then
# el8
sudo dnf -y install libcurl-devel pcre-devel zlib-devel gmp-devel ncurses-compat-libs
else
# el9 or later
sudo dnf -y install libcurl-devel pcre-devel zlib-devel gmp-devel
# for GHC
ln -sf /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
fi
else
sudo yum -y install libcurl-devel pcre-devel zlib-devel gmp-devel
fi
TMP_DIR=$(mktemp -d "${HOME}/tmp.XXXXXXXXXX")
pushd "${TMP_DIR}"
# Install ghc
# Ubuntu 20.04.01 LTS + initial: 8.6.5
# Ubuntu 20.04.01 LTS + apt upgrade: 8.8.1
#
# NG: GHC_VERSION=8.8.4
# Error:
# + cabal install cryptonite -f -use_target_attributes
# cabal: Error: Could not find module: AutoConf with any suffix:
# ["gc","chs","hsc","x","y","ly","cpphs","hs","lhs","hsig","lhsig"]. If the
# module is autogenerated it should be added to 'autogen-modules'.
GHC_VERSION=8.6.5
echo "# Install GHC version ${GHC_VERSION}"
if ! type ghc > /dev/null 2>&1; then
GHC_BINARY_PACKAGE="ghc-${GHC_VERSION}-x86_64-centos7-linux.tar.xz"
GHC_URL="https://downloads.haskell.org/~ghc/${GHC_VERSION}/${GHC_BINARY_PACKAGE}"
CACHE_FILE="${CACHE_DIR}/${GHC_BINARY_PACKAGE}"
echo "- Check cache file: ${CACHE_FILE}"
if [[ ! -f "${CACHE_FILE}" ]]; then
echo "- Downlod URL: ${GHC_URL}"
curl -fsSL "${GHC_URL}" -O
cp -a "${GHC_BINARY_PACKAGE}" "${CACHE_FILE}"
else
echo "- Use cache file: ${CACHE_FILE}"
cp -a "${CACHE_FILE}" .
fi
tar xf "${GHC_BINARY_PACKAGE}"
cd "ghc-${GHC_VERSION}"
./configure --prefix="${GHC_PREFIX}"
make install
else
echo "- Skip: ghc found. $(ghc --version)"
fi
# Install cabal-install
echo "# Install cabal-install"
if ! type cabal > /dev/null 2>&1; then
# Cabal-3.0.1.0 -> 3.0.0.0
CABAL_VERSION=$(ghc-pkg list Cabal | grep Cabal- | head -1 | egrep -o "\-[0-9].[0-9]" | cut -d'-' -f 2).0.0
echo "- Install Cabal version ${CABAL_VERSION}"
CABAL_BINARY_PACKAGE="cabal-install-${CABAL_VERSION}-x86_64-unknown-linux.tar.gz"
CABAL_URL="https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/${CABAL_BINARY_PACKAGE}"
CACHE_FILE="${CACHE_DIR}/${CABAL_BINARY_PACKAGE}"
echo "- Check cache file: ${CACHE_FILE}"
if [[ ! -f "${CACHE_FILE}" ]]; then
echo "- Downlod URL: ${CABAL_URL}"
curl -fsSL "${CABAL_URL}" -O
cp -a "${CABAL_BINARY_PACKAGE}" "${CACHE_FILE}"
else
echo "- Use cache file: ${CACHE_FILE}"
cp -a "${CACHE_FILE}" .
fi
tar xf "${CABAL_BINARY_PACKAGE}"
rm -f cabal.sig
mkdir -p "${GHC_PREFIX}/bin"
mv cabal "${GHC_PREFIX}/bin/"
echo "- Cabal update"
cabal update
else
echo "- Skip: cabal found. $(cabal --version)"
fi
popd