Added quotes around filenames.
[scripts.git] / emacs-cvs-in-debian.sh
1 #!/bin/bash
2
3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify  #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation.                         #
7 #                                                                       #
8 # This program is distributed in the hope that it will be useful, but   #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of            #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
11 # General Public License for more details.                              #
12 #                                                                       #
13 # You should have received a copy of the GNU General Public License     #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.  #
15 #                                                                       #
16 # Written by and Copyright (C) Francois Fleuret                         #
17 # Contact <francois@fleuret.org> for comments & bug reports             #
18 #########################################################################
19
20 # You need at least the Debian packages: gcc make cvs texinfo
21 # libx11-dev libxft-dev libgif-dev libjpeg62-dev libpng12-dev
22 # libtiff4-dev libxpm-dev
23
24 set -e
25
26 DIR=/usr/local/emacs-snapshot
27
28 while [[ $1 ]]; do
29
30     case $1 in
31
32         ################################################################
33
34         download)
35
36             mkdir -p ${DIR}
37
38             cd ${DIR}
39
40             cvs -z3 \
41                 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs \
42                 co emacs
43
44             ;;
45
46         ################################################################
47
48         compile)
49
50             cd ${DIR}/emacs/
51
52             # I do not like gtk and such, hence the very limited
53             # configuration options. Feel free to add your own.
54
55             ./configure --prefix=${DIR} \
56                 --with-xpm --with-jpeg --with-tiff --with-png \
57                 --with-x --with-xft
58
59             make -k bootstrap
60             make install
61
62             ;;
63
64         ################################################################
65
66         install)
67
68             if [[ -a /usr/share/emacs-snapshot ]]; then
69                 echo "You have to remove /usr/share/emacs-snapshot." >&2
70                 exit 1
71             fi
72
73             # We do not know the version you downloaded. This ugly
74             # command will figure it out for you
75
76             SHARE=$(find ${DIR}/share/emacs/ -maxdepth 1 -mindepth 1 -type d \
77                 | \grep "/[0-9\.]*$")
78
79             if [[ ! -d "${SHARE}" ]]; then
80                 echo "Can not find ${SHARE}, that's weird." >&2
81                 exit 1
82             fi
83
84             ln -s ${SHARE}/ /usr/share/emacs-snapshot
85
86             for p in emacs ctags etags emacsclient ebrowse; do
87                 # Install the binary as a link in /usr/bin
88                 ln -s ${DIR}/bin/$p /usr/bin/$p-snapshot
89                 # Tell the Debian system that the binary can be used
90                 # as an alternative version
91                 update-alternatives \
92                     --install /usr/bin/$p $p /usr/bin/$p-snapshot 23
93                 # Tell the Debian system that that new version should
94                 # be used as default
95                 update-alternatives \
96                     --set $p /usr/bin/$p-snapshot
97             done
98
99             mkdir -p /etc/emacs-snapshot/site-start.d
100
101             # Compile and install for that version of emacs all the
102             # emacs packages installed as Debian packages (vm, bbdb,
103             # etc.)
104             /usr/lib/emacsen-common/emacs-install emacs-snapshot
105
106             ;;
107
108         ################################################################
109
110         deinstall)
111
112             # Remove that version of emacs from the list of versions
113             # for which Debian emacs-related packages should be
114             # compiled
115             /usr/lib/emacsen-common/emacs-remove emacs-snapshot
116
117             rm -rf /etc/emacs-snapshot
118
119             # Remove the alternatives
120             for p in emacs ctags etags emacsclient ebrowse; do
121                 update-alternatives --remove $p /usr/bin/$p-snapshot
122                 rm /usr/bin/$p-snapshot
123             done
124
125             rm /usr/share/emacs-snapshot
126             ;;
127
128         ################################################################
129
130         remove)
131
132             rm -rf ${DIR}
133
134             ;;
135
136         ################################################################
137
138         *)
139
140             echo "$0 <download | compile | install | deinstall | remove>" >&2
141             exit 1
142
143             ;;
144
145     esac
146
147     shift 1
148
149 done