-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathhead.hackage.sh
More file actions
executable file
·201 lines (146 loc) · 4.47 KB
/
head.hackage.sh
File metadata and controls
executable file
·201 lines (146 loc) · 4.47 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/sh
die () {
echo "ERROR: $1" >&2
exit 1
}
cat_repo () {
cat <<EOF
repository head.hackage
url: http://head.hackage.haskell.org/
secure: True
root-keys: 07c59cb65787dedfaef5bd5f987ceb5f7e5ebf88b904bbd4c5cbdeb2ff71b740
2e8555dde16ebd8df076f1a8ef13b8f14c66bad8eafefd7d9e37d0ed711821fb
8f79fd2389ab2967354407ec852cbe73f2e8635793ac446d09461ffb99527f6e
key-threshold: 3
EOF
}
# this needs to match the `remote-repo-cache` global config setting
PKGCACHE="${HOME}/.cabal/packages"
check_pkgcache () {
if [ ! -d "$PKGCACHE" ]; then
die "package cache folder ('$PKGCACHE') doesn't seem exist; please edit script"
fi
}
# CABAL executable
# If $CABAL env-var is set, use that; otherwise default to the executable 'cabal'
CABAL=${CABAL:-cabal}
# GHC handling
check_ghc () {
if [ -z "$GHC" -a -x "/opt/ghc/head/bin/ghc" ]; then
echo "INFO: \$GHC was unset. Using the detected '/opt/ghc/head/bin/ghc' executable!"
echo " Set \$GHC to a different compiler if needed or edit the generated"
echo " 'cabal.project(.local)' file accordingly"
echo ""
GHC="/opt/ghc/head/bin/ghc"
fi
# set $GHC to the name or (or full path if not in $PATH) of the GHC HEAD executable
if [ -z "$GHC" ]; then
die "set \$GHC with the path to your GHC HEAD executable"
elif [ ! -f "$GHC" -a ! -x "$GHC" ]; then
echo "WARNING: \$GHC='$GHC' does not appear to be a GHC executable"
fi
}
############################################################################
# main
case "X$1" in
Xupdate)
check_pkgcache
if "$CABAL" new-update --help > /dev/null 2>&1; then
echo "INFO: '$CABAL' is recent enough and supports 'cabal new-update head.hackage'; you can try using that directly!"
echo ""
CFGFILE=$(mktemp)
cat_repo > "$CFGFILE"
# we need to wipe the cache for head.hackage to workaround issues in hackage-security
rm -rf "$PKGCACHE/head.hackage/"
echo "http-transport: plain-http" >> "$CFGFILE"
"$CABAL" --project-file="$CFGFILE" new-update head.hackage
rm "$CFGFILE"
else
echo "INFO: '$CABAL' doesn't seem to support 'cabal new-update' yet. Using legacy fallback"
CFGFILE=$(mktemp)
cat_repo > "$CFGFILE"
# we need to wipe the cache for head.hackage to workaround issues in hackage-security
rm -rf "$PKGCACHE/head.hackage/"
echo "http-transport: plain-http" >> "$CFGFILE"
echo "remote-repo-cache: $PKGCACHE" >> "$CFGFILE"
"$CABAL" --config-file="$CFGFILE" update
rm "$CFGFILE"
fi
;;
Xdump-repo)
cat_repo
;;
Xinit)
if [ -e cabal.project ]; then
die "cabal.project file exists already, aborting! Use '$0 init-local' to generate a 'cabal.project.local' config."
else
check_ghc
echo "INFO: creating new cabal.project file"
{
cat <<EOF
-- generated by head.hackage.sh
with-compiler: $GHC
EOF
echo "packages: ."
shift
for PKG in "$@"; do
echo "optional-packages: $PKG"
done
echo ""
cat_repo
echo "-- end of generated content"
} > cabal.project
fi
;;
Xinit-local)
if [ ! -e cabal.project ]; then
die "cabal.project does not exist, aborting!"
exit 1
fi
if [ -e cabal.project.local ]; then
die "cabal.project.local file exists already, aborting!"
else
check_ghc
echo "INFO: creating new cabal.project.local file"
{
cat <<EOF
-- generated by head.hackage.sh
with-compiler: $GHC
EOF
shift
for PKG in "$@"; do
echo "optional-packages: $PKG"
done
echo ""
cat_repo
echo "-- end of generated content"
} > cabal.project.local
fi
;;
Xhelp)
cat <<EOF
Usage: $0 <command>
Known <commands>
update update head.hackage package index
init [folder(s)] create cabal.project file for GHC HEAD and
optionally populate 'packages:' with extra folders
init-local [folder(s)] create 'cabal.project.local' file for GHC HEAD
and optionally populate 'packages:' with extra folders
dump-repo dump 'repository' declaration to stdout and exit
help show help (you're here)
EOF
;;
X)
echo "no command given; try 'help'" >&2
exit 1
;;
*)
die "unrecognised command '$1'; try 'help'"
;;
esac
# Local variables:
# coding: utf-8
# mode: sh
# sh-basic-offset: 2
# sh-indentation: 2
# End: