-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·201 lines (168 loc) · 4.26 KB
/
install.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
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
SIGNATURE="emacs-pervasives"
# remote info
SRC_REPOS=tarao/emacs-pervasives
GITHUB=http://github.com
EMACSWIKI=http://www.emacswiki.org/emacs/download
RAW_GITHUB=https://raw.github.com
RAW_SRC=$RAW_GITHUB/$SRC_REPOS/master
# local info
EMACSD="$HOME/.emacs.d"
INIT_EL="$HOME/.emacs $HOME/.emacs.el $HOME/.emacs.d/init.el"
GITHUB_PACKAGES="m2ym/popup-el m2ym/auto-complete emacsmirror/undo-tree"
EMACSWIKI_PACKAGES="anything.el anything-match-plugin.el anything-config.el \
anything-obsolete.el anything-complete.el descbinds-anything.el"
PACKAGE_DST=$EMACSD/site-lisp
testing() {
[ -n "$TEST" ] && return 0
return 1
}
silent() {
cmd="$1"; shift
if [ -n "$VERBOSE" ]; then
$cmd "$@" && return
else
$cmd "$@" >/dev/null 2>&1 && return
fi
return 1
}
executable() {
type "$1" >/dev/null && return 0
return 1
}
if executable wget; then
wcat() {
wget -O - "$1" 2>/dev/null && return
return 1
}
elif executable curl; then
wcat() {
curl -L "$1" && return
return 1
}
fi
is_github() {
pattern='^\(git\|https\?\)://github\.com/[a-zA-Z0-9_]\+/[^/]\+\(\.git\)\?$'
echo "$1" | grep "$pattern" >/dev/null && return
return 1
}
github_repos() {
pat_github='\(git\|https\?\):\/\/github\.com'
pat_repos='\([a-zA-Z0-9_]\+\/[^/]\+\?\)'
strip_ext='s/^\(.*\)\.git$/\1/'
echo "$1" | sed -e "s/^$pat_github\/$pat_repos$/\\2/" | sed -e "$strip_ext"
}
pgit_clone() {
url="$1"; shift
executable git && git clone "$url" "$@" && return
is_github "$url" || return 1
executable sed || {
echo 'You need sed to retrieve repository without git command' >&2
return 1
}
http_repos=http://github.com/`github_repos "$url"`
https_repos=https://github.com/`github_repos "$url"`
svn_repos="$https_repos"
executable svn && svn checkout "$svn_repos/trunk" "$@" && return
executable tar && {
tar_url="$http_repos/tarball/master"
dir="$1"
mkdir -p "$dir"
wcat "$tar_url" | tar xfz - --strip-components 1 -C "$dir" && return
}
echo 'You need svn or tar to retrieve repository without git command' >&2
return 1
}
pgit() {
cmd="$1"; shift
case "$cmd" in
'' | '-h' | '--help')
echo 'pgit COMMAND'
;;
*)
cmd="pgit_$cmd"
executable "$cmd" && $cmd "$@" && return
return 1
;;
esac
}
clone() {
echo "Retrieving $GITHUB/$1"
testing && return
silent pgit clone "$GITHUB/$1" "$1" || {
echo 'You need either git, svn or tar to retrieve remote packages.'
return 1
}
}
emacswiki_get() {
echo "Retrieving $EMACSWIKI/$1"
testing && return
sleep 2
wcat "$EMACSWIKI/$1" > `basename "$1"`
}
select_init_el() {
for f in $@; do
[ -w "$f" ] && {
echo $f
return
}
done
echo $f
}
install_init_el() {
init=`select_init_el $INIT_EL`
echo "Emacs init file: $init"
if grep "$SIGNATURE" "$init" >/dev/null 2>&1; then
echo "$SIGNATURE is already installed"
return
fi
echo "Adding $RAW_SRC/init.el to $init"
testing || wcat "$RAW_SRC/init.el" >> "$init"
}
emacs_compile() {
echo -n "Compiling '$2'..."
testing || {
if silent emacs $1 --batch -f batch-byte-compile "$2"; then
echo 'done'
else
echo 'fail'
fi
}
}
compile_els() {
[ -d "$2" ] || return
last=`pwd`
cd "$2"
for f in `ls *.el`; do
emacs_compile "$1" "$f"
done
cd "$last"
}
install_github_packages() {
load_path='-L .'
for repos in "$@"; do
[ -d "$repos" ] || clone "$repos"
dir=`pwd`
compile_els "$load_path" "$repos"
load_path="$load_path -L $dir/$repos"
done
}
install_emacswiki_packages() {
load_path='-L .'
for file in "$@"; do
[ -e "$" ] || emacswiki_get "$file"
emacs_compile "$load_path" `basename "$file"`
done
}
( executable grep && executable wcat ) || {
echo 'You need the following commands:'
echo ' - grep'
echo ' - wget or curl'
exit 1
}
mkdir -p "$EMACSD"
install_init_el
mkdir -p "$PACKAGE_DST"
cd "$PACKAGE_DST"
install_github_packages $GITHUB_PACKAGES
install_emacswiki_packages $EMACSWIKI_PACKAGES