r3894: If we can't find getopt_long, try looking in libgnugetopt
[rox-filer.git] / install.sh
blobf20d076131eba4c7329cfe5dfc696142b654a35b
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
64 5) Specify the prefix
66 Enter 1, 2, 3, 4 or 5:
67 EOF
68 printf ">>> "
70 read REPLY
71 echo
73 case $REPLY in
74 1) APPDIR=/usr/local/apps
75 BINDIR=/usr/local/bin
76 SHAREDIR=/usr/local/share
77 CHOICESDIR=${SHAREDIR}/Choices
78 MANDIR=/usr/local/man # (not under share!)
80 2) APPDIR=${HOME}/Apps
81 BINDIR=${HOME}/bin
82 if [ -n "$CHOICESPATH" ]; then
83 CHOICESDIR=`echo $CHOICESPATH | sed -e 's/^\([^:]*\).*$/\\1/'`
85 if [ ! -n "$CHOICESDIR" ]; then
86 CHOICESDIR=${HOME}/Choices
88 if [ -n "$XDG_DATA_HOME" ]; then
89 SHAREDIR=${XDG_DATA_HOME}
90 else
91 SHAREDIR=${HOME}/.local/share
93 MANDIR=${HOME}/man
94 if [ ! -d "$MANDIR" ]; then
95 MANDIR=
98 3) APPDIR=/usr/apps
99 BINDIR=/usr/bin
100 SHAREDIR=/usr/share
101 CHOICESDIR=${SHAREDIR}/Choices
102 MANDIR=${SHAREDIR}/man
104 4) echo "Where should the ROX-Filer application go?"
105 get_dir "/usr/local/apps"
106 APPDIR="$DIR"
107 echo
108 echo "Where should the launcher script go?"
109 get_dir "/usr/local/bin"
110 BINDIR="$DIR"
111 echo
112 echo "Where should the shared resources (eg, MIME data) go?"
113 get_dir "/usr/local/share"
114 SHAREDIR="$DIR"
115 echo
116 echo "Where should the default run actions go?"
117 get_dir "$SHAREDIR/Choices"
118 CHOICESDIR="$DIR"
119 echo
120 echo "Where should the man pages go?"
121 get_dir "/usr/local/man"
122 MANDIR="$DIR"
124 5) echo "What prefix should I use?"
125 get_dir "/usr/local"
126 APPDIR="$DIR/apps"
127 BINDIR="$DIR/bin"
128 SHAREDIR="$DIR/share"
129 CHOICESDIR=${SHAREDIR}/Choices
130 MANDIR="$DIR/man" # (not under share!)
133 *) die "Invalid choice!";;
134 esac
136 MIMEDIR=${SHAREDIR}/mime
138 MIMEINFO="${MIMEDIR}/packages/rox.xml"
140 cat << EOF
141 The application directory will be:
142 $APPDIR/ROX-Filer
144 The launcher script will be:
145 $BINDIR/rox
147 Run actions will be in:
148 $CHOICESDIR
150 MIME rules will be:
151 $MIMEINFO
154 if [ ! -f rox.1 ]; then
155 echo '*** The ROX-Filer manpage (rox.1) is missing.'
156 echo '*** It can be created from Manual.xml by running'
157 echo "*** 'make' in the ROX-Filer/src/Docs directory."
158 echo '*** The daily CVS snapshots have it ready-built'
159 echo
160 MANDIR=""
163 if [ -n "$MANDIR" ]; then
164 echo "The manual pages will be:"
165 echo " $MANDIR/man1/rox.1"
166 echo " $MANDIR/man1/ROX-Filer.1"
167 else
168 echo "The manual page will not be installed."
171 echo
172 echo "OK?"
173 confirm_or_die
174 echo
176 endir "$SHAREDIR"
178 if [ -n "$MANDIR" ]; then
179 echo "Installing manpage..."
180 endir "$MANDIR"
181 endir "$MANDIR/man1"
182 cp rox.1 "$MANDIR/man1/rox.1" || die "Can't install manpage!"
183 rm -f "$MANDIR/man1/ROX-Filer.1" || die "Can't install manpage!"
184 ln -s "$MANDIR/man1/rox.1" "$MANDIR/man1/ROX-Filer.1" || die "Can't install manpage!"
187 echo "Installing run actions (existing actions will not be replaced)..."
188 endir "$CHOICESDIR/MIME-types"
189 cd Choices || die "Choices missing"
190 for file in MIME-types/*; do
191 if [ -f "$file" ]; then
192 dest="$CHOICESDIR/$file"
193 if [ ! -f "$dest" ]; then
194 if [ ! -d "$dest" ]; then
195 echo Install $file as $dest
196 cp "$file" "$dest"
200 done
201 cd ..
203 endir "$MIMEDIR"
204 endir "$MIMEDIR/packages"
205 cp rox.xml "$MIMEINFO" || die "Failed to create $MIMEINFO"
206 update-mime-database "$MIMEDIR" || die "update-mime-database failed
207 Make sure you have installed the shared MIME database from:
208 http://www.freedesktop.org/software/shared-mime-info"
210 echo "Installing application..."
211 endir "$APPDIR"
213 (cd ROX-Filer/src && make clean) > /dev/null 2>&1
214 if [ -d "$APPDIR/ROX-Filer" ]; then
215 echo "ROX-Filer is already installed - delete the existing"
216 echo "copy?"
217 confirm_or_die
218 echo Deleting...
219 # Move it away first. If $APPDIR is on an nfs mount then deleting
220 # the binary may fail.
221 old="$APPDIR/.ROX-Filer.old"
222 if [ -d "$old" ]; then
223 echo "Cleaning up old copy from previous install."
224 rm -rf "$old"
226 mv "$APPDIR/ROX-Filer" "$old"
227 rm -rf "$old" || echo "Could not delete old copy.
228 This is usually because it is still executing. When it exits you may like
229 to delete $old"
231 cp -r ROX-Filer "$APPDIR"
233 echo "Installing launcher script..."
234 endir "$BINDIR"
236 cat > "$BINDIR/rox" << EOF
237 #!/bin/sh
238 exec $APPDIR/ROX-Filer/AppRun "\$@"
240 [ $? -eq 0 ] || die "Failed to install 'rox' script"
241 chmod a+x "$BINDIR/rox"
243 cat << EOF
245 Script installed. You can run the filer by simply typing 'rox'
246 Make sure that $BINDIR is in your PATH though - if it isn't then
247 you must use
248 \$ $BINDIR/rox
249 to run it instead.
251 ****************************
252 *** Now read the manual! ***
253 ****************************
255 Run ROX and click on the help icon on the toolbar:
257 \$ rox