epm 4.76 KB
Newer Older
Vitaly Lipatov's avatar
Vitaly Lipatov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/sh
#
# Copyright (C) 2012  Etersoft
# Copyright (C) 2012  Vitaly Lipatov <lav@etersoft.ru>
#
# This file 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.
#

21 22 23 24 25 26 27 28 29 30
PROGDIR=$(dirname $0)

load_helper()
{
    [ -r "$PROGDIR/$1" ] || fatal "Have no $PROGDIR/$1 helper file"
    . $PROGDIR/$1
}

load_helper epm-sh-functions

31
set_sudo
32

Vitaly Lipatov's avatar
Vitaly Lipatov committed
33 34 35 36 37 38 39

#############################

phelp()
{
	echo "$Descr
$Usage
40
 Commands:
41
$(get_help HELPCMD)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
42

43
 Options:
44
$(get_help HELPOPT)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
45 46 47
"
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
48 49 50 51 52 53 54
print_version()
{
        echo "EPM package manager version @VERSION@"
        echo "Copyright (c) Etersoft 2012"
        echo "This program may be freely redistributed under the terms of the GNU GPL"
}

Danil Mikhailov's avatar
Danil Mikhailov committed
55 56
Usage="Usage: epm [options] <command> [package name(s), package files]..."
Descr="epm - EPM package manager"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
57

58
verbose=
59
quiet=
60
non_interactive=
61
skip_installed=
Vitaly Lipatov's avatar
Vitaly Lipatov committed
62 63 64
epm_cmd=
pkg_files=
pkg_names=
65 66 67 68 69 70

progname="${0##*/}"
case $progname in
    epmi)
        epm_cmd=install
        ;;
Danil Mikhailov's avatar
Danil Mikhailov committed
71 72 73 74 75 76 77 78 79 80 81
    epme)
        epm_cmd=remove
        ;;
    epms)
        epm_cmd=search
        ;;
    epmqf)
        epm_cmd=query_file
        ;;
    epm)
        ;;
82 83 84 85 86
    *)
        fatal "Unknown command: $progname"
        ;;
esac

Vitaly Lipatov's avatar
Vitaly Lipatov committed
87 88
for opt in "$@" ; do
    case $opt in
89
    -h|--help|help)       # HELPOPT: this help
Vitaly Lipatov's avatar
Vitaly Lipatov committed
90 91
        phelp; exit 0
        ;;
92 93
    -v|--version)         # HELPOPT: print version
        print_version; exit 0
Vitaly Lipatov's avatar
Vitaly Lipatov committed
94
        ;;
95
    --verbose)            # HELPOPT: verbose mode
Vitaly Lipatov's avatar
Vitaly Lipatov committed
96 97
        verbose=1
        ;;
98 99 100
    --skip-installed)     # HELPOPT: skip already install during install
        skip_installed=1
        ;;
101 102 103
    --quiet)              # HELPOPT: quiet mode (do not print commands before exec)
        quiet=1
        ;;
104
    --auto)               # HELPOPT: non interactive mode
105 106
        non_interactive=1
        ;;
107
    -i|install|add)       # HELPCMD: install package(s) from remote repositories or from local file
Vitaly Lipatov's avatar
Vitaly Lipatov committed
108 109
        epm_cmd=install
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
110 111 112
    reinstall)            # HELPCMD: reinstall package(s) from remote repositories or from local file
        epm_cmd=reinstall
        ;;
113
    -e|-P|remove|delete)  # HELPCMD: remove (delete) package(s) from the database and the system
Danil Mikhailov's avatar
Danil Mikhailov committed
114 115
        epm_cmd=remove
        ;;
116
    -qi|info)             # HELPCMD: print package detail info
Vitaly Lipatov's avatar
Vitaly Lipatov committed
117 118
        epm_cmd=info
        ;;
119
    clean)                # HELPCMD: clean local package cache
Vitaly Lipatov's avatar
Vitaly Lipatov committed
120 121
        epm_cmd=clean
        ;;
122
    -qa|list|packages)    # HELPCMD: list of installed package(s)
123 124
        epm_cmd=packages
        ;;
125
    update)               # HELPCMD: update remote package repository databases
Vitaly Lipatov's avatar
Vitaly Lipatov committed
126 127
        epm_cmd=update
        ;;
128
    dist-upgrade|upgrade) # HELPCMD: performs upgrades of package software distributions
129 130
        epm_cmd=upgrade
        ;;
131
    -s|search)            # HELPCMD: search in remote package repositories
Danil Mikhailov's avatar
Danil Mikhailov committed
132 133
        epm_cmd=search
        ;;
134
    -q|installed)         # HELPCMD: check presence of package(s)
Danil Mikhailov's avatar
Danil Mikhailov committed
135
        epm_cmd=query
Danil Mikhailov's avatar
Danil Mikhailov committed
136
        ;;
137
    -qf|which)            # HELPCMD: query package(s) owning file
Danil Mikhailov's avatar
Danil Mikhailov committed
138 139
        epm_cmd=query_file
        ;;
140
    -ql|filelist)         # HELPCMD: print package file list
141
        epm_cmd=filelist
Danil Mikhailov's avatar
Danil Mikhailov committed
142
        ;;
143
    check|fix)            # HELPCMD: check local package base integrity and fix it
144 145 146 147 148 149 150
        epm_cmd=check
        ;;
    checkpkg|integrity)   # HELPCMD: check package integrity
        epm_cmd=checkpkg
        ;;
    simulate)             # HELPCMD: simulate install (check requires)
        epm_cmd=simulate
151
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
152 153
    *)
        if [ -f "$opt" ] ; then
154
            pkg_files="$pkg_files $opt"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
155
        else
156
            pkg_names="$pkg_names $opt"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
157 158 159 160 161 162 163 164
        fi
        ;;
    esac
done

pkg_files=$(strip_spaces "$pkg_files")
pkg_names=$(strip_spaces "$pkg_names")

165 166
pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")

Vitaly Lipatov's avatar
Vitaly Lipatov committed
167 168 169
echover "pkg_files=$pkg_files"
echover "pkg_names=$pkg_names"

170 171
# Fill for use: PMTYPE, DISTRNAME, DISTRVERSION, PKGFORMAT, PKGVENDOR, RPMVENDOR
DISTRVENDOR=$PROGDIR/distr_info
Vitaly Lipatov's avatar
Vitaly Lipatov committed
172 173 174
[ -n "$DISTRNAME" ] || DISTRNAME=$($DISTRVENDOR -d)
[ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v)
set_target_pkg_env
175 176
set_pm_type

177
# Run helper for command
Vitaly Lipatov's avatar
Vitaly Lipatov committed
178 179 180 181 182 183
if [ -z "$epm_cmd" ] ; then
    print_version
    echo
    fatal "Run $ epm --help for get help"
fi

184
load_helper epm-$epm_cmd
185 186
epm_$epm_cmd
# return last error code