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

20 21
PROGDIR=$(dirname "$0")
PROGNAME=$(basename "$0")
22
# TODO: pwd for ./epm and which for epm
23
[ "$PROGDIR" = "." ] && PROGDIR=$(pwd)
24 25
if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
    PROGDIR=""
26
    PROGNAME=""
27
fi
28

29
# will replaced with /usr/share/eepm during install
30
SHAREDIR=$PROGDIR
31 32
# will replaced with /etc/eepm during install
CONFIGDIR=$PROGDIR/../etc
33 34 35

load_helper()
{
36
    local CMD="$SHAREDIR/$1"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
37 38
    # do not use fatal() here, it can be initial state
    [ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
Vitaly Lipatov's avatar
Vitaly Lipatov committed
39
    # shellcheck disable=SC1090
40
    . $CMD
41 42
}

43

44 45
load_helper epm-sh-functions

Vitaly Lipatov's avatar
Vitaly Lipatov committed
46 47
#PATH=$PATH:/sbin:/usr/sbin

48 49
set_pm_type

50
check_tty
Vitaly Lipatov's avatar
Vitaly Lipatov committed
51 52 53 54 55 56 57 58

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

phelp()
{
	echo "$Descr
$Usage

Vitaly Lipatov's avatar
Vitaly Lipatov committed
59
Options:
60
$(get_help HELPOPT)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
61 62 63 64 65 66 67 68 69 70

Short commands:
$(get_help HELPSHORT)

$(get_help HELPCMD)

Examples:
    $ epmi etckeeper      install etckeeper package
    $ epmqp lib           print out all installed packages with 'lib' in a name
    $ epmqf ip            print out a package the command 'ip' from is
Vitaly Lipatov's avatar
Vitaly Lipatov committed
71 72 73
"
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
74 75
print_version()
{
76
        echo "EPM package manager version @VERSION@  Telegram: https://t.me/useepm  https://wiki.etersoft.ru/Epm"
77
        echo "Running on $($DISTRVENDOR -e) ('$PMTYPE' package manager uses '$PKGFORMAT' package format)"
78
        echo "Copyright (c) Etersoft 2012-2023"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
79
        echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
Vitaly Lipatov's avatar
Vitaly Lipatov committed
80 81
}

82

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

86
EPMVERSION=@VERSION@
87
verbose=$EPM_VERBOSE
88
quiet=
89
nodeps=
90
noremove=
91
dryrun=
92
force=
93
repack=
94
inscript=
95
scripts=
96
noscripts=
97
short=
98
direct=
Vitaly Lipatov's avatar
Vitaly Lipatov committed
99
sort=
100
non_interactive=$EPM_AUTO
101
interactive=
102
force_yes=
103
skip_installed=
104
skip_missed=
105
show_command_only=
Vitaly Lipatov's avatar
Vitaly Lipatov committed
106 107
epm_cmd=
pkg_files=
108
pkg_dirs=
Vitaly Lipatov's avatar
Vitaly Lipatov committed
109
pkg_names=
110
pkg_urls=
111
quoted_args=
112
direct_args=
113

114
# load system wide config
115
[ -f $CONFIGDIR/eepm.conf ] && . $CONFIGDIR/eepm.conf
116 117


118
case $PROGNAME in
Vitaly Lipatov's avatar
Vitaly Lipatov committed
119
    epmi)                      # HELPSHORT: alias for epm install
120 121
        epm_cmd=install
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
122
    epmI)                      # HELPSHORT: alias for epm Install
Vitaly Lipatov's avatar
Vitaly Lipatov committed
123 124
        epm_cmd=Install
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
125
    epme)                      # HELPSHORT: alias for epm remove
Danil Mikhailov's avatar
Danil Mikhailov committed
126 127
        epm_cmd=remove
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
128
    epmcl)                     # HELPSHORT: alias for epm changelog
129 130
        epm_cmd=changelog
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
131
    epms)                      # HELPSHORT: alias for epm search
Danil Mikhailov's avatar
Danil Mikhailov committed
132 133
        epm_cmd=search
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
134
    epmsf)                     # HELPSHORT: alias for epm search file
