LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File fetch-2gis.sh.in of Package 2gis (Project home:XRevan86:non-free)

#!/bin/sh

NAME=__NAME__
VERSION=__VERSION__
ALT_VER=__ALT_VER__
ARCH=__ARCH__

POST_MESSAGE="/var/adm/update-messages/__NAME-__VERSION__-__RELEASE__-1"

SERVER="http://deb.2gis.ru/pool/non-free/2/$NAME"
FILE="${NAME}_${ALT_VER}_${ARCH}.deb"

CURL_OPTIONS="-L -s --speed-limit 3500 --speed-time 15"

if ( ! which id > /dev/null ) || ( ! which tar > /dev/null ); then
    echo "Running in non-chrooted (install into directory) mode... Exit safely."
    exit 0
fi

if [ "$(id -u)" != 0 ]; then
    echo "error: You must be root to use this application!"
    exit 1
fi

. "/etc/sysconfig/proxy"

if [ "$PROXY_ENABLED" != no ]; then
    if [ -n "$HTTP_PROXY" ]; then
        export http_proxy="$HTTP_PROXY"
    fi
fi

if [ -z $http_proxy ]; then
    echo
    echo "note: No proxy is used. Please set the environment variable \"http_proxy\""
    echo "note: to your favourite proxy if you want to use a proxy for the download."
    echo "note:"
    echo "note:   sh: export http_proxy=\"http://proxy.example.org:3128/\""
    echo "note:   csh: setenv http_proxy \"http://proxy.example.org:3128/\""
fi

tmpdir="$(mktemp -d "/tmp/$(basename $0).XXXXXX")"
trap "rm -rf $tmpdir" EXIT
if [ $? -ne 0 ]; then
    echo "$0: Can't create temp dir, exiting..."
    exit 4
fi

cd "$tmpdir"

for server in $useserver $SERVER; do
    archive="$server/$FILE"
    rm -f "$FILE"
    echo "$FILE ($archive):"
    echo -n "  Fetching   ... "
    curl $CURL_OPTIONS -o "$FILE" "$archive"
    if [ $? -ne 0 ]; then
        rm -f "$FILE"
        echo "failed ... deleted!"
        success=false
        continue
    fi
    success=true
    echo "done"
    break
done

if [ "$success" != false ]; then
    # Extract.
    ar -x "$FILE"
    tar -xf data.tar.xz
    # Install into system root.
    install -Dpm 0755 ".%{_bindir}/$NAME" "%{_bindir}/$NAME"
    cp -aT ".%{_libexecdir}/2GIS/v4" "%{_libdir}/$NAME/v4"
    rm -f "%{_libexecdir}/2GIS"
    for lib in libpthread.so.0 libm.so.6 libdl.so.2; do
        rm -f "%{_libdir}/2gis/v4/lib/$lib"
    done
    ln -s "%{_libdir}/$NAME" "%{_libexecdir}/2GIS"
    cp -aT ".%{_datadir}/2GIS" "%{_datadir}/2GIS"
    install -Dpm 0644 ".%{_datadir}/applications/$NAME.desktop" "%{_datadir}/applications/$NAME.desktop"

    install -Dpm 0644 ".%{_datadir}/icons/hicolor/48x48/apps/$NAME.png" \
      "%{_datadir}/icons/hicolor/48x48/apps/$NAME.png"
    install -Dpm 0644 ".%{_datadir}/icons/hicolor/scalable/apps/$NAME.svg" \
      "%{_datadir}/icons/hicolor/scalable/apps/$NAME.svg"

    install -Dpm 0644 ".%{_datadir}/man/man1/$NAME.1.gz" "%{_datadir}/man/man1/$NAME.1.gz"

    install -Dpm 0644 ".%{_datadir}/doc/$NAME/copyright" "%{_datadir}/doc/packages/$NAME/COPYING"
    gzip -d ".%{_datadir}/doc/$NAME/changelog.Debian.gz"
    install -Dpm 0644 ".%{_datadir}/doc/$NAME/changelog.Debian" "%{_datadir}/doc/packages/$NAME/ChangeLog"

    chown root:doublegis "%{_bindir}/$NAME"
    chmod g+s "%{_bindir}/$NAME"

    gtk-update-icon-cache --quiet --force "%{_datadir}/icons/hicolor/"

    echo "*** 2GIS files installed. ***" | tee $POST_MESSAGE
else
    echo "*** No 2GIS files installed. ***" | tee $POST_MESSAGE
fi

if [ -f "%{_datadir}/doc/packages/$NAME/COPYING" ]; then
    cat "%{_datadir}/doc/packages/$NAME/COPYING" | tee $POST_MESSAGE
fi