#!/bin/sh # # Copyright (C) 2012 Etersoft # Copyright (C) 2012 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) # will replaced to /usr/share/eepm during install SHAREDIR=$(dirname $0) 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; } . $CMD } load_helper epm-sh-functions #PATH=$PATH:/sbin:/usr/sbin set_sudo check_tty ############################# phelp() { echo "$Descr $Usage Commands: $(get_help HELPCMD) Options: $(get_help HELPOPT) " } print_version() { echo "EPM package manager version @VERSION@" echo "Running on $($DISTRVENDOR) ('$PMTYPE' package manager uses '$PKGFORMAT' package format)" echo "Copyright (c) Etersoft 2012-2013" echo "This program may be freely redistributed under the terms of the GNU AGPLv3." } Usage="Usage: epm [options] <command> [package name(s), package files]..." Descr="epm - EPM package manager" set_pm_type verbose= quiet= nodeps= force= non_interactive= skip_installed= show_command_only= epm_cmd= pkg_files= pkg_names= progname="${0##*/}" case $progname in epmi) epm_cmd=install ;; epme) epm_cmd=remove ;; epms) epm_cmd=search ;; epmq) epm_cmd=query ;; epmqf) epm_cmd=query_file ;; epmqa) epm_cmd=packages ;; epmqp) epm_cmd=query_package ;; epm|upm|eepm) ;; *) # epm by default # fatal "Unknown command: $progname" ;; esac check_command() { # do not override command [ -z "$epm_cmd" ] || return case $1 in -i|install|add) # HELPCMD: install package(s) from remote repositories or from local file epm_cmd=install ;; -e|-P|remove|delete) # HELPCMD: remove (delete) package(s) from the database and the system epm_cmd=remove ;; -s|search) # HELPCMD: search in remote package repositories epm_cmd=search ;; -qp|query_package) # HELPCMD: search in the list of installed packages epm_cmd=query_package ;; -qf|which|belongs) # HELPCMD: query package(s) owning file epm_cmd=query_file ;; reinstall) # HELPCMD: reinstall package(s) from remote repositories or from local file epm_cmd=reinstall ;; -q|installed) # HELPCMD: check presence of package(s) epm_cmd=query ;; -sf|sf|filesearch) # HELPCMD: search in which package a file is included epm_cmd=search_file ;; -ql|filelist) # HELPCMD: print package file list epm_cmd=filelist ;; check|fix|verify) # HELPCMD: check local package base integrity and fix it epm_cmd=check ;; changelog|cl) # HELPCMD: show changelog for package epm_cmd=changelog ;; -qi|info|show) # HELPCMD: print package detail info epm_cmd=info ;; requires|deplist) # HELPCMD: print package requires epm_cmd=requires ;; -qa|list|packages|-l) # HELPCMD: list of installed package(s) epm_cmd=packages ;; update) # HELPCMD: update remote package repository databases epm_cmd=update ;; addrepo|ar) # HELPCMD: add package repo epm_cmd=addrepo ;; repolist|sl|rl|listrepo) # HELPCMD: print repo list epm_cmd=repolist ;; removerepo|rr) # HELPCMD: remove package repo epm_cmd=removerepo ;; clean) # HELPCMD: clean local package cache epm_cmd=clean ;; autoremove) # HELPCMD: auto remove unneeded package(s) epm_cmd=autoremove ;; upgrade|dist-upgrade) # HELPCMD: performs upgrades of package software distributions epm_cmd=upgrade ;; Upgrade) # HELPCMD: performs update && upgrade command epm_cmd=Upgrade ;; simulate) # HELPCMD: simulate install (it does check requires, minimally) epm_cmd=simulate ;; checkpkg|integrity) # HELPCMD: check package integrity epm_cmd=checkpkg ;; *) return 1 ;; esac return 0 } check_option() { case $1 in -h|--help|help) # HELPOPT: this help phelp exit 0 ;; -v|--version) # HELPOPT: print version print_version exit 0 ;; --verbose) # HELPOPT: verbose mode verbose=1 ;; --skip-installed) # HELPOPT: skip already install during install skip_installed=1 ;; --show-command-only) # HELPOPT: show command only, do not any action (supports install and remove ONLY) show_command_only=1 ;; --quiet) # HELPOPT: quiet mode (do not print commands before exec) quiet=1 ;; --nodeps) # HELPOPT: skip dependency check (during install/simulate and so on) nodeps="--nodeps" ;; --force) # HELPOPT: force install/remove package (f.i., override) force="--force" ;; --auto) # HELPOPT: non interactive mode non_interactive=1 ;; *) return 1 ;; esac return 0 } for opt in "$@" ; do check_command $opt && continue check_option $opt && continue if [ -f "$opt" ] ; then pkg_files="$pkg_files $opt" else pkg_names="$pkg_names $opt" fi done pkg_files=$(strip_spaces "$pkg_files") pkg_names=$(strip_spaces "$pkg_names") 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 print_version echo fatal "Run $ epm --help for get help" fi # Run helper for command load_helper epm-$epm_cmd epm_$epm_cmd # return last error code (from subroutine)