This repository has been archived by the owner on Sep 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbootstrap_dev.sh
executable file
·166 lines (149 loc) · 3.21 KB
/
bootstrap_dev.sh
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
#!/bin/bash -e
#
# bootstrap_dev.sh
#
# Install marelle for the current user only.
#
function has_exec() {
[ ! -z "$(which $1)" ]
}
function missing_exec() {
[ -z "$(which $1)" ]
}
is_apt_updated=0
function apt_update() {
if [ $is_apt_updated -eq 0 ]; then
sudo apt-get update
is_apt_updated=1
fi
}
is_brew_updated=0
function brew_update() {
if [ $is_brew_updated -eq 0 ]; then
brew update
is_brew_updated=1
fi
}
function install_git() {
echo 'Trying to install git'
case $(uname -s) in
Darwin)
if has_exec brew; then
brew_update
brew install git
else
bail "Please install Homebrew and retry"
fi
;;
Linux)
if has_exec apt-get; then
apt_update
sudo apt-get install -y git
elif has_exec yum; then
# XXX yum update?
sudo yum install git
else
bail "Unknown linux variant"
fi
;;
FreeBSD)
if has_exec pkg; then
sudo pkg install -y git
else
bail "Old FreeBSD version without pkgng"
fi
;;
*)
bail "Unknown operating system $(uname -s)"
;;
esac
}
function install_prolog() {
echo 'Trying to install prolog'
case $(uname -s) in
Darwin)
if has_exec brew; then
brew_update
brew install swi-prolog
else
bail "Please install Homebrew and retry"
fi
;;
Linux)
if has_exec apt-get; then
apt_update
sudo apt-get install -y swi-prolog-nox
elif has_exec yum; then
sudo yum install swi-prolog
else
bail "Unknown linux variant"
fi
;;
FreeBSD)
if has_exec pkg; then
sudo pkg install -y swi-pl
else
bail "Old FreeBSD version without pkgng"
fi
;;
*)
bail "Unknown operating system $(uname -s)"
;;
esac
}
function bail()
{
echo "$1 -- bailing"
exit 1
}
function check_in_path() {
echo $PATH | tr ':' '\n' | grep -x -c "$1";
}
function checkout_marelle() {
echo 'Trying to check out marelle'
mkdir -p ~/.local/bin
git clone https://github.com/larsyencken/marelle ~/.local/marelle
cat >~/.local/bin/marelle <<EOF
#!/bin/sh
exec swipl -q -t main -s ~/.local/marelle/marelle.pl "\$@"
EOF
chmod a+x ~/.local/bin/marelle
if [ ! -d ~/.local/marelle -o ! -x ~/.local/bin/marelle ]; then
bail "Ran into a problem checking out marelle"
fi
}
function put_marelle_in_path() {
echo 'Checking if marelle is in PATH'
if [ -f ~/.bash_profile ]; then
echo 'export PATH=~/.local/bin:$PATH' >>~/.bash_profile
source ~/.bash_profile
elif [ -f ~/.profile ]; then
echo 'export PATH=~/.local/bin:$PATH' >>~/.profile
source ~/.profile
fi
if missing_exec marelle; then
bail "Couldn't set up marelle in PATH. Add ~/.local/bin to your PATH in your shell's rc."
fi
}
function main() {
echo 'BOOTSTRAPPING MARELLE'
if missing_exec git; then
install_git
fi
echo 'Git: OK'
if missing_exec swipl; then
install_prolog
fi
echo 'Prolog: OK'
if [ ! -d ~/.local/marelle ]; then
checkout_marelle
fi
echo 'Marelle: OK'
hash -r
if missing_exec marelle; then
put_marelle_in_path
fi
echo 'Marelle in PATH: OK'
echo 'DONE'
}
main