135 136
        epm_cmd=search_file
        ;;
137 138 139
    epmwd)                     # HELPSHORT: alias for epm wd
        epm_cmd=whatdepends
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
140
    epmq)                      # HELPSHORT: alias for epm query
141 142
        epm_cmd=query
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
143
    epmqi)                     # HELPSHORT: alias for epm info
144 145
        epm_cmd=info
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
146
    epmqf)                     # HELPSHORT: alias for epm belongs
Danil Mikhailov's avatar
Danil Mikhailov committed
147 148
        epm_cmd=query_file
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
149
    epmqa)                     # HELPSHORT: alias for epm packages
150 151
        epm_cmd=packages
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
152
    epmqp)                     # HELPSHORT: alias for epm qp (epm query package)
153 154
        epm_cmd=query_package
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
155
    epmql)                     # HELPSHORT: alias for epm filelist
156 157
        epm_cmd=filelist
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
158
    epmrl)                     # HELPSHORT: alias for epm repo list
159
        epm_cmd=repolist
160
        direct_args=1
161
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
162
    epmu)                      # HELPSHORT: alias for epm update
163
        epm_cmd=update
164
        direct_args=1
165
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
166
    epm|upm|eepm)              # HELPSHORT: other aliases for epm command
Danil Mikhailov's avatar
Danil Mikhailov committed
167
        ;;
168 169
    epm.sh)
        ;;
170
    *)
171 172
        # epm by default
        # fatal "Unknown command: $progname"
173 174 175
        ;;
esac

176 177 178
# was called with alias name
[ -n "$epm_cmd" ] && PROGNAME="epm"

179 180 181 182 183
check_command()
{
    # do not override command
    [ -z "$epm_cmd" ] || return

Vitaly Lipatov's avatar
Vitaly Lipatov committed
184
# HELPCMD: PART: Base commands:
185
    case $1 in
186
    -i|install|add|i|it)         # HELPCMD: install package(s) from remote repositories or from local file
Vitaly Lipatov's avatar
Vitaly Lipatov committed
187 188
        epm_cmd=install
        ;;
189
    -e|-P|rm|del|remove|delete|uninstall|erase|purge|e)  # HELPCMD: remove (delete) package(s) from the database and the system
Danil Mikhailov's avatar
Danil Mikhailov committed
190 191
        epm_cmd=remove
        ;;
192
    -s|search|s|find|sr)                # HELPCMD: search in remote package repositories
193
        epm_cmd=search
194
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
195
    -qp|qp|query_package)     # HELPCMD: search in the list of installed packages
196 197
        epm_cmd=query_package
        ;;
198
    -qf|qf|-S|wp|which|belongs)     # HELPCMD: query package(s) owning file
199
        epm_cmd=query_file
200
        ;;
201

Vitaly Lipatov's avatar
Vitaly Lipatov committed
202
# HELPCMD: PART: Useful commands:
Vitaly Lipatov's avatar
Vitaly Lipatov committed
203
    reinstall)                # HELPCMD: reinstall package(s) from remote repositories or from local file
204
        epm_cmd=reinstall
Danil Mikhailov's avatar
Danil Mikhailov committed
205
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
206
    Install)                  # HELPCMD: perform update package repo info and install package(s) via install command
207 208
        epm_cmd=Install
        ;;
209
    -q|q|query)               # HELPCMD: check presence of package(s) and print this name (also --short is supported)
Danil Mikhailov's avatar
Danil Mikhailov committed
210
        epm_cmd=query
Danil Mikhailov's avatar
Danil Mikhailov committed
211
        ;;
212 213 214
    installed)                # HELPCMD: check presence of package(s) (like -q with --quiet)
        epm_cmd=installed
        ;;
215
    -sf|sf|filesearch|search-file)        # HELPCMD: search in which package a file is included
216 217
        epm_cmd=search_file
        ;;
218
    -ql|ql|filelist|get-files)          # HELPCMD: print package file list
219
        epm_cmd=filelist
Danil Mikhailov's avatar
Danil Mikhailov committed
220
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
221
    check|fix|verify)         # HELPCMD: check local package base integrity and fix it
