home *** CD-ROM | disk | FTP | other *** search
- #!/bin/bash
- #
- # Copyright 2006-2007 Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- errorout () { echo "$0: $@" >&2; cd /tmp; rm -rf GoogleEarthInstall; exit 2; }
- INSTALLDIR=/opt
- INSTALLATION=google-earth
- [ "$(id -u)" = "0" ] || errorout must have superuser privileges
- touch /usr/share/foobarbazquux || errorout /usr is read-only
- rm -f /usr/share/foobarbazquux
- touch $INSTALLDIR/foobarbazquux || errorout $INSTALLDIR is read-only
- $INSTALLDIR/$INSTALLATION/uninstall.sh 2>/dev/null || true
- if ! dd if=/dev/null of=$INSTALLDIR/foobarbazquux seek=1 bs=64M; then
- rm -f $INSTALLDIR/foobarbazquux
- errorout not enough room in $INSTALLDIR
- fi
- rm -f $INSTALLDIR/foobarbazquux
- cd /tmp
- if ! dd if=/dev/null of=foobarbazquux seek=1 bs=128M; then
- rm -f foobarbazquux
- errorout not enough room in /tmp
- fi
- rm -f foobarbazquux
- mkdir GoogleEarthInstall
- cd GoogleEarthInstall
- sIFS="$IFS"
- IFS=:
- set $LANGUAGE:en
- IFS="$sIFS"
- unset sIFS
- for PICKLANG; do
- EULALANG=$(echo $PICKLANG | cut -d . -f 1)
- echo " ar cs de en es fr it ja ko nl pl pt ru zh_TW " | grep -q " $EULALANG " && break
- EULALANG=$(echo $PICKLANG | cut -d _ -f 1)
- echo " ar cs de en es fr it ja ko nl pl pt ru zh_TW " | grep -q " $EULALANG " && break
- done
- EULAFILE=EULA-GoogleEarth-${EULALANG}.txt
- wget -O- http://earth.google.com/intl/$(echo $EULALANG | tr _ -)/download-earth.html | perl -e 'undef $/; binmode(STDIN, ":utf8"); binmode(STDOUT, ":locale"); $_ = <STDIN>; s/.*<textarea[^>]*>(.*?)<\/textarea>.*/$1/is; print $_' > $EULAFILE
- cat >GoogleEarth.template1 <<EOF
- Template: shared/GoogleEarth-EULA
- Type: boolean
- Default: false
- Description: Do you agree to this license?
- EOF
- grep -v '^$' $EULAFILE | sed 's/^[^[:space:]].*/&\n/g' | sed -e 's/^\s*$/./g' -e 's/^/ /g' >>GoogleEarth.template1
- echo >>GoogleEarth.template1
- debconf-loadtemplate $INSTALLATION GoogleEarth.template1 || errorout failed to load debconf template1
- export -f errorout
- cat >GoogleEarth.debconf.sh <<EOF
- #!/bin/bash
- . /usr/share/debconf/confmodule || errorout unable to use debconf
- GoogleEarth_cleanup () {
- db_unregister shared/GoogleEarth-EULA
- db_purge
- }
- errorin () { GoogleEarth_cleanup; errorout "\$@"; }
- STATE=1
- while true; do
- case "\$STATE" in
- 0) # ensure going back from license presentment is harmless
- STATE=1
- continue
- ;;
- 1) # present license
- db_fset shared/GoogleEarth-EULA seen false
- db_input critical shared/GoogleEarth-EULA || errorin EULA could not be displayed
- ;;
- 2) # determine users' choice
- db_get shared/GoogleEarth-EULA || errorin could not get EULA response
- if [ "\$RET" != "true" ]; then
- cd /tmp
- rm -rf GoogleEarthInstall
- GoogleEarth_cleanup
- exit 1
- fi
- break
- ;;
- *) # unknown state
- errorin license state unknown: \$STATE
- ;;
- esac
- if db_go; then
- STATE=\$((\$STATE + 1))
- else
- STATE=\$((\$STATE - 1))
- fi
- done
- GoogleEarth_cleanup
- EOF
- chmod a+x GoogleEarth.debconf.sh
- ./GoogleEarth.debconf.sh || exit $?
- wget -N http://dl.google.com/earth/client/current/GoogleEarthLinux.bin || errorout could not download Google Earth
- sh GoogleEarthLinux.bin --noexec --keep --nox11 --nochown --target GoogleEarthInstaller
- rm -f GoogleEarthLinux.bin
- cd GoogleEarthInstaller
- cat >GoogleEarth.template2 <<EOF
- Template: shared/GoogleEarth-README
- Type: note
- Description: GoogleEarth README
- EOF
- grep -v '^$' README.linux | sed -re 's/^[[:blank:]]?[^[:blank:]]+.*$/ &/g' -e 's/^\s*$/./g' -e 's/^/ /g' >>GoogleEarth.template2
- echo >>GoogleEarth.template2
- debconf-loadtemplate $INSTALLATION GoogleEarth.template2 || errorout failed to load debconf template2
- cat >GoogleEarth.debconf.sh <<EOF
- #!/bin/bash
- . /usr/share/debconf/confmodule || errorout unable to use debconf
- GoogleEarth_cleanup () {
- db_unregister shared/GoogleEarth-EULA
- db_unregister shared/GoogleEarth-README
- db_purge
- }
- errorin () { GoogleEarth_cleanup; errorout "\$@"; }
- STATE=1
- while true; do
- case "\$STATE" in
- 0) # ensure going back is harmless
- STATE=1
- continue
- ;;
- 1) # present README
- db_fset shared/GoogleEarth-README seen false
- db_input low shared/GoogleEarth-README
- ;;
- 2) # after README
- break
- ;;
- *) # unknown state
- errorin license state unknown: \$STATE
- ;;
- esac
- if db_go; then
- STATE=\$((\$STATE + 1))
- else
- STATE=\$((\$STATE - 1))
- fi
- done
- GoogleEarth_cleanup
- EOF
- chmod a+x GoogleEarth.debconf.sh
- ./GoogleEarth.debconf.sh || exit $?
- mkdir $INSTALLATION
- cp -a ../$EULAFILE bin/googleearth googleearth-icon.png googleearth.xpm linux README* $INSTALLATION
- cd $INSTALLATION
- tar xf ../googleearth-linux-x86.tar
- tar xf ../googleearth-data.tar
- cd ..
- mv $INSTALLATION $INSTALLDIR
- cat >uninstall.sh <<EOF
- #!/bin/bash
- export SETUP_INSTALLPATH=$INSTALLDIR/$INSTALLATION
- export XDG_DATA_DIRS=/usr/share
- EOF
- . uninstall.sh
- chmod a+x uninstall.sh
- mv uninstall.sh $SETUP_INSTALLPATH
- grep -v 'xdg-desktop-icon[[:blank:]]*install' postinstall.sh > postinstall1.sh
- cat preuninstall.sh >> $SETUP_INSTALLPATH/uninstall.sh
- echo 'rm -rf $SETUP_INSTALLPATH' >> $SETUP_INSTALLPATH/uninstall.sh
- sh postinstall1.sh
- cd /tmp
- rm -rf GoogleEarthInstall
-