r1526: Respect CHOICESPATH when installing (spotted by Vincent Lefevre).
[rox-filer.git] / install.sh
blob7df9799df6ce7fde7cd23605c9453e53e41ff86e
1 #!/bin/sh
3 die() {
4 echo "$*" >&2
5 echo "Aborting..." >&2
6 exit 1
9 get_dir() {
10 while [ 1 -eq 1 ]; do
11 printf "[$1] >>> "
12 read DIR
14 case "$DIR" in
15 /*) return;;
16 ?*) echo "The path must start with a \`/'";;
17 *) DIR="$1"
18 echo OK, using default value.
19 return;;
20 esac
21 done
24 # Create the directory if it doesn't exist. Exit if it can't be created.
25 endir() {
26 if [ ! -d "$1" ]; then
27 mkdir -p "$1" || die "Can't create $1 directory!"
31 confirm_or_die() {
32 while [ 1 -eq 1 ]; do
33 printf "[yes/no] >>> "
34 read CONFIRM
35 case "$CONFIRM" in
36 [yY]*) return;;
37 [nN]*) die "OK.";;
38 esac
39 done
42 cd `dirname $0`
44 echo Testing the filer...
45 ./ROX-Filer/AppRun -v
46 if [ $? -ne 0 ]; then
47 die "Filer doesn't work! Giving up..."
50 umask 022
53 cat << EOF
55 **************************************************************************
57 Where would you like to install the filer?
58 Normally, you should choose (1) if you have root access, or (2) if not.
60 1) Inside /usr/local
61 2) Inside my home directory
62 3) Inside /usr
63 4) Specify paths manually
65 Enter 1, 2, 3 or 4:
66 EOF
67 printf ">>> "
69 read REPLY
70 echo
72 case $REPLY in
73 1) APPDIR=/usr/local/apps
74 BINDIR=/usr/local/bin
75 MANDIR=/usr/local/man
76 CHOICESDIR=/usr/local/share/Choices
77 MIMEDIR=/usr/local/share/mime/mime-info
79 2) APPDIR=${HOME}/Apps
80 BINDIR=${HOME}/bin
81 if [ -n "$CHOICESPATH" ]; then
82 CHOICESDIR=`echo $CHOICESPATH | sed -e 's/^\([^:]*\).*$/\\1/'`
84 echo -$CHOICESDIR-
85 if [ ! -n "$CHOICESDIR" ]; then
86 CHOICESDIR=${HOME}/Choices
88 MIMEDIR=${HOME}/.mime/mime-info
89 if [ ! -d ${HOME}/man ]; then
90 MANDIR=""
91 else
92 MANDIR=${HOME}/man
95 3) APPDIR=/usr/apps
96 BINDIR=/usr/bin
97 MANDIR=/usr/man
98 CHOICESDIR=/usr/share/Choices
99 MIMEDIR=/usr/local/mime/mime-info
101 4) echo "Where should the ROX-Filer application go?"
102 get_dir "/usr/local/apps"
103 APPDIR="$DIR"
104 echo
105 echo "Where should the launcher script go?"
106 get_dir "/usr/local/bin"
107 BINDIR="$DIR"
108 echo
109 echo "Where should the manual page go?"
110 get_dir "/usr/local/man"
111 MANDIR="$DIR"
112 echo
113 echo "Where should the default icons and run actions go?"
114 get_dir "/usr/local/share/Choices"
115 CHOICESDIR="$DIR"
116 echo
117 echo "Where should the MIME info file go?"
118 get_dir "/usr/local/share/mime/mime-info"
119 MIMEDIR="$DIR"
121 *) die "Invalid choice!";;
122 esac
124 MIMEINFO="${MIMEDIR}/rox.mimeinfo"
126 cat << EOF
127 The application directory will be:
128 $APPDIR/ROX-Filer
130 The launcher script will be:
131 $BINDIR/rox
133 Icons and run actions will be in:
134 $CHOICESDIR
136 MIME-info rules will be:
137 $MIMEINFO
140 if [ -n "$MANDIR" ]; then
141 echo "The manual pages will be:"
142 echo " $MANDIR/man1/rox.1"
143 echo " $MANDIR/man1/ROX-Filer.1"
144 else
145 echo "The manual page will not be installed."
148 echo
149 echo "OK?"
150 confirm_or_die
151 echo
153 if [ -n "$MANDIR" ]; then
154 echo "Installing manpage..."
155 endir "$MANDIR"
156 endir "$MANDIR/man1"
157 cp rox.1 "$MANDIR/man1/rox.1" || die "Can't install manpage!"
158 rm -f "$MANDIR/man1/ROX-Filer.1" || die "Can't install manpage!"
159 ln -s "$MANDIR/man1/rox.1" "$MANDIR/man1/ROX-Filer.1" || die "Can't install manpage!"
162 echo "Installing icons (existing icons will not be replaced)..."
163 endir "$CHOICESDIR/MIME-icons"
164 endir "$CHOICESDIR/MIME-types"
165 cd Choices || die "Choices missing"
166 for file in MIME-*/*; do
167 if [ -f "$file" ]; then
168 dest="$CHOICESDIR/$file"
169 if [ ! -f "$dest" ]; then
170 if [ ! -d "$dest" ]; then
171 echo Install $file as $dest
172 cp "$file" "$dest"
176 done
177 cd ..
179 endir "$MIMEDIR"
180 cp rox.mimeinfo "$MIMEINFO" || die "Failed to create $MIMEINFO"
182 echo "Installing application..."
183 endir "$APPDIR"
185 (cd ROX-Filer/src; make clean) > /dev/null
186 if [ -d "$APPDIR/ROX-Filer" ]; then
187 echo "ROX-Filer is already installed - delete the existing"
188 echo "copy?"
189 confirm_or_die
190 echo Deleting...
191 rm -rf "$APPDIR/ROX-Filer"
193 cp -r ROX-Filer "$APPDIR"
195 echo "Installing launcher script..."
196 endir "$BINDIR"
198 cat > "$BINDIR/rox" << EOF
199 #!/bin/sh
200 exec $APPDIR/ROX-Filer/AppRun "\$@"
202 [ $? -eq 0 ] || die "Failed to install 'rox' script"
203 chmod a+x "$BINDIR/rox"
205 cat << EOF
207 Script installed. You can run the filer by simply typing 'rox'
208 Make sure that $BINDIR is in your PATH though - if it isn't then
209 you must use
210 \$ $BINDIR/rox
211 to run it instead.
213 ****************************
214 *** Now read the manual! ***
215 ****************************
217 Run ROX and click on the information icon on the toolbar:
219 \$ rox