install-curly.sh 1.47 KB
Newer Older
1
#!/bin/sh
2
curly_version="0.59.4.2"
3
curly_url="https://www.curly-lang.org/pkg/curly-$curly_version.tar.xz"
4

5
import_stdkeys=
6
7
prefix_dir="$HOME/.local"
lib_dir=
8
9
bin_dir=

10
while [ "$#" -gt  0 ]; do
11
12
13
14
15
16
17
18
19
20
    o="$1"; shift
    optval=
    case "$o" in
	-[pB]?*) optval="${o#-?}" optname="${o%$optval}";;
	--*=*) optname="${o%%=*}"; optval="${o#--*=}";;
	-[pB]|--prefix|--bin-dir) optname="$o"; optval="$1"; shift;;
	*) optname="$o";;
    esac
    case "$optname" in
	--import-standard-keys) import_stdkeys=true;;
21
22
	-p|--prefix) prefix_dir="$optval";;
	-L|--lib-dir) lib_dir="$optval";;
23
	-B|--bin-dir) bin_dir="$optval";;
24
25
26
    esac
done

27
28
if [ "${lib_dir:+x}" = '' ]; then
    read -p "Please enter a directory in which to install Curly (default: $prefix_dir/lib) : " lib_dir </dev/tty
29
fi
30
31
32
33
34
35
if [ "${lib_dir:+x}" = '' ]; then
    lib_dir="$prefix_dir/lib"
fi

if [ "${bin_dir:+x}" = '' ]; then
    bin_dir="$prefix_dir/bin"
36
37
38
39
40
41
42
43
44
45
46
47
fi

trace() { printf "\033[1m$ %s \033[m" "$*" >&2; "$@"; ret="$?"; echo >&2; return $ret; }
has_cmd() { which "$1" >/dev/null 2>&1; }
if has_cmd curl; then
    get_url() { curl -s "$1"; }
elif has_cmd wget; then
    get_url() { wget -q -O- "$1"; }
else
    get_url() { exit 1; }
fi

48
49
50
get_url "$curly_url" | { mkdir -p "$lib_dir"; trace tar -xJ --checkpoint=40 --checkpoint-action=dot -C "$lib_dir"; }
mkdir -p "$bin_dir"
trace ln -fs "$lib_dir/curly-$curly_version/curly" "$bin_dir/curly"
51
if [ -n "$import_stdkeys" ]; then
52
    "$bin_dir/curly" %'key import curly-std standard.curly-lang.org'
53
fi