222
        epm_cmd=check
223
        direct_args=1
224
        ;;
225 226
    dedup)                    # HELPCMD: remove unallowed duplicated pkgs (after upgrade crash)
        epm_cmd=dedup
227
        direct_args=1
228
        ;;
229
    -cl|cl|changelog)         # HELPCMD: show changelog for package
230 231
        epm_cmd=changelog
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
232
    -qi|qi|info|show)         # HELPCMD: print package detail info
233 234
        epm_cmd=info
        ;;
235
    requires|deplist|depends|req|depends-on)     # HELPCMD: print package requires
236 237
        epm_cmd=requires
        ;;
238
    provides|prov)            # HELPCMD: print package provides
239 240
        epm_cmd=provides
        ;;
241
    whatdepends|rdepends|whatrequires|wd|required-by)   # HELPCMD: print packages dependences on that
242 243
        epm_cmd=whatdepends
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
244
    whatprovides)             # HELPCMD: print packages provides that target
245 246
        epm_cmd=whatprovides
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
247
    conflicts)                # HELPCMD: print package conflicts
248 249
        epm_cmd=conflicts
        ;;
250
    -qa|qa|-l|list|ls|packages|list-installed|li)  # HELPCMD: print list of installed package(s)
251 252
        epm_cmd=packages
        ;;
253
    programs)                 # HELPCMD: print list of installed GUI program(s) (they have .desktop files)
254
        epm_cmd=programs
255
        direct_args=1
256
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
257
    assure)                   # HELPCMD: <command> [package] [version]: install package if command does not exist
258 259
        epm_cmd=assure
        ;;
260
    policy|resolve)           # HELPCMD: print detailed information about the priority selection of package
261 262
        epm_cmd=policy
        ;;
263

Vitaly Lipatov's avatar
Vitaly Lipatov committed
264
# HELPCMD: PART: Repository control:
265
    update|update-repo|ur)                   # HELPCMD: update remote package repository databases
266
        epm_cmd=update
267
        direct_args=1
268
        ;;
269
    addrepo|ar|--add-repo)    # HELPCMD: add package repo (etersoft, autoimports, archive 2017/12/31); run with param to get list
270
        epm_cmd=addrepo
271
        direct_args=1
272
        ;;
273
    repolist|sl|rl|listrepo|repo-list|list-repo|lr)  # HELPCMD: print repo list
Vitaly Lipatov's avatar
Vitaly Lipatov committed
274
        epm_cmd=repolist
275
        direct_args=1
Vitaly Lipatov's avatar
Vitaly Lipatov committed
276
        ;;
277
    repofix)                  # HELPCMD: <mirror>: fix paths in sources lists (ALT Linux only). use repofix etersoft/yandex/basealt for rewrite URL to the specified server
278
        epm_cmd=repofix
279
        direct_args=1
280
        ;;
281
    removerepo|remove-repo|rr)            # HELPCMD: remove package repo (shortcut for epm repo remove)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
282
        epm_cmd=removerepo
283
        direct_args=1
Vitaly Lipatov's avatar
Vitaly Lipatov committed
284
        ;;
285 286
    repo)                     # HELPCMD: manipulate with repository list (run epm repo --help to help)
        epm_cmd=repo
287
        direct_args=1
288
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
289 290
    full-upgrade)              # HELPCMD: update all system packages and kernel
        epm_cmd=full_upgrade
291
        direct_args=1
Vitaly Lipatov's avatar
Vitaly Lipatov committed
292
        ;;
293
    release-upgrade|upgrade-release|upgrade-system|release-switch)  # HELPCMD: upgrade/switch whole system to the release in arg (default: next (latest) release)
294
        epm_cmd=release_upgrade
295
        direct_args=1
296
        ;;
297 298 299 300
    release-downgrade|downgrade-release|downgrade-system)           # HELPCMD: downgrade whole system to the release in arg (default: previuos release)
        epm_cmd=release_downgrade
        direct_args=1
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
301
    kernel-update|kernel-upgrade|update-kernel|upgrade-kernel)      # HELPCMD: update system kernel to the last repo version
