3 # Copyright (C) 2006-2012 Bart Martens <bartm@knars.be>
4 # Copyright (C) 2013 Bdale Garbee <bdale@gag.com>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
31 [ `whoami` = "root" ] || die_hard "must be root"
35 echo " update-openrocket --install"
36 echo " update-openrocket --uninstall"
37 echo " update-openrocket --status"
38 echo "Additional options:"
44 getopt_temp=`getopt -o iusfvq --long install,uninstall,status,fast,verbose,quiet -n 'update-openrocket' -- "$@"` || show_usage
45 eval set -- "$getopt_temp" || show_usage
84 echo "Internal error!"
90 [ "$ACTION" != "none" -a $# -eq 0 ] || show_usage
91 [ "$quiet" != "yes" ] || verbose=no
93 [ "$verbose" != "yes" ] || echo "options : $getopt_temp"
95 UNPACKDIR=`mktemp -d /tmp/openrocket.XXXXXXXXXX` || die_hard "mktemp failed"
96 echo "$UNPACKDIR" | grep -q "^/tmp/openrocket\." || die_hard "paranoia"
97 cd "$UNPACKDIR" || die_hard "cd failed"
99 [ "$verbose" != "yes" ] || echo "temporary directory: $UNPACKDIR"
102 [ "$verbose" != "yes" ] || echo "cleaning up temporary directory $UNPACKDIR ..."
104 echo "$UNPACKDIR" | grep -q "^/tmp/openrocket\." || die_hard "paranoia"
108 die_hard_with_a_cleanup() {
114 trap "die_hard_with_a_cleanup interrupted" INT
116 cachedir=/var/cache/openrocket
119 wgetfast='-t 3 -T 15 '
120 wgetalways=' -nd -P . '
121 wgetprogress=' -v --progress=dot:default '
123 get_installed_version() {
125 installed=`unzip -p /usr/lib/openrocket/*.jar build.properties | grep build.version= | awk -F\= '{ print $2 }'`
129 url=`wget --no-check-certificate -qO - https://openrocket.info | grep https | grep download | awk '{ print $5 }' | grep https | sed -e 's/href=\"//g' -e 's/\"//g'`
132 get_upstream_version() {
134 upstream=`echo $url | awk -F/ '{ print $8 }' | sed -e 's/release-//g'`
140 [ "$verbose" != "yes" ] || echo "selected action = $ACTION"
142 get_installed_version
143 [ "$verbose" != "yes" ] || echo "installed version = $installed"
146 [ "$verbose" != "yes" ] || echo "upstream version = $upstream"
148 if [ "$installed" != "" -a "$upstream" != "" -a "$installed" = "$upstream" ]
151 [ "$verbose" != "yes" ] || echo "upstream version $upstream is already installed"
155 wgetoptions="$wgetquiet $wgetalways"
156 [ "$verbose" != "yes" ] || wgetoptions="$wgetalways $wgetprogress"
157 [ "$fast" != "yes" ] || wgetoptions="$wgetoptions $wgetfast"
158 [ "$verbose" != "yes" ] || echo "wgetoptions=$wgetoptions"
160 [ "$verbose" != "yes" ] || echo "downloading $url..."
163 wget $wgetoptions $url \
164 || die_hard_with_a_cleanup "wget failed to download $downloadurl"
166 targetdir=/usr/lib/openrocket
168 [ "$verbose" != "yes" ] || echo "removing old .jar files from $targetdir ..."
169 rm -f $targetdir/*.jar
171 [ "$verbose" != "yes" ] || echo "moving download to $targetdir ..."
172 mv -f OpenRocket-$upstream.jar $targetdir/OpenRocket-$upstream.jar
174 [ "$verbose" != "yes" ] || ( get_installed_version && echo "create /usr/bin/openrocket wrapper" )
176 echo "#!/bin/sh" > /usr/bin/openrocket
177 echo "exec /usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar /usr/lib/openrocket/OpenRocket-$upstream.jar \"\$@\"" >> /usr/bin/openrocket
178 chmod +x /usr/bin/openrocket
180 [ "$verbose" != "yes" ] || ( get_installed_version && echo "OpenRocket version: $installed" )
182 fi # end if installed != upstream
184 [ "$verbose" != "yes" ] || echo "end of action $ACTION"
189 [ "$verbose" != "yes" ] || echo "selected action = $ACTION"
191 [ "$verbose" != "yes" ] || echo "removing files ..."
192 rm -f /usr/lib/openrocket/*.jar
194 [ "$verbose" != "yes" ] || echo "end of action $ACTION"
199 [ "$verbose" != "yes" ] || echo "selected action = $ACTION"
201 get_installed_version
202 echo "OpenRocket version installed on this system : $installed"
204 echo "OpenRocket version available on upstream site: $upstream"
206 [ "$verbose" != "yes" ] || echo "end of action $ACTION"
221 [ "$verbose" != "yes" ] || echo "end of update-openrocket"