epm-check_updated_repo 1.99 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2014, 2015  Etersoft
# Copyright (C) 2014, 2015  Vitaly Lipatov <lav@etersoft.ru>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

20
__is_repo_info_downloaded()
21 22 23
{
    case $PMTYPE in
        apt-*)
24
            if [ -r /var/cache/apt ] ; then
25
                $SUDO test -r /var/cache/apt/pkgcache.bin || return
26 27 28 29 30 31 32 33 34 35 36
            fi
            ;;
        *)
            ;;
    esac
    return 0
}

__is_repo_info_uptodate()
{
    case $PMTYPE in
37 38
        apt-rpm)
            # apt-deb do not update lock file date
Vitaly Lipatov's avatar
Vitaly Lipatov committed
39
            if $SUDO test -r /var/lib/apt/lists ; then
40
                local LOCKFILE=/var/lib/apt/lists/lock
41
                $SUDO test -r $LOCKFILE || return
42
                # if repo older than 1 day, return false
43
                # find print string if file is obsoleted
44
                test -z "$($SUDO find $LOCKFILE -mtime +1)" || return
45
            fi
46 47 48 49 50 51 52 53 54
            ;;
        *)
            ;;
    esac
    return 0
}

update_repo_if_needed()
{
55 56 57 58 59 60
    # check if we need skip update checking
    if [ "$1" = "soft" ] && [ -n "$SUDO" ] ; then
        # if sudo requires a password, skip autoupdate
        sudo -n true 2>/dev/null || { info "sudo requires a password, skip repo status checking" ; return 0 ; }
    fi

61
    cd /
62
    if ! __is_repo_info_downloaded || ! __is_repo_info_uptodate ; then
63
        load_helper epm-update
64
        pkg_filenames= epm_update
65
    fi
66
    cd - >/dev/null
67 68

}