3
# Copyright (C) 2012-2023 Etersoft
4
# Copyright (C) 2012-2023 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
PROGDIR=$(dirname "$0")
21
PROGNAME=$(basename "$0")
22
[ -n "$EPMCURDIR" ] || export EPMCURDIR="$(pwd)"
23
CMDSHELL="/usr/bin/env bash"
24
# TODO: pwd for ./epm and which for epm
25
[ "$PROGDIR" = "." ] && PROGDIR="$EPMCURDIR"
26
if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
31
# will replaced with /usr/share/eepm during install
33
# will replaced with /etc/eepm during install
34
CONFIGDIR=$PROGDIR/../etc
38
# package, single (file), pipe, git
40
[ "$SHAREDIR" = "$PROGDIR" ] && EPMMODE="single"
41
[ "$EPMVERSION" = "@""VERSION""@" ] && EPMMODE="git"
42
[ "$PROGNAME" = "" ] && EPMMODE="pipe"
44
if [ "$EPMMODE" = "git" ] ; then
45
EPMVERSION=$(head $PROGDIR/../eepm.spec | grep "^Version: " | sed -e 's|Version: ||' )
50
local shieldname="loaded$(echo "$1" | sed -e 's|-||g')"
52
eval "[ -n \"\$$shieldname\" ]" && debug "Already loaded $1" && return
54
local CMD="$SHAREDIR/$1"
55
# do not use fatal() here, it can be initial state
56
[ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
58
# shellcheck disable=SC1090
63
load_helper epm-sh-functions
66
if [ "$1" = "tool" ] ; then
73
if [ "$1" = "--inscript" ] && [ "$2" = "tool" ] ; then
85
#############################
101
$ epmi etckeeper install etckeeper package
102
$ epmqp lib print out all installed packages with 'lib' in a name
103
$ epmqf ip print out a package the command 'ip' from is
109
echo "EPM package manager version $EPMVERSION Telegram: https://t.me/useepm https://wiki.etersoft.ru/Epm"
110
echo "Running on $DISTRNAME/$DISTRVERSION ('$PMTYPE' package manager uses '$PKGFORMAT' package format)"
111
echo "Copyright (c) Etersoft 2012-2024"
112
echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
116
Usage="Usage: epm [options] <command> [package name(s), package files]..."
117
Descr="epm - EPM package manager"
135
non_interactive=$EPM_AUTO
154
eget_backend=$EGET_BACKEND
155
epm_vardir=/var/lib/eepm
156
epm_cachedir=/var/cache/eepm
157
eget_ipfs_db=$epm_vardir/eget-ipfs-db.txt
159
# load system wide config
160
[ -f $CONFIGDIR/eepm.conf ] && . $CONFIGDIR/eepm.conf
164
epmi) # HELPSHORT: alias for epm install
167
epmI) # HELPSHORT: alias for epm Install
170
epme) # HELPSHORT: alias for epm remove
173
epmcl) # HELPSHORT: alias for epm changelog
176
epmp) # HELPSHORT: alias for epm play
180
epms) # HELPSHORT: alias for epm search
184
epmsf) # HELPSHORT: alias for epm search-file (epm sf)
187
epmwd) # HELPSHORT: alias for epm wd
190
epmq) # HELPSHORT: alias for epm query
193
epmqi) # HELPSHORT: alias for epm info
196
epmqf) # HELPSHORT: alias for epm belongs
199
epmqa) # HELPSHORT: alias for epm packages
202
epmqp) # HELPSHORT: alias for epm qp (epm query package)
203
epm_cmd=query_package
205
epmql) # HELPSHORT: alias for epm filelist
208
epmrl) # HELPSHORT: alias for epm repo list
212
epmu) # HELPSHORT: alias for epm update
216
epm|upm|eepm) # HELPSHORT: other aliases for epm command
222
# fatal "Unknown command: $progname"
226
# was called with alias name
227
[ -n "$epm_cmd" ] && PROGNAME="epm"
231
# do not override command
232
[ -z "$epm_cmd" ] || return
234
# HELPCMD: PART: Base commands:
236
-i|install|add|i|it) # HELPCMD: install package(s) from remote repositories or from local file
239
-e|-P|rm|del|remove|delete|uninstall|erase|purge|e) # HELPCMD: remove (delete) package(s) from the database and the system
242
-s|search|s|find|sr) # HELPCMD: search in remote package repositories
246
-qp|qp|grep|query_package) # HELPCMD: search in the list of installed packages
247
epm_cmd=query_package
249
-qf|qf|-S|wp|which|belongs) # HELPCMD: query package(s) owning file
253
# HELPCMD: PART: Useful commands:
254
reinstall) # HELPCMD: reinstall package(s) from remote repositories or from local file
257
Install) # HELPCMD: perform update package repo info and install package(s) via install command
260
-q|q|query) # HELPCMD: check presence of package(s) and print this name (also --short is supported)
263
installed) # HELPCMD: check presence of package(s) (like -q with --quiet)
266
status) # HELPCMD: get status of package(s) (see epm status --help)
270
-sf|sf|filesearch|search-file) # HELPCMD: search in which package a file is included
273
-ql|ql|filelist|get-files) # HELPCMD: print package file list
276
-cl|cl|changelog) # HELPCMD: show changelog for package
279
-qi|qi|info|show) # HELPCMD: print package detail info
282
requires|deplist|depends|req|depends-on) # HELPCMD: print package requires
285
provides|prov) # HELPCMD: print package provides
288
whatdepends|rdepends|whatrequires|wd|required-by) # HELPCMD: print packages dependences on that
291
whatprovides) # HELPCMD: print packages provides that target
294
conflicts) # HELPCMD: print package conflicts
297
-qa|qa|ls|packages|list-installed|li) # HELPCMD: print list of all installed packages
301
list) # HELPCMD: print list of packages (see epm list --help)
305
# it is too hard operation, so just list name is very short for it
306
list-available) # HELPCMD: print list of all available packages
307
epm_cmd=list_available
310
programs) # HELPCMD: print list of installed GUI program(s) (they have .desktop files)
314
assure) # HELPCMD: <command> [package] [version]: install package if command does not exist
317
policy|resolve) # HELPCMD: print detailed information about the priority selection of package
321
# HELPCMD: PART: Repository control:
322
update|update-repo|ur) # HELPCMD: update remote package repository databases
326
addrepo|ar|--add-repo) # HELPCMD: add package repo (etersoft, autoimports, archive 2017/01/31); run with param to get list
330
repolist|sl|rl|listrepo|repo-list|list-repo|lr) # HELPCMD: print repo list
334
repofix) # HELPCMD: <mirror>: fix paths in sources lists (ALT Linux only). use repofix etersoft/yandex/basealt for rewrite URL to the specified server
338
removerepo|remove-repo|rr) # HELPCMD: remove package repo (shortcut for epm repo remove)
342
repo) # HELPCMD: manipulate with repository list (see epm repo --help)
346
check|fix|verify) # HELPCMD: check local package base integrity and fix it
350
dedup) # HELPCMD: remove unallowed duplicated pkgs (after upgrade crash)
354
full-upgrade) # HELPCMD: update all system packages and kernel
358
release-upgrade|upgrade-release|upgrade-system|release-switch) # HELPCMD: upgrade/switch whole system to the release in arg (default: next (latest) release)
359
epm_cmd=release_upgrade
362
release-downgrade|downgrade-release|downgrade-system) # HELPCMD: downgrade whole system to the release in arg (default: previuos release)
363
epm_cmd=release_downgrade
366
kernel-update|kernel-upgrade|update-kernel|upgrade-kernel) # HELPCMD: update system kernel to the last repo version
367
epm_cmd=kernel_update
370
remove-old-kernels|remove-old-kernel) # HELPCMD: remove old system kernels (exclude current or last two kernels)
371
epm_cmd=remove_old_kernels
374
stats) # HELPCMD: show statistics about repositories and installations
379
# HELPCMD: PART: Other commands:
380
clean|delete-cache|dc) # HELPCMD: clean local package cache
384
restore) # HELPCMD: install (restore) packages need for the project (f.i. by requirements.txt)
388
autoremove|package-cleanup) # HELPCMD: auto remove unneeded package(s) Supports args for ALT: [--direct [libs|python|perl|libs-devel]]
392
mark) # HELPCMD: mark package as manually or automatically installed or hold/unhold it (see epm mark --help)
396
history) # HELPCMD: show a log of actions taken by the software management (see epm history --help)
400
autoorphans|--orphans|remove-orphans) # HELPCMD: remove all packages not from the repository
404
upgrade|up|dist-upgrade) # HELPCMD: performs upgrades of package software distributions
407
Upgrade) # HELPCMD: force update package base, then run upgrade
411
downgrade) # HELPCMD: downgrade [all] packages to the repo state
414
download|fetch|fc) # HELPCMD: download package(s) file to the current dir
417
# TODO: replace with install --simulate
418
simulate) # HELPCMD: simulate install with check requires
421
audit) # HELPCMD: audits installed packages against known vulnerabilities
425
#checksystem) # HELPCMD: check system for known errors (package management related)
426
# epm_cmd=checksystem
429
site|url) # HELPCMD: open package's site in a browser (use -p for open packages.altlinux.org site)
432
ei|ik|epminstall|epm-install|selfinstall) # HELPCMD: install package(s) from Korinf (eepm by default)
435
print) # HELPCMD: print various info, run epm print help for details
439
tool) # HELPCMD: run embedded tool (see epm tool --help)
443
repack) # HELPCMD: repack rpm to local compatibility
446
pack) # HELPCMD: pack tarball or dir to a rpm package
454
prescription|recipe) # HELPCMD: run prescription (a script to achieving the goal), run without args to get list
458
play) # HELPCMD: install the application from the official site (run without args to get list)
462
-V|checkpkg|integrity) # HELPCMD: check package file integrity (checksum)
465
-h|--help|help) # HELPOPT: print this help
490
-v|--version) # HELPOPT: print version
491
[ -n "$epm_cmd" ] && return 1
492
[ -n "$short" ] && echo "$EPMVERSION" | sed -e 's|-.*||' && exit 0
496
--verbose) # HELPOPT: verbose mode
499
--debug) # HELPOPT: more debug output mode
502
--skip-installed) # HELPOPT: skip already installed packages during install
505
--skip-missed) # HELPOPT: skip not installed packages during remove
508
--show-command-only) # HELPOPT: show command only, do not any action (supports install and remove ONLY)
511
--quiet|--silent) # HELPOPT: quiet mode (do not print commands before exec)
514
--nodeps) # HELPOPT: skip dependency check (during install/simulate and so on)
517
--force) # HELPOPT: force install/remove package (f.i., override)
520
--noremove|--no-remove) # HELPOPT: exit if any packages are to be removed during upgrade
521
noremove="--no-remove"
523
--no-stdin|--inscript) # HELPOPT: don't read from stdin for epm args
526
--dry-run|--simulate|--just-print|--no-act) # HELPOPT: print only (autoremove/autoorphans/remove only)
529
--short) # HELPOPT: short output (just 'package' instead 'package-version-release')
532
--direct) # HELPOPT: direct install package file from ftp (not via hilevel repository manager)
535
--repack) # HELPOPT: repack rpm package(s) before install
538
--norepack) # HELPOPT: don't repack rpm package(s) if it is by default before install
539
norepack="--norepack"
541
--install) # HELPOPT: install packed rpm package(s)
544
--scripts) # HELPOPT: include scripts in repacked rpm package(s) (see --repack or repacking when foreign package is installed)
547
--noscripts) # HELPOPT: disable scripts in install packages
548
noscripts="--noscripts"
550
--save-only) # HELPOPT: save the package/tarball after all transformations (instead of install it)
551
save_only="--save-only"
553
--put-to-repo=*) # HELPOPT: put the package after all transformations to the repo (--put-to-repo=/path/to/repo)
554
put_to_repo="$(echo "$1" | sed -e 's|--put-to-repo=||')"
556
--download-only) # HELPOPT: download only the package/tarball (before any transformation)
557
download_only="--download-only"
559
--url) # HELPOPT: print only URL instead of download package
562
--sort) # HELPOPT: sort output, f.i. --sort=size (supported only for packages command)
563
# TODO: how to read arg?
566
-y|--auto|--assumeyes|--non-interactive|--disable-interactivity) # HELPOPT: non interactive mode
567
non_interactive="--auto"
570
--interactive) # HELPOPT: interactive mode (ask before any operation)
571
interactive="--interactive"
574
--force-yes) # HELPOPT: force yes in a danger cases (f.i., during release upgrade)
575
force_yes="--force-yes"
577
--no-check-certificate)
578
fatal "--no-check-certificate is a wget option. It is recommended never use it at all. Check the date or upgrade your system."
581
[ -n "$direct_args" ] && return 1
582
[ -n "$pkg_options" ] && pkg_options="$pkg_options $1" || pkg_options="$1"
595
# files can be with full path or have extension via .
596
if [ -f "$opt" ] && echo "$opt" | grep -q "[/\.]" ; then
597
has_space "$opt" && warning "There are space(s) in filename '$opt', it is not supported. Skipped" && continue
598
[ -n "$pkg_files" ] && pkg_files="$pkg_files $opt" || pkg_files="$opt"
599
elif [ -d "$opt" ] ; then
600
has_space "$opt" && warning "There are space(s) in directory path '$opt', it is not supported. Skipped" && continue
601
[ -n "$pkg_dirs" ] && pkg_dirs="$pkg_dirs $opt" || pkg_dirs="$opt"
602
elif is_url "$opt" ; then
603
has_space "$opt" && warning "There are space(s) in URL '$opt', it is not supported. Skipped" && continue
604
[ -n "$pkg_urls" ] && pkg_urls="$pkg_urls $opt" || pkg_urls="$opt"
606
has_space "$opt" && warning "There are space(s) in package name '$opt', it is not supported. Skipped." && continue
607
echo "$opt" | grep -q "[*]" && warning "There are forbidden symbols in package name '$opt'. Skipped." && continue
608
[ -n "$pkg_names" ] && pkg_names="$pkg_names $opt" || pkg_names="$opt"
610
[ -n "$quoted_args" ] && quoted_args="$quoted_args \"$opt\"" || quoted_args="\"$opt\""
614
# handle external EPM_OPTIONS
615
for opt in $EPM_OPTIONS ; do
620
# NOTE: can't use while read here: set vars inside
623
[ "$opt" = "--" ] && FLAGENDOPTS=1 && continue
625
if [ -z "$FLAGENDOPTS" ] ; then
626
check_command "$opt" && continue
627
check_option "$opt" && continue
630
if [ -n "$direct_args" ] ; then
631
[ -n "$quoted_args" ] && quoted_args="$quoted_args \"$opt\"" || quoted_args="\"$opt\""
633
# Note: will parse all params separately (no package names with spaces!)
634
check_filenames "$opt"
638
if [ -n "$quiet" ] ; then
644
export EPM_OPTIONS="$nodeps $force $verbose $debug $quiet $interactive $non_interactive $save_only $download_only"
646
# if input is not console and run script from file, get pkgs from stdin too
647
if [ ! -n "$inscript" ] && [ -p /dev/stdin ] && [ "$EPMMODE" != "pipe" ] ; then
648
for opt in $(withtimeout 10 cat) ; do
650
# workaround against # yes | epme
651
[ "$opt" = "y" ] && break;
652
[ "$opt" = "yes" ] && break;
657
# in common case dirs equals to names only suddenly
658
pkg_names=$(strip_spaces "$pkg_names $pkg_dirs")
660
pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
663
#echover "command: $epm_cmd"
664
#echover "pkg_files=$pkg_files"
665
#echover "pkg_names=$pkg_names"
672
epm search <name> - search package by name
673
epm install <package> - install package
674
epm full-upgrade - do full upgrade (packages, kernel) of the system
675
epm Upgrade - upgrade all installed packages (Upgrade = update + upgrade)
676
epm play [application] - install the application (run without params to get list of available apps)
677
epm qf (<command>|<path>) - print what package contains this command (file)
678
epm sf <name> - search for the name in all files of all packages
679
epm cl <package name> - print changelog for the package
683
# Just printout help if run without args
684
if [ -z "$epm_cmd" ] ; then
687
fatstr="Unrecognized command in '$*' arg(s)"
688
if [ -z "$*" ] ; then
689
fatstr="That program needs be running with some command"
692
echo "Run $(echocmd "$PROGNAME --help") to get help." >&2
693
echo "Run $(echocmd "epm print info") to get some system and distro info." >&2
697
# Use eatmydata for write specific operations
699
update|upgrade|Upgrade|install|reinstall|Install|remove|autoremove|kernel_update|release_upgrade|release_downgrade|check)
704
[ -n "$verbose$EPM_VERBOSE" ] && showcmd "$0 $*"
706
# Run helper for command with natural args
707
load_helper epm-$epm_cmd
708
eval epm_$epm_cmd $quoted_args
709
# return last error code (from subroutine)