r1996: Cope slightly better with invalid filenames in various places (reported by
[rox-filer.git] / install.sh
blobfc28512894b1101e67fc40d9d710824232b89243
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
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
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
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"
119 MIMEDIR="$DIR"
121 *) die "Invalid choice!";;
122 esac
124 MIMEINFO="${MIMEDIR}/packages/rox.xml"
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 rules will be:
137 $MIMEINFO
140 if [ ! -f rox.1 ]; then
141 echo '*** The ROX-Filer manpage (rox.1) is missing.'
142 echo '*** It can be created from Manual.xml by running'
143 echo "*** 'make' in the ROX-Filer/src/Docs directory."
144 echo '*** The daily CVS snapshots have it ready-built'
145 echo
146 MANDIR=""
149 if [ -n "$MANDIR" ]; then
150 echo "The manual pages will be:"
151 echo " $MANDIR/man1/rox.1"
152 echo " $MANDIR/man1/ROX-Filer.1"
153 else
154 echo "The manual page will not be installed."
157 echo
158 echo "OK?"
159 confirm_or_die
160 echo
162 if [ -n "$MANDIR" ]; then
163 echo "Installing manpage..."
164 endir "$MANDIR"
165 endir "$MANDIR/man1"
166 cp rox.1 "$MANDIR/man1/rox.1" || die "Can't install manpage!"
167 rm -f "$MANDIR/man1/ROX-Filer.1" || die "Can't install manpage!"
168 ln -s "$MANDIR/man1/rox.1" "$MANDIR/man1/ROX-Filer.1" || die "Can't install manpage!"
171 echo "Installing icons (existing icons will not be replaced)..."
172 endir "$CHOICESDIR/MIME-icons"
173 endir "$CHOICESDIR/MIME-types"
174 cd Choices || die "Choices missing"
175 for file in MIME-*/*; do
176 if [ -f "$file" ]; then
177 dest="$CHOICESDIR/$file"
178 if [ ! -f "$dest" ]; then
179 if [ ! -d "$dest" ]; then
180 echo Install $file as $dest
181 cp "$file" "$dest"
185 done
186 cd ..
188 endir "$MIMEDIR"
189 endir "$MIMEDIR/packages"
190 cp rox.xml "$MIMEINFO" || die "Failed to create $MIMEINFO"
191 update-mime-database "$MIMEDIR" || die "update-mime-database failed
192 Make sure you have installed the shared MIME database from:
193 http://www.freedesktop.org/standards/shared-mime-info.html"
195 echo "Installing application..."
196 endir "$APPDIR"
198 (cd ROX-Filer/src && make clean) > /dev/null 2>&1
199 if [ -d "$APPDIR/ROX-Filer" ]; then
200 echo "ROX-Filer is already installed - delete the existing"
201 echo "copy?"
202 confirm_or_die
203 echo Deleting...
204 rm -rf "$APPDIR/ROX-Filer"
206 cp -r ROX-Filer "$APPDIR"
208 echo "Installing launcher script..."
209 endir "$BINDIR"
211 cat > "$BINDIR/rox" << EOF
212 #!/bin/sh
213 exec $APPDIR/ROX-Filer/AppRun "\$@"
215 [ $? -eq 0 ] || die "Failed to install 'rox' script"
216 chmod a+x "$BINDIR/rox"
218 cat << EOF
220 Script installed. You can run the filer by simply typing 'rox'
221 Make sure that $BINDIR is in your PATH though - if it isn't then
222 you must use
223 \$ $BINDIR/rox
224 to run it instead.
226 ****************************
227 *** Now read the manual! ***
228 ****************************
230 Run ROX and click on the information icon on the toolbar:
232 \$ rox