d7ec9517316e23520dde9e5efc04d1330f713a1e
[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 desktop="$target"/AltOS/altos.desktop
145
146 rm -f "$desktop"
147 sed -e "s;%bindir%;$BIN;" -e "s;%icondir%;$BIN;" "$target"/AltOS/altos.desktop.in > "$desktop"
148
149 #
150 # Figure out where to install the .desktop file. If we can, write it
151 # to the public /usr/share/applications, otherwise, write it to the
152 # per-user ~/.local/share/applications
153 #
154
155 public=/usr/share/applications
156 private=$HOME/.local/share/applications
157 apps=""
158
159 if [ -d "$public" -a -w "$public" ]; then
160     apps="$public"
161 else
162     mkdir -p "$private" >/dev/null 2>&1 
163     if [ -d "$private" -a -w "$private" ]; then
164         apps="$private"
165     fi
166 fi
167         
168 case "$apps" in
169 "")
170     echo "Cannot install application icon"
171     finish 1
172     ;;
173 esac
174
175 echo -n "Installing .desktop file to $apps..."
176
177 cp "$desktop" "$apps"
178
179 case "$?" in
180 0)
181     echo " done."
182     ;;
183 *)
184     echo " failed."
185     ;;
186 esac
187
188 #
189 # Install icon to desktop if desired
190 #
191
192
193
194 finish 0
195
196 __ARCHIVE_BELOW__