epm 18.2 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
[ "$PROGDIR" = "." ] && PROGDIR=$(pwd)
23 24
if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
    PROGDIR=""
25
    PROGNAME=""
26
fi
27

28
# will replaced to /usr/share/eepm during install
29
SHAREDIR=$PROGDIR
Vitaly Lipatov's avatar
Vitaly Lipatov committed
30
CONFIGDIR=$PROGDIR/..
31 32 33

load_helper()
{
34
    local CMD="$SHAREDIR/$1"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
35 36
    # 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
37
    # shellcheck disable=SC1090
38
    . $CMD
39 40
}

41

42 43
load_helper epm-sh-functions

Vitaly Lipatov's avatar
Vitaly Lipatov committed
44 45
#PATH=$PATH:/sbin:/usr/sbin

46 47
set_pm_type

48
check_tty
Vitaly Lipatov's avatar
Vitaly Lipatov committed
49 50 51 52 53 54 55 56

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

phelp()
{
	echo "$Descr
$Usage

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

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
69 70 71
"
}

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

80

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

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

111 112 113 114
# load system wide config
[ -f /etc/eepm/eepm.conf ] && . /etc/eepm/eepm.conf


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

173 174 175
# was called with alias name
[ -n "$epm_cmd" ] && PROGNAME="epm"

176 177 178 179 180
check_command()
{
    # do not override command
    [ -z "$epm_cmd" ] || return

Vitaly Lipatov's avatar
Vitaly Lipatov committed
181
# HELPCMD: PART: Base commands:
182
    case $1 in
Vitaly Lipatov's avatar
Vitaly Lipatov committed
183
    -i|install|add|i)         # HELPCMD: install package(s) from remote repositories or from local file
Vitaly Lipatov's avatar
Vitaly Lipatov committed
184 185
        epm_cmd=install
        ;;
186
    -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
187 188
        epm_cmd=remove
        ;;
189
    -s|search|s)                # HELPCMD: search in remote package repositories
190
        epm_cmd=search
191
        ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
192
    -qp|qp|query_package)     # HELPCMD: search in the list of installed packages
193 194
        epm_cmd=query_package
        ;;
195
    -qf|qf|-S|wp|which|belongs)     # HELPCMD: query package(s) owning file
196
        epm_cmd=query_file
197
        ;;
198

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

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

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

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

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

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

485 486 487 488 489
# handle external EPM_OPTIONS
for opt in $EPM_OPTIONS ; do
        check_option "$opt"
done

490
FLAGENDOPTS=
491
# NOTE: can't use while read here: set vars inside
492
for opt in "$@" ; do
493

494
    [ "$opt" = "--" ] && FLAGENDOPTS=1 && continue
495

496
    if [ -z "$FLAGENDOPTS" ] ; then
497 498
        check_command "$opt" && continue
        check_option "$opt" && continue
499
    fi
500

501 502
    if [ -n "$direct_args" ] ; then
        quoted_args="$quoted_args \"$opt\""
503 504 505
    else
        # Note: will parse all params separately (no package names with spaces!)
        check_filenames "$opt"
506
    fi
Vitaly Lipatov's avatar
Vitaly Lipatov committed
507 508
done

509 510 511
# fill
export EPM_OPTIONS="$nodeps $force $non_interactive"

512
# if input is not console and run script from file, get pkgs from stdin too
513
if [ ! -n "$inscript" ] && ! inputisatty && [ -n "$PROGDIR" ] ; then
514
    for opt in $(withtimeout 10 cat) ; do
515 516 517 518
        # FIXME: do not work
        # workaround against # yes | epme
        [ "$opt" = "y" ] && break;
        [ "$opt" = "yes" ] && break;
519 520 521 522
        check_filenames $opt
    done
fi

Vitaly Lipatov's avatar
Vitaly Lipatov committed
523
pkg_files=$(strip_spaces "$pkg_files")
524
pkg_dirs=$(strip_spaces "$pkg_dirs")
525 526
# in common case dirs equals to names only suddenly
pkg_names=$(strip_spaces "$pkg_names $pkg_dirs")
527
pkg_urls=$(strip_spaces "$pkg_urls")
Vitaly Lipatov's avatar
Vitaly Lipatov committed
528

529
pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
530

531 532 533 534
# Just debug
#echover "command: $epm_cmd"
#echover "pkg_files=$pkg_files"
#echover "pkg_names=$pkg_names"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
535

Vitaly Lipatov's avatar
Vitaly Lipatov committed
536
# Just printout help if run without args
Vitaly Lipatov's avatar
Vitaly Lipatov committed
537 538 539
if [ -z "$epm_cmd" ] ; then
    print_version
    echo
540
    fatstr="Unknown command in $* arg(s)"
541
    [ -n "$*" ] || fatstr="That program needs be running with some command"
542 543 544
    echo "Run $ $PROGNAME --help  to get help." >&2
    echo "Run $ epm print info  to get some system and distro info." >&2
    fatal "$fatstr."
Vitaly Lipatov's avatar
Vitaly Lipatov committed
545 546
fi

547 548
# Use eatmydata for write specific operations
case $epm_cmd in
549
    update|upgrade|Upgrade|install|reinstall|Install|remove|autoremove|kernel_update|release_upgrade|release_downgrade|check)
550
        set_eatmydata
551
        ;;
552 553
esac

554 555
[ -n "$verbose$EPM_VERBOSE" ] && showcmd "$0 $*"

556
# Run helper for command with natural args
557
load_helper epm-$epm_cmd
558
eval epm_$epm_cmd $quoted_args
Vitaly Lipatov's avatar
Vitaly Lipatov committed
559
# return last error code (from subroutine)