302
        epm_cmd=kernel_update
303
        direct_args=1
Vitaly Lipatov's avatar
Vitaly Lipatov committed
304
        ;;
305 306
    remove-old-kernels|remove-old-kernel)      # HELPCMD: remove old system kernels (exclude current or last two kernels)
        epm_cmd=remove_old_kernels
307
        direct_args=1
308
        ;;
309

Vitaly Lipatov's avatar
Vitaly Lipatov committed
310
# HELPCMD: PART: Other commands:
311
    clean|delete-cache|dc)                    # HELPCMD: clean local package cache
312
        epm_cmd=clean
313
        direct_args=1
314
        ;;
315 316 317
    restore)                  # HELPCMD: install (restore) packages need for the project (f.i. by requirements.txt)
        epm_cmd=restore
        ;;
318
    autoremove|package-cleanup)   # HELPCMD: auto remove unneeded package(s) Supports args for ALT: [--direct [libs|python|perl|libs-devel]]
319
        epm_cmd=autoremove
320
        direct_args=1
321
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
322
    mark)                     # HELPCMD: mark package as manually or automatically installed or hold/unhold it (see epm mark --help)
323 324
        epm_cmd=mark
        ;;
325 326 327
    history)                  # HELPCMD: show a log of actions taken by the software management
        epm_cmd=history
        ;;
328
    autoorphans|--orphans|remove-orphans)    # HELPCMD: remove all packages not from the repository
329 330
        epm_cmd=autoorphans
        ;;
331
    upgrade|up|dist-upgrade)     # HELPCMD: performs upgrades of package software distributions
332 333
        epm_cmd=upgrade
        ;;
334
    Upgrade)                  # HELPCMD: force update package base, then run upgrade
335
        epm_cmd=Upgrade
336
        direct_args=1
337
        ;;
338 339 340
    downgrade)                # HELPCMD: downgrade [all] packages to the repo state
        epm_cmd=downgrade
        ;;
341
    download|fetch|fc)        # HELPCMD: download package(s) file to the current dir
342 343
        epm_cmd=download
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
344
# TODO: replace with install --simulate
345
    simulate)                 # HELPCMD: simulate install with check requires
346 347
        epm_cmd=simulate
        ;;
348 349
    audit)                    # HELPCMD: audits installed packages against known vulnerabilities
        epm_cmd=audit
350
        direct_args=1
351
        ;;
352 353
    #checksystem)              # HELPCMD: check system for known errors (package management related)
    #    epm_cmd=checksystem
354
    #    direct_args=1
355
    #    ;;
356 357 358
    site|url)                 # HELPCMD: open package's site in a browser (use -p for open packages.altlinux.org site)
        epm_cmd=site
        ;;
359
    ei|ik|epminstall|epm-install|selfinstall) # HELPCMD: install package(s) from Korinf (eepm by default)
360 361
        epm_cmd=epm_install
        ;;
362 363
    print)                    # HELPCMD: print various info, run epm print help for details
        epm_cmd=print
364
        direct_args=1
365
        ;;
366 367 368 369
    tool)                     # HELPCMD: run embedded tool (f.i., epm tool eget)
        epm_cmd=tool
        direct_args=1
        ;;
370 371 372
    repack)                   # HELPCMD: repack rpm to local compatibility
        epm_cmd=repack
        ;;
373 374
    prescription|recipe)      # HELPCMD: run prescription (a script to achieving the goal), run without args to get list
        epm_cmd=prescription
375
        direct_args=1
376
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
377
    play)                     # HELPCMD: install the application from the official site (run without args to get list)
378
        epm_cmd=play
379
        direct_args=1
Vitaly Lipatov's avatar
Vitaly Lipatov committed
380
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
381
    -V|checkpkg|integrity)    # HELPCMD: check package file integrity (checksum)
382 383
        epm_cmd=checkpkg
        ;;
384 385 386 387 388
    -h|--help|help)           # HELPOPT: print this help
        help=1
        phelp
        exit 0
        ;;
389 390
    *)
        return 1
391
        ;;
392 393 394 395
    esac
    return 0
}

