telegps: Get telegps application working again
[fw/altos] / altosui / linux-install.sh
1 #!/bin/sh
2
3 can_ask=y
4
5 finish()
6 {
7     if [ "$can_ask" = "y" ]; then
8         echo ""
9         echo -n "Press enter to continue..."
10         read foo
11     fi
12     exit $1
13 }
14
15 #
16 # Make sure we have a terminal to talk to
17 #
18
19 if tty -s; then
20     :
21 else
22     case "$DISPLAY" in
23         "")
24         echo 'No user input available'
25         can_ask=n
26         ;;
27         *)
28         GUESS_XTERMS="x-terminal-emulator xterm rxvt roxterm gnome-terminal dtterm eterm Eterm kvt konsole aterm"
29         for a in $GUESS_XTERMS; do
30             if type $a >/dev/null 2>&1; then
31                 XTERM=$a
32                 break
33             fi
34         done
35         case "$XTERM" in
36             "")
37             echo 'No terminal emulator available'
38             can_ask=n
39             ;;
40             *)
41             exec "$XTERM" -e "sh '$0'"
42             ;;
43         esac
44         ;;
45     esac
46 fi
47
48 #
49 # Make sure we can run java
50 #
51
52 echo -n "Checking for java..."
53
54 if java -version > /dev/null 2>&1; then
55     echo " found it."
56 else
57     echo " java isn't working."
58     echo ""
59     echo "You'll need to install a java runtime system"
60     echo "on this computer before AltOS will work properly."
61     finish 1
62 fi
63     
64 #
65 # Pick an installation target
66
67
68 if [ '(' -d /opt -a -w /opt ')' -o '(' -d /opt/AltOS -a -w /opt/AltOS ')' ]; then
69     target_default=/opt
70 else
71     target_default="$HOME"
72 fi
73
74 case "$#" in
75 0)
76     echo -n "Installation location [default: $target_default] "
77     if [ "$can_ask" = "y" ]; then
78         read target
79     else
80         echo ""
81         target=""
82     fi
83     case "$target" in
84         "")
85         target="$target_default"
86         ;;
87     esac
88     ;;
89 *)
90     target="$1"
91     ;;
92 esac
93
94 target_altos="$target"/AltOS
95
96 echo -n "Installing to $target..."
97
98 #
99 # Make sure the target exists
100 #
101 mkdir -p "$target_altos"
102
103 if [ ! -d "$target_altos" ]; then
104     echo "$target_altos does not exist and cannot be created"
105     finish 1
106 fi
107
108 if [ ! -w "$target_altos" ]; then
109     echo "$target_altos cannot be written"
110     finish 1
111 fi
112
113 #
114 # Unpack the tar archive appended to the end of this script
115 #
116 archive_line=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' "$0"`
117
118 tail -n+$archive_line "$0" | tar xjf - -C "$target"
119
120 case $? in
121 0)
122     echo " done."
123     ;;
124 *)
125     echo "Install failed."
126     finish 1
127     ;;
128 esac
129
130 #
131 # Create the .desktop file by editing the paths
132 #
133
134 case "$target" in
135 /*)
136     target_abs="$target"
137     ;;
138 *)
139     target_abs=`pwd`/$target
140     ;;
141 esac
142
143 BIN="$target_abs"/AltOS
144
145 for infile in "$target"/AltOS/*.desktop.in; do
146     desktop="$target"/AltOS/`basename "$infile" .in`
147     rm -f "$desktop"
148     sed -e "s;%bindir%;$BIN;" -e "s;%icondir%;$BIN;" "$infile" > "$desktop"
149     chmod +x "$desktop"
150 done
151
152 #
153 # Install the .desktop file
154 #
155
156 for desktop in "$target"/AltOS/*.desktop; do
157     case `id -u` in
158         0)
159             xdg-desktop-menu install --mode system "$desktop"
160             ;;
161         *)
162             xdg-desktop-menu install --mode user "$desktop"
163             ;;
164     esac
165 done
166
167 #
168 # Install mime type file
169 #
170
171 for mimetype in "$target"/AltOS/*-mimetypes.xml; do
172     case `id -u` in
173         0)
174             xdg-mime install --mode system "$mimetype"
175             ;;
176         *)
177             xdg-mime install --mode user "$mimetype"
178             ;;
179     esac
180 done
181
182 #
183 # Install icons
184 #
185
186 for icon_dir in /usr/share/icons/hicolor/scalable/mimetypes "$HOME/.icons" "$HOME/.kde/share/icons"; do
187     if [ -w "$icon_dir" ]; then
188         cp "$target"/AltOS/*.svg "$icon_dir"
189         update-icon-caches "$icon_dir"
190     fi
191 done
192
193
194 #
195 # Install icon to desktop if desired
196 #
197
198 if [ -d $HOME/Desktop ]; then
199     default_desktop=n
200     if [ "$can_ask" = "y" ]; then
201         :
202     else
203         default_desktop=y
204     fi
205
206     answered=n
207     while [ "$answered" = "n" ]; do
208         echo -n "Install icons to desktop? [default: $default_desktop] "
209         if [ "$can_ask" = "y" ]; then
210             read do_desktop
211         else
212             echo
213             do_desktop=""
214         fi
215
216         case "$do_desktop" in
217             "")
218             do_desktop=$default_desktop
219             ;;
220         esac
221
222         case "$do_desktop" in
223         [yYnN]*)
224             answered=y
225             ;;
226         esac
227     done
228
229     case "$do_desktop" in
230         [yY]*)
231             echo -n "Installing desktop icons..."
232             for d in "$target"/AltOS/*.desktop; do
233                 base=`basename $d`
234                 cp --remove-destination "$d" "$HOME/Desktop/"
235             done
236             ;;
237     esac
238
239     echo " done."
240 fi
241
242 finish 0
243
244 __ARCHIVE_BELOW__