altosui: Add ignitor tab for TeleMega extra ignitors
[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 case "$target" in
134 /*)
135     target_abs="$target"
136     ;;
137 *)
138     target_abs=`pwd`/$target
139     ;;
140 esac
141
142 BIN="$target_abs"/AltOS
143
144 for infile in "$target"/AltOS/*.desktop.in; do
145     desktop="$target"/AltOS/`basename "$infile" .in`
146     rm -f "$desktop"
147     sed -e "s;%bindir%;$BIN;" -e "s;%icondir%;$BIN;" "$infile" > "$desktop"
148     chmod +x "$desktop"
149 done
150
151 #
152 # Figure out where to install the .desktop files. If we can, write it
153 # to the public /usr/share/applications, otherwise, write it to the
154 # per-user ~/.local/share/applications
155 #
156
157 public=/usr/share/applications
158 private=$HOME/.local/share/applications
159 apps=""
160
161 if [ -d "$public" -a -w "$public" ]; then
162     apps="$public"
163 else
164     mkdir -p "$private" >/dev/null 2>&1 
165     if [ -d "$private" -a -w "$private" ]; then
166         apps="$private"
167     fi
168 fi
169         
170 case "$apps" in
171 "")
172     echo "Cannot install application icon"
173     finish 1
174     ;;
175 esac
176
177 echo -n "Installing .desktop files to $apps..."
178
179 cp "$target"/AltOS/*.desktop "$apps"
180
181 case "$?" in
182 0)
183     echo " done."
184     ;;
185 *)
186     echo " failed."
187     ;;
188 esac
189
190 #
191 # Install icon to desktop if desired
192 #
193
194 if [ -d $HOME/Desktop ]; then
195     default_desktop=n
196     if [ "$can_ask" = "y" ]; then
197         :
198     else
199         default_desktop=y
200     fi
201
202     answered=n
203     while [ "$answered" = "n" ]; do
204         echo -n "Install icons to desktop? [default: $default_desktop] "
205         if [ "$can_ask" = "y" ]; then
206             read do_desktop
207         else
208             echo
209             do_desktop=""
210         fi
211
212         case "$do_desktop" in
213             "")
214             do_desktop=$default_desktop
215             ;;
216         esac
217
218         case "$do_desktop" in
219         [yYnN]*)
220             answered=y
221             ;;
222         esac
223     done
224
225     echo -n "Installing desktop icons..."
226     case "$do_desktop" in
227     [yY]*)
228         for d in "$target"/AltOS/*.desktop; do
229             ln -f -s "$d" "$HOME/Desktop/"
230         done
231         ;;
232     esac
233
234     echo " done."
235 fi
236
237 finish 0
238
239 __ARCHIVE_BELOW__