396 397 398
check_option()
{
    case $1 in
399
    -v|--version)         # HELPOPT: print version
400
        [ -n "$epm_cmd" ] && return 1
Vitaly Lipatov's avatar
Vitaly Lipatov committed
401
        [ -n "$short" ] && echo "$EPMVERSION" | sed -e 's|-.*||' && exit 0
Vitaly Lipatov's avatar
Vitaly Lipatov committed
402 403
        print_version
        exit 0
404 405
        ;;
    --verbose)            # HELPOPT: verbose mode
406
        verbose="--verbose"
407
        ;;
408
    --skip-installed)     # HELPOPT: skip already installed packages during install
409 410
        skip_installed=1
        ;;
411 412 413
    --skip-missed)        # HELPOPT: skip not installed packages during remove
        skip_missed=1
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
414
    --show-command-only)  # HELPOPT: show command only, do not any action (supports install and remove ONLY)
415 416
        show_command_only=1
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
417
    --quiet|--silent)     # HELPOPT: quiet mode (do not print commands before exec)
418 419
        quiet=1
        ;;
420 421 422
    --nodeps)             # HELPOPT: skip dependency check (during install/simulate and so on)
        nodeps="--nodeps"
        ;;
423 424 425
    --force)              # HELPOPT: force install/remove package (f.i., override)
        force="--force"
        ;;
426 427 428
    --noremove|--no-remove)  # HELPOPT: exit if any packages are to be removed during upgrade
        noremove="--no-remove"
        ;;
429
    --no-stdin|--inscript)  # HELPOPT: don't read from stdin for epm args
430 431
        inscript=1
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
432
    --dry-run|--simulate|--just-print|--no-act) # HELPOPT: print only (autoremove/autoorphans/remove only)
433 434
        dryrun="--dry-run"
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
435
    --short)              # HELPOPT: short output (just 'package' instead 'package-version-release')
436 437
        short="--short"
        ;;
438 439 440
    --direct)              # HELPOPT: direct install package file from ftp (not via hilevel repository manager)
        direct="--direct"
        ;;
441 442 443
    --repack)              # HELPOPT: repack rpm package(s) before install
        repack="--repack"
        ;;
444
    --scripts)             # HELPOPT: include scripts in repacked rpm package(s) (see --repack or repacking when foreign package is installed)
445
        scripts="--scripts"
446 447 448
        ;;
    --noscripts)           # HELPOPT: disable scripts in install packages
        noscripts="--noscripts"
449
        ;;
450
    --sort)               # HELPOPT: sort output, f.i. --sort=size (supported only for packages command)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
451
        # TODO: how to read arg?
452 453
        sort="$1"
        ;;
454
    --auto|--assumeyes|--non-interactive)  # HELPOPT: non interactive mode
Vitaly Lipatov's avatar
Vitaly Lipatov committed
455
        non_interactive="--auto"
456 457 458 459 460
        interactive=""
        ;;
    --interactive)  # HELPOPT: interactive mode (ask before any operation)
        interactive="--interactive"
        non_interactive=""
461
        ;;
462 463 464
    --force-yes)           # HELPOPT: force yes in a danger cases (f.i., during release upgrade)
        force_yes="--force-yes"
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
465
    *)
466
        return 1
Vitaly Lipatov's avatar
Vitaly Lipatov committed
467 468
        ;;
    esac
469 470 471
    return 0
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
472 473
# TODO: skip for commands where we don't need parse args

474 475
check_filenames()
{
476
    local opt
477
    for opt in "$@" ; do
478 479
        # files can be with full path or have extension via .
        if [ -f "$opt" ] && echo "$opt" | grep -q "[/\.]" ; then
480
            has_space "$opt" && warning "There are space(s) in filename '$opt', it is not supported. Skipped" && continue
481
            pkg_files="$pkg_files $opt"
482
        elif [ -d "$opt" ] ; then
483
            has_space "$opt" && warning "There are space(s) in directory path '$opt', it is not supported. Skipped" && continue
484
            pkg_dirs="$pkg_dirs $opt"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
485
        elif echo "$opt" | grep -q "^[fhtps]*://" ; then
486
            has_space "$opt" && warning "There are space(s) in URL '$opt', it is not supported. Skipped" && continue
487
            pkg_urls="$pkg_urls $opt"
488
        else
Vitaly Lipatov's avatar
Vitaly Lipatov committed
489
            has_space "$opt" && warning "There are space(s) in package name '$opt', it is not supported. Skipped." && continue
490
            # TODO: don't add unknown options (like -y, --unknown) to pkg_names
491 492 493 494
            pkg_names="$pkg_names $opt"
        fi
        quoted_args="$quoted_args \"$opt\""
    done
495 496
}

