yum 10.6 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 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#!/bin/sh
#
# Copyright (C) 2012-2021  Etersoft
# Copyright (C) 2012-2021  Vitaly Lipatov <lav@etersoft.ru>
#
# 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/>.
#

PROGDIR=$(dirname "$0")
PROGNAME=$(basename "$0")
[ "$PROGDIR" = "." ] && PROGDIR=$(pwd)
if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
    PROGDIR=""
    PROGNAME=""
fi

# will replaced to /usr/share/eepm during install
SHAREDIR=$PROGDIR
CONFIGDIR=$PROGDIR/..

load_helper()
{
    local CMD="$SHAREDIR/$1"
    # do not use fatal() here, it can be initial state
    [ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
    # shellcheck disable=SC1090
    . $CMD
}


load_helper epm-sh-functions

#PATH=$PATH:/sbin:/usr/sbin

set_pm_type

48
#set_sudo
Vitaly Lipatov's avatar
Vitaly Lipatov committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

check_tty

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

phelp()
{
	echo "
Usage: yum [options] COMMAND

List of Commands:

$(get_help HELPCMD | sed -e 's@|@,@g')

Options:
$(get_help HELPOPT | sed -e 's@|@,@g')

"
}

print_version()
{
        echo "EPM package manager version @VERSION@  https://wiki.etersoft.ru/Epm"
        echo "Running on $($DISTRVENDOR -e) ('$PMTYPE' package manager uses '$PKGFORMAT' package format)"
        echo "Copyright (c) Etersoft 2012-2021"
        echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
}


EPMVERSION=@VERSION@
verbose=
quiet=
nodeps=
noremove=
dryrun=
force=
repack=
inscript=
scripts=
noscripts=
short=
direct=
sort=
non_interactive=
skip_installed=
skip_missed=
show_command_only=
epm_cmd=
pkg_files=
pkg_dirs=
pkg_names=
pkg_urls=
quoted_args=

# load system wide config
[ -f /etc/eepm/eepm.conf ] && . /etc/eepm/eepm.conf


check_command()
{
    # do not override command
    [ -z "$epm_cmd" ] || return

112 113 114 115
# Bellow original commands to be mapped into eepm are taken from the following places:
# - yum help
# - source code of dnf 4.x, dnf/cli/commands/*.py, "aliases = (<...>)" (yum-dnf will understand them)
# - default upstream configs of aliases in dnf 4.x (output of `dnf alias`)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
# HELPCMD:
    case $1 in
    check)                    # HELPCMD: Check for problems in the rpmdb
        epm_cmd=check
        ;;
    check-update)             # HELPCMD: Check for available package updates
        epm_cmd=upgrade
        ;;
    clean)                    # HELPCMD: Remove cached data
        epm_cmd=clean
        ;;
    deplist)                  # HELPCMD: List a package's dependencies
        # TODO: hilevel in any case
        epm_cmd=requires
        ;;
131 132 133 134
    distribution-synchronization | distro-sync | distrosync | dsync | dup) # HELPCMD: Synchronize installed packages to the latest available versions
        # TODO: distro-sync can either upgrade or downgrade packages,
        # apt-get with pinned priorities of repositiories would be a replacement
        fatal "Is not supported"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
135
        ;;
136
    downgrade | dg)           # HELPCMD: downgrade a package
Vitaly Lipatov's avatar
Vitaly Lipatov committed
137 138
        epm_cmd=downgrade
        ;;
139
    remove | rm | erase)      # HELPCMD: Remove a package or packages from your system
Vitaly Lipatov's avatar
Vitaly Lipatov committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
        epm_cmd=remove
        ;;
    groupinfo)                # HELPCMD: Display details about a package group
        fatal "Is not supported"
        ;;
    groupinstall)             # HELPCMD: Install the packages in a group on your system
        fatal "Is not supported"
        ;;
    grouplist)                # HELPCMD: List available package groups
        fatal "Is not supported"
        ;;
    groupremove)              # HELPCMD: Remove the packages in a group from your system
        fatal "Is not supported"
        ;;
    help)                     # HELPCMD: Display a helpful usage message
        help=1
        phelp
        exit 0
        ;;
159
    history | hist)           # HELPCMD: Display, or use, the transaction history
Vitaly Lipatov's avatar
Vitaly Lipatov committed
160 161 162 163 164
        fatal "Is not supported"
        ;;
    info)                     # HELPCMD: Display details about a package or group of packages
        epm_cmd=info
        ;;
165
    install | in | localinstall) # HELPCMD: Install a package or packages on your system
Vitaly Lipatov's avatar
Vitaly Lipatov committed
166 167 168 169 170 171 172 173 174
        epm_cmd=install
        ;;
    list)                     # HELPCMD: List a package or groups of packages
        # TODO: support base options (see list -h), all available packages by default
        epm_cmd=packages
        ;;
    load-transaction)         # HELPCMD: load a saved transaction from filename
        fatal "Is not supported"
        ;;
175 176
    makecache | refresh)      # HELPCMD: Generate or update the metadata cache
        epm_cmd=update
Vitaly Lipatov's avatar
Vitaly Lipatov committed
177 178 179 180 181
        ;;
    provides)                 # HELPCMD: Find what package provides the given value
        # TODO: hilevel in any case
        epm_cmd=provides
        ;;
182
    reinstall | rei)          # HELPCMD: reinstall a package
Vitaly Lipatov's avatar
Vitaly Lipatov committed
183 184
        epm_cmd=reinstall
        ;;
185
    repolist | repoinfo)      # HELPCMD: Display the configured software repositories
Vitaly Lipatov's avatar
Vitaly Lipatov committed
186 187 188 189 190
        epm_cmd=repolist
        ;;
    resolvedep)               # HELPCMD: Determine which package provides the given dependency
        epm_cmd=whatprovides
        ;;
191
    search | se)              # HELPCMD: Search package details for the given string
Vitaly Lipatov's avatar
Vitaly Lipatov committed
192 193
        epm_cmd=search
        ;;
194
    shell | sh)               # HELPCMD: Run an interactive yum shell
Vitaly Lipatov's avatar
Vitaly Lipatov committed
195 196 197 198 199 200 201 202 203 204
        # TODO: not full compatible
        apt-shell
        ;;
    update)                   # HELPCMD: Update a package or packages on your system
        epm_cmd=install
        ;;
    upgrade)                  # HELPCMD: Update packages taking obsoletes into account
        epm_cmd=upgrade
        ;;
    version)                  # HELPCMD: Display a version for the machine and/or available repos.
205 206 207
        echo "Installed: $DISTRVERSION/$DISTRARCH"
        echo "version"
        exit 0
Vitaly Lipatov's avatar
Vitaly Lipatov committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
        ;;
    *)
        return 1
        ;;
    esac
    return 0
}

check_option()
{
    case $1 in
    -h|--help)            # HELPOPT: show this help message and exit
        help=1
        phelp
        exit 0
       ;;
    -t|--tolerant)        # HELPOPT: be tolerant of errors
        fatal "Is not supported"
        ;;
    -C|--cacheonly)       # HELPOPT: run entirely from system cache, don't update cache
        fatal "Is not supported"
        ;;
    --showduplicates)     # HELPOPT: show duplicates, in repos, in list/search commands
        fatal "Is not supported"
        ;;
    --quiet)              # HELPOPT: quiet operation
        quiet=1
        ;;
    -v|--verbose)         # HELPOPT: verbose operation
        verbose="--verbose"
        ;;
    -y|--assumeyes)       # HELPOPT: answer yes for all questions
        non_interactive="--auto"
        ;;
    --assumeno)           # HELPOPT: answer no for all questions
        fatal "Is not supported"
        ;;
    --version)            # HELPOPT: show Yum version and exit
        print_version
        exit 0
        ;;
#    --installroot=[path]  set install root
#  --enablerepo=[repo]   enable one or more repositories (wildcards allowed)
#  --disablerepo=[repo]  disable one or more repositories (wildcards allowed)
#  -x [package], --exclude=[package]
#                        exclude package(s) by name or glob
#  --disableexcludes=[repo]
#                        disable exclude from main, for a repo or for
#                        everything
#  --obsoletes           enable obsoletes processing during updates
#  --noplugins           disable Yum plugins
#  --nogpgcheck          disable gpg signature checking
#  --skip-broken         skip packages with depsolving problems
#  --releasever=RELEASEVER
#                        set value of $releasever in yum config and repo files
#  --downloadonly        don't update, just download
#  --downloaddir=DLDIR   specifies an alternate directory to store packages
#  --setopt=SETOPTS      set arbitrary config and repo options
    *)
        return 1
        ;;
    esac
    return 0
}

# TODO: skip for commands where we don't need parse args

check_filenames()
{
    local opt
    for opt in "$@" ; do
        # files can be with full path or have extension via .
        if [ -f "$opt" ] && echo "$opt" | grep -q "[/\.]" ; then
            has_space "$opt" && warning "There are space(s) in filename '$opt', it is not supported. Skipped" && continue
            pkg_files="$pkg_files $opt"
        elif [ -d "$opt" ] ; then
            has_space "$opt" && warning "There are space(s) in directory path '$opt', it is not supported. Skipped" && continue
            pkg_dirs="$pkg_dirs $opt"
        elif echo "$opt" | grep -q "^[fhtps]*://" ; then
            has_space "$opt" && warning "There are space(s) in URL '$opt', it is not supported. Skipped" && continue
            pkg_urls="$pkg_urls $opt"
        else
            has_space "$opt" && warning "There are space(s) in package name '$opt', it is not supported. Skipped." && continue
            pkg_names="$pkg_names $opt"
        fi
        quoted_args="$quoted_args \"$opt\""
    done
}

FLAGENDOPTS=
for opt in "$@" ; do
    [ "$opt" = "--" ] && FLAGENDOPTS=1 && continue
    if [ -z "$FLAGENDOPTS" ] ; then
        check_command "$opt" && continue
        check_option "$opt" && continue
    fi
    # Note: will parse all params separately (no package names with spaces!)
    check_filenames "$opt"
done

pkg_files=$(strip_spaces "$pkg_files")
pkg_dirs=$(strip_spaces "$pkg_dirs")
# in common case dirs equals to names only suddenly
pkg_names=$(strip_spaces "$pkg_names $pkg_dirs")
pkg_urls=$(strip_spaces "$pkg_urls")

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

# Just debug
#echover "command: $epm_cmd"
#echover "pkg_files=$pkg_files"
#echover "pkg_names=$pkg_names"

# Just printout help if run without args
if [ -z "$epm_cmd" ] ; then
    phelp
    echo
    fatstr="No such command: $*. Please use /usr/bin/yum --help"
    [ -n "$*" ] || fatstr="You need to give some command"
327 328 329 330
    # TODO: https://bugzilla.altlinux.org/show_bug.cgi?id=39093
    # Почему-то только в этом файле/пакете использование info вызывает зависимость на пакет info
    #info "$fatstr."
    echo "$fatstr."
Vitaly Lipatov's avatar
Vitaly Lipatov committed
331 332 333 334 335 336 337 338 339
    exit 1
fi

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

# Run helper for command with natural args
load_helper epm-$epm_cmd
eval epm_$epm_cmd $quoted_args
# return last error code (from subroutine)