This repository has been archived by the owner on Nov 27, 2019. It is now read-only.
/
grab-lily-sources.sh
225 lines (200 loc) · 7.27 KB
/
grab-lily-sources.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
# this script will set up everything (hopefully) that you
# need to compile LilyPond from source - that is, it will:
# - install appropriate version of git
# - download required libraries
# - clone lilypond sources
# - clone scripts by Janek that make building easier
# - set environment variables used by various lilypond scripts.
#
# You will be asked where the lilypond sources and Janek's
# scripts should be placed.
#
# With -y option, the script will assume that your answer
# to all questions is 'yes'.
# With -b option, lilypond will be built immediately after
# the script finishes.
#
# This script was written for Ubuntu and Ubuntu-based Linux
# distributions. It should work on other distributions that
# use apt package manager (for example Debian), but you may
# have to change 'sudo' to 'su', for example.
if [ ! "$BASH_VERSION" ] ; then
echo "Please do not use sh to run this script - i.e., don't run" 1>&2
echo " sh $0" 1>&2
echo "Use bash instead, or just execute it directly like this:" 1>&2
echo " ./$0" 1>&2
exit 1
fi
while getopts "bd:yw" opts; do
case $opts in
b)
default_compilation="master";;
d)
location=$OPTARG;;
y)
yes="--yes";; # assume 'yes' to questions
w)
nocolors="--color=never";;
esac
done
#########################################################
# helper functions:
die() { # in case of error
echo -e "$@\nExiting."
exit 1
}
check_version() {
# returns 0 (i.e. success) if the first argument is greater
# or equal to the second (interpreted as version numbers)
[ "$2" = "$(echo -e "$2\n$1" | sort -V | head -n1)" ]
}
countdown() {
for i in {1..5}; do
sleep $(echo $1 / 5 | bc -l)
echo -n .
done
echo ""
}
install_git() {
sudo add-apt-repository $yes ppa:git-core/ppa
sudo apt-get $yes update
sudo apt-get $yes install git
}
if [ -z $nocolors ]; then
normal="\e[00m"
red="\e[00;31m"
green="\e[00;32m"
yellow="\e[00;33m"
blue="\e[00;34m"
violet="\e[00;35m"
cyan="\e[00;36m"
gray="\e[00;37m"
bold="$(tput bold)"
dircolor=$violet
fi
##########################################################
# Where all lilypond stuff should be placed?
if [ -n "$LILYPOND_GIT" ]; then
echo "It seems that you already have some LilyPond"
echo "configuration: your \$LILYPOND_GIT points to"
echo -e " $LILYPOND_GIT\n"
sleep 1
location="$(readlink -m $LILYPOND_GIT/..)"
else
if [ -z "$location" ]; then
echo "Where would you like LilyPond stuff to be placed?"
echo "Please specify a path relative to your home directory."
echo "Subdirectories with LilyPond sources, binaries and"
echo "building scripts will be placed there."
read location
fi
location=$HOME/$location
LILYPOND_GIT="$location/lilypond-sources"
fi
if [ -z "$LILYPOND_BUILD_DIR" ]; then
LILYPOND_BUILD_DIR="$location/lilypond-builds"
fi
JANEK_SCRIPTS="$location/janek-scripts"
echo "I will download LilyPond sources and other stuff into"
echo -en "$dircolor $location $normal"
countdown 5
mkdir -p $location
# make sure a recent enough version of git is installed
which git &>/dev/null
if [ $? != 0 ]; then
echo "Git isn't installed on your computer. Installing now..."
install_git
else
# is installed git version recent enough?
git_required="1.8"
# there's a build number after the last dot.
git_installed=$(git --version | sed 's/git\ version\ //' | sed 's/.[^.]*$//')
check_version $git_installed $git_required
if [ $? = 1 ]; then
echo "You have git version $git_installed."
echo "Required version is $git_required."
echo "Installing newer git version..."
install_git
fi
fi
echo ""
echo "Installing packages needed for compiling LilyPond:"
sudo apt-get $yes build-dep lilypond \
|| die "Failed to install build dependencies for LilyPond." \
"\nMaybe your system is too old and the package repositories" \
"\nare no longer available?" \
"\nOr maybe your package manager configuration should be changed?" \
"\nMake sure that your package manager will search the 'source'" \
"\nrepositories (containing source code packages)." \
"\n(I am just guessing...)"
# Note from Urs:
#
# If you don't have TeXLive installed through your OS's package
# manager the script will install it for you. Unfortunately this is
# also necessary if you have installed TeXLive manually through its
# own distribution. Having two separate installations of TeXLive is
# (apart from disk space) no problem at all, you just have to make
# sure that your system finds the right version first on its search
# path. However, if you didn't install the full TeXLive
# distribution the LilyPond build process may fail due to missing
# packages. In that case you have to make sure all relevant
# packages are present, if in doubt you may simply to 'tlmgr
# install scheme-full'.
sudo apt-get $yes install autoconf || die "Failed to install autoconf."
sudo apt-get $yes install dblatex || die "Failed to install dblatex."
sudo apt-get $yes install texlive-lang-cyrillic \
|| die "Failed to install texlive-lang-cyrillic."
# clone lilypond sources
if [ ! -d "$LILYPOND_GIT/.git" ]; then
# $LILYPOND_GIT doesn't exist yet or is not a git repository
git clone git://git.sv.gnu.org/lilypond.git $LILYPOND_GIT \
|| die "Failed to clone LilyPond."
fi
# also, clone a repository with helpful scripts written by Janek:
if [ ! -d "$JANEK_SCRIPTS/.git" ]; then
git clone https://github.com/janek-warchol/cli-tools.git $JANEK_SCRIPTS \
|| die "Failed to clone Janek's scripts."
fi
lilypond_bash_settings="
# environment variables and aliases for LilyPond work:
export LILYPOND_GIT=$LILYPOND_GIT
export LILYPOND_BUILD_DIR=$LILYPOND_BUILD_DIR
alias build-lilypond=$JANEK_SCRIPTS/lilypond/build-lily.sh
alias update-lilypond-sources=$JANEK_SCRIPTS/lilypond/pull-all.sh
lily() {
# A shorthand for running custom-built LilyPond versions
# from command line. Usage example:
# lily master somefile
# this will compile 'somefile' using LilyPond from 'master'
# subdirectory of \$LILYPOND_BUILD_DIR (assuming it exists).
lily_version=\"\$1\"
shift
\"\$LILYPOND_BUILD_DIR/\$lily_version/out/bin/lilypond\" \"\$@\"
}
"
# add the above settings to bash initialization file
echo -en "$lilypond_bash_settings" | tee -a ~/.bashrc
# use them in this script, so that calling build-lily will work:
eval "$lilypond_bash_settings"
echo -en "
===============================================================
The script was successful. You have LilyPond source code in
$dircolor $LILYPOND_GIT$normal
and some scripts and other stuff written by Janek Warchoł in
$JANEK_SCRIPTS.
To complete the \"installation\",$bold please restart your terminal
$normal(some settings need to be reloaded).
After that, use 'build-lilypond' command to compile lilypond. Run
build-lilypond --help
to learn how to use it. For a more detailed introduction, see
$JANEK_SCRIPTS/lilypond/intro-text.md
"
# the script was run with -b option: build lilypond right away
if [ -n "$default_compilation" ]; then
echo -en "\nbuild-lilypond will be ran in 15 seconds "
countdown 15
$JANEK_SCRIPTS/lilypond/build-lily.sh -c "$default_compilation"
else
echo "==============================================================="
fi