497 498 499 500 501
# handle external EPM_OPTIONS
for opt in $EPM_OPTIONS ; do
        check_option "$opt"
done

502
FLAGENDOPTS=
503
# NOTE: can't use while read here: set vars inside
504
for opt in "$@" ; do
505

506
    [ "$opt" = "--" ] && FLAGENDOPTS=1 && continue
507

508
    if [ -z "$FLAGENDOPTS" ] ; then
509 510
        check_command "$opt" && continue
        check_option "$opt" && continue
511
    fi
512

513 514
    if [ -n "$direct_args" ] ; then
        quoted_args="$quoted_args \"$opt\""
515 516 517
    else
        # Note: will parse all params separately (no package names with spaces!)
        check_filenames "$opt"
518
    fi
Vitaly Lipatov's avatar
Vitaly Lipatov committed
519 520
done

521 522 523 524 525
if [ -n "$quiet" ] ; then
    verbose=''
    EPM_VERBOSE=''
fi

526 527 528
# fill
export EPM_OPTIONS="$nodeps $force $non_interactive"

529
# if input is not console and run script from file, get pkgs from stdin too
530
if [ ! -n "$inscript" ] && ! inputisatty && [ -n "$PROGDIR" ] ; then
531
    for opt in $(withtimeout 10 cat) ; do
532 533 534 535
        # FIXME: do not work
        # workaround against # yes | epme
        [ "$opt" = "y" ] && break;
        [ "$opt" = "yes" ] && break;
536 537 538 539
        check_filenames $opt
    done
fi

Vitaly Lipatov's avatar
Vitaly Lipatov committed
540
pkg_files=$(strip_spaces "$pkg_files")
541
pkg_dirs=$(strip_spaces "$pkg_dirs")
542 543
# in common case dirs equals to names only suddenly
pkg_names=$(strip_spaces "$pkg_names $pkg_dirs")
544
pkg_urls=$(strip_spaces "$pkg_urls")
Vitaly Lipatov's avatar
Vitaly Lipatov committed
545

546
pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
547

548 549 550 551
# Just debug
#echover "command: $epm_cmd"
#echover "pkg_files=$pkg_files"
#echover "pkg_names=$pkg_names"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
552

Vitaly Lipatov's avatar
Vitaly Lipatov committed
553
# Just printout help if run without args
Vitaly Lipatov's avatar
Vitaly Lipatov committed
554
if [ -z "$epm_cmd" ] ; then
555 556 557
    print_version >&2
    echo >&2
    fatstr="Unrecognized command in '$*' arg(s)"
558
    [ -n "$*" ] || fatstr="That program needs be running with some command"
559 560
    echo "Run $(echocmd "$PROGNAME --help") to get help." >&2
    echo "Run $(echocmd "epm print info") to get some system and distro info." >&2
561
    fatal "$fatstr."
Vitaly Lipatov's avatar
Vitaly Lipatov committed
562 563
fi

564 565
# Use eatmydata for write specific operations
case $epm_cmd in
566
    update|upgrade|Upgrade|install|reinstall|Install|remove|autoremove|kernel_update|release_upgrade|release_downgrade|check)
567
        set_eatmydata
568
        ;;
569 570
esac

571 572
[ -n "$verbose$EPM_VERBOSE" ] && showcmd "$0 $*"

573
# Run helper for command with natural args
574
load_helper epm-$epm_cmd
575
eval epm_$epm_cmd $quoted_args
Vitaly Lipatov's avatar
Vitaly Lipatov committed
576
# return last error code (from subroutine)