Commit db3edf22 authored by Vitaly Lipatov's avatar Vitaly Lipatov

commit packed 3.50.0

parent 714d5b32
......@@ -33,9 +33,15 @@ SHAREDIR=$PROGDIR
# will replaced with /etc/eepm during install
CONFIGDIR=$PROGDIR/../etc
EPMVERSION="3.42.0"
EPMVERSION="3.50.0"
if [ "$EPMVERSION" = "@""VERSION""@" ] ; then
# package, single (file), pipe, git
EPMMODE="package"
[ "$SHAREDIR" = "$PROGDIR" ] && EPMMODE="single"
[ "$EPMVERSION" = "@""VERSION""@" ] && EPMMODE="git"
[ "$PROGNAME" = "" ] && EPMMODE="pipe"
if [ "$EPMMODE" = "git" ] ; then
EPMVERSION=$(head $PROGDIR/../eepm.spec | grep "^Version: " | sed -e 's|Version: ||' )
fi
......@@ -511,7 +517,7 @@ disabled_eget()
local EGET
# use internal eget only if exists
if [ -s $SHAREDIR/tools_eget ] ; then
$SHAREDIR/tools_eget "$@"
( EGET_BACKEND=$eget_backend $SHAREDIR/tools_eget "$@" )
return
fi
fatal "Internal error: missed tools_eget"
......@@ -1366,6 +1372,9 @@ case $PMTYPE in
pkgng)
sudocmd pkg audit -F
;;
apk)
sudocmd apk audit
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
......@@ -1993,6 +2002,9 @@ case $PMTYPE in
xbps)
sudocmd xbps-pkgdb -a
;;
apk)
sudocmd apk fix
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
......@@ -2024,6 +2036,9 @@ check_pkg_integrity()
# FIXME: debsums -ca package ?
docmd dpkg --contents $PKG >/dev/null && echo "Package $PKG is correct."
;;
apk)
docmd apkg verify $PKG
;;
exe)
file $PKG | grep -q "executable for MS Windows"
;;
......@@ -2871,8 +2886,8 @@ __epm_korinf_list() {
__epm_korinf_install() {
# skip interactive for install eepm from stdin
if inputisatty && [ -n "$PROGDIR" ] && [ "$1" != "eepm" ] ; then
# enable interactive for install eepm from console
if inputisatty && [ -n "$PROGDIR" ] && [ "$1" = "eepm" ] ; then
[ -n "$non_interactive" ] || interactive="--interactive"
fi
......@@ -3063,6 +3078,10 @@ __epm_filelist_name()
opkg)
CMD="opkg files"
;;
apk)
docmd apk manifest $@ | sed -e 's|^sha1.* |/|'
return
;;
eopkg)
docmd eopkg --files -s info $@ | grep "^/"
return
......@@ -3439,6 +3458,9 @@ case $PMTYPE in
opkg)
docmd opkg info $pkg_names
;;
apk)
docmd apk info $pkg_names
;;
pkgng)
docmd pkg info $pkg_names
;;
......@@ -3765,6 +3787,12 @@ __epm_if_command_path()
is_dirpath "$1" && rhas "$1" "bin/"
}
__epm_get_replacepkgs()
{
[ -n "$2" ] && echo '--replacepkgs' && return
# don't use --replacepkgs when install only one file
}
epm_install_files()
{
local files="$*"
......@@ -3802,9 +3830,7 @@ epm_install_files()
fi
# --replacepkgs: Install the Package Even If Already Installed
local replacepkgs='--replacepkgs'
# don't use --replacepkgs when install only one file
[ -f "$files" ] && replacepkgs=''
local replacepkgs="$(__epm_get_replacepkgs $files)"
sudocmd rpm -Uvh $replacepkgs $(subst_option dryrun --test) $force $noscripts $nodeps $files && save_installed_packages $files && return
local RES=$?
# TODO: check rpm result code and convert it to compatible format if possible
......@@ -3826,9 +3852,7 @@ epm_install_files()
epm install $(epm req --short $files) || return
# retry with rpm
# --replacepkgs: Install the Package Even If Already Installed
local replacepkgs='--replacepkgs'
# don't use --replacepkgs when install only one file
[ -f "$files" ] && replacepkgs=''
local replacepkgs="$(__epm_get_replacepkgs $files)"
sudocmd rpm -Uvh $replacepkgs $(subst_option dryrun --test) $force $noscripts $nodeps $files && save_installed_packages $files
return
fi
......@@ -3915,9 +3939,7 @@ epm_install_files()
__epm_check_if_src_rpm $files
# --replacepkgs: Install the Package Even If Already Installed
local replacepkgs='--replacepkgs'
# don't use --replacepkgs when install only one file
[ -f "$files" ] && replacepkgs=''
local replacepkgs="$(__epm_get_replacepkgs $files)"
sudocmd rpm -Uvh $replacepkgs $(subst_option dryrun --test) $force $noscripts $nodeps $files && return
local RES=$?
......@@ -5084,7 +5106,7 @@ __run_script()
[ -f "$script.rpmnew" ] && warning "There is .rpmnew file(s) in $psdir dir. The play script can be outdated."
shift
( unset EPMCURDIR ; $script "$@" )
( unset EPMCURDIR ; export PATH=$PROGDIR:$PATH ; $script "$@" )
return
}
......@@ -5170,8 +5192,6 @@ __epm_play_run()
local script="$psdir/$1.sh"
shift
# TODO: use epm print info instead of one?
# we will have DISTRVENDOR there
export PATH=$PROGDIR:$PATH
set_sudo
......@@ -5367,6 +5387,7 @@ __epm_play_install()
epm_play()
{
[ "$EPMMODE" = "package" -o "$EPMMODE" = "git" ] || fatal "epm play is not supported in single file mode"
local psdir="$(realpath $CONFIGDIR/play.d)"
local prsdir="$(realpath $CONFIGDIR/prescription.d)"
......@@ -5375,6 +5396,23 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
exit
fi
if [ "$1" = "--ipfs" ] ; then
shift
if [ -d "$(dirname "$epm_ipfs_db")" ] ; then
export EGET_IPFS_DB="$eget_ipfs_db"
if [ ! -r "$EGET_IPFS_DB" ] ; then
sudorun touch "$EGET_IPFS_DB" >&2
sudorun chmod -v a+rw "$EGET_IPFS_DB" >&2
# get initial db from server
local URL="https://eepm.ru/app-versions"
info "Initialize IPFS DB in $EGET_IPFS_DB file and fill it with data from $URL/eget-ipfs-db.txt"
docmd eget -q -O $EGET_IPFS_DB "$URL/eget-ipfs-db.txt"
fi
else
warning "ipfs db dir $eget_ipfs_db is not exists, skipping --ipfs"
fi
fi
if [ "$1" = "--remove" ] || [ "$1" = "remove" ] ; then
shift
......@@ -5477,6 +5515,9 @@ case $PMTYPE in
packagekit)
docmd pkcon resolve $pkg_names
;;
apk)
docmd apk policy $pkg_names
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
......@@ -7946,6 +7987,10 @@ __epm_have_repack_rule()
# skip repacking on non ALT systems
[ "$BASEDISTRNAME" = "alt" ] || return 1
local packager="$(epm print field Packager for "$1" 2>/dev/null)"
[ "$packager" = "EPM <support@etersoft.ru>" ] && return 1
[ "$packager" = "EPM <support@eepm.ru>" ] && return 1
# FIXME: use real way (for any archive)
local pkgname="$(epm print name for package "$1")"
local repackcode="$EPM_REPACK_SCRIPTS_DIR/$pkgname.sh"
......@@ -7955,7 +8000,8 @@ __epm_have_repack_rule()
__epm_check_if_needed_repack()
{
__epm_have_repack_rule "$@" || return
warning "There is repack rule for $pkgname package. It is better install this package via 'epm --repack install' or 'epm play'."
local pkgname="$(epm print name for package "$1")"
warning "There is repack rule for '$pkgname' package. It is better install this package via 'epm install --repack' or 'epm play'."
}
__epm_split_by_pkg_type()
......@@ -8258,7 +8304,7 @@ __create_rpmmacros()
%_topdir $HOME/RPM
%_tmppath $TMPDIR
%packager EPM <support@etersoft.ru>
%packager EPM <support@eepm.ru>
%_vendor EEPM
%_gpg_name support@etersoft.ru
......@@ -10903,6 +10949,22 @@ done
}
# File bin/epm-stats:
epm_stats()
{
case $PMTYPE in
apk)
CMD="apk stats"
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
docmd $CMD "$@"
}
# File bin/epm-tool:
epm_tool_help()
......@@ -10950,6 +11012,9 @@ epm_tool()
showcmd json "$@"
internal_tools_json "$@"
;;
"which")
print_command_path "$@" # HELPCMD: which like command (no output to stderr, can works without which package)
;;
*)
fatal "Unknown command $ epm tool $WHAT. Use epm print help for get help."
;;
......@@ -10969,7 +11034,7 @@ get_latest_version()
__check_for_epm_version()
{
local latest="$(get_latest_version "epm" 2>/dev/null)"
local latest="$(get_latest_version eepm)"
#[ -z "$latest" ] && return
local res="$(epm print compare "$EPMVERSION" "$latest")"
[ "$res" = "-1" ] && info "Latest EPM version in Korinf repository is $latest. You have version $EPMVERSION running."
......@@ -11184,6 +11249,9 @@ epm_upgrade()
pkgng)
CMD="pkg upgrade"
;;
apk)
CMD="apk upgrade"
;;
chocolatey)
CMD="chocolatey update all"
;;
......@@ -11413,6 +11481,7 @@ is_command()
firstupper()
{
# FIXME: works with GNU sed only
echo "$*" | sed 's/.*/\u&/'
}
......@@ -11549,7 +11618,7 @@ case $DISTRIB_ID in
Cygwin)
CMD="aptcyg"
;;
alpine)
AlpineLinux)
CMD="apk"
;;
TinyCoreLinux)
......@@ -11667,7 +11736,8 @@ normalize_name()
;;
*)
#echo "${1// /}"
firstupper "$1" | sed -e "s/ //g" -e 's|(.*||'
#firstupper "$1" | sed -e "s/ //g" -e 's|(.*||'
echo "$1" | sed -e "s/ //g" -e 's|(.*||'
;;
esac
}
......@@ -12363,7 +12433,7 @@ case "$1" in
;;
--bug-report-url)
print_bug_report_url
exit
return
;;
-s|-n|--vendor-name)
override_distrib "$2"
......@@ -12421,12 +12491,40 @@ internal_tools_eget()
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
PROGDIR=$(dirname "$0")
PROGNAME=$(basename "$0")
CMDSHELL="/bin/sh"
[ "$PROGDIR" = "." ] && PROGDIR="$(pwd)"
if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
PROGDIR=""
PROGNAME=""
fi
fatal()
{
echo "FATAL: $*" >&2
exit 1
}
info()
{
echo "$*" >&2
}
eget()
{
if [ -n "$PROGNAME" ] ; then
local bashopt=''
[ -n "$verbose" ] && bashopt='-x'
(unset EGET_IPFS_GATEWAY; unset EGET_IPFS_API ; unset EGET_IPFS_DB ; $CMDSHELL $bashopt $PROGDIR/$PROGNAME "$@" )
else
#epm_main --inscript "$@"
fatal "Improve me"
fi
}
# TODO:
arch="$(uname -m)"
......@@ -12540,6 +12638,15 @@ is_command()
print_command_path "$1" >/dev/null
}
# add realpath if missed
if ! is_command realpath ; then
realpath()
{
[ -n "$*" ] || return
readlink -f "$@"
}
fi
# check man glob
filter_glob()
......@@ -12566,7 +12673,7 @@ is_fileurl()
echo "$1" | grep -q "^file:/"
}
dir_from_url()
path_from_url()
{
echo "$1" | sed -e 's|^file://*|/|'
}
......@@ -12576,6 +12683,36 @@ is_url()
echo "$1" | grep -q "^[filehtps]*:/"
}
is_strange_url()
{
local URL="$1"
is_url "$URL" || return
echo "$URL" | grep -q "[?&]"
}
is_ipfs_hash()
{
echo "$1" | grep -q -E "^Qm[[:alnum:]]{44}$"
}
is_ipfsurl()
{
is_ipfs_hash "$1" && return
echo "$1" | grep -q "^ipfs://"
}
is_httpurl()
{
# TODO: improve
echo "$1" | grep -q "^https://" & return
echo "$1" | grep -q "^http://" & return
}
cid_from_url()
{
echo "$1" | sed -e 's|^ipfs://*||'
}
# args: cmd <URL> <options>
# will run cmd <options> <URL>
......@@ -12610,17 +12747,25 @@ WGETUSERAGENT=''
CURLUSERAGENT=''
WGETQ='' #-q
CURLQ='' #-s
# TODO: aria2c
# TODO: wget --trust-server-names
# TODO:
WGETNAMEOPTIONS='--content-disposition'
CURLNAMEOPTIONS='--remote-name --remote-header-name'
CURLNAMEOPTIONS='--remote-name --remote-time --remote-header-name'
LISTONLY=''
CHECKURL=''
GETRESPONSE=''
GETFILENAME=''
GETREALURL=''
GETIPFSCID=''
LATEST=''
SECONDLATEST=''
CHECKMIRRORS=''
TARGETFILE=''
FORCEIPV=''
set_quiet()
{
WGETQ='-q'
......@@ -12649,11 +12794,21 @@ Options:
--list|--list-only - print only URLs
--check URL - check if the URL is accessible (returns HTTP 200 OK)
--get-response URL - get response with all headers (ever if HEAD is not acceptable)
--get-filename URL - print filename for the URL (via Content-Disposition if applicable)
--get-real-url URL - print URL after all redirects
Supported URLs:
ftp:// http:// https:// file:/ ipfs://
Supported backends (set like EGET_BACKEND=curl)
wget curl (todo: aria2c)
Examples:
$ eget http://ftp.somesite.ru/package-*.x64.tar
$ eget http://ftp.somesite.ru/package *.tar
$ eget https://github.com/owner/project package*.ext
$ eget -O myname ipfs://QmVRUjnsnxHWkjq91KreCpUk4D9oZEbMwNQ3rzdjwND5dR
$ eget --list http://ftp.somesite.ru/package-*.tar
$ eget --check http://ftp.somesite.ru/test
$ eget --list http://download.somesite.ru 'package-*.tar.xz'
......@@ -12703,6 +12858,18 @@ while [ -n "$1" ] ; do
CHECKURL="$1"
#set_quiet
;;
--get-filename)
GETFILENAME="$1"
;;
--get-response)
GETRESPONSE="$1"
;;
--get-real-url)
GETREALURL="$1"
;;
--get-ipfs-cid)
GETIPFSCID="$1"
;;
--latest)
LATEST="$1"
;;
......@@ -12727,39 +12894,384 @@ while [ -n "$1" ] ; do
done
#############################3
# defaults
# https://github.com/ipfs/kubo/issues/5541
ipfs_diag_timeout='--timeout 10s'
ipfs_api_local="/ip4/127.0.0.1/tcp/5001"
[ -n "$EGET_IPFS_API" ] && ipfs_api_local="$EGET_IPFS_API"
ipfs_api_brave="/ip4/127.0.0.1/tcp/45005"
ipfs_gateway="https://cloudflare-ipfs.com/ipfs"
[ -n "$EGET_IPFS_GATEWAY" ] && ipfs_gateway="$EGET_IPFS_GATEWAY"
IPFS_GATEWAY="$ipfs_gateway"
# Test data: https://etersoft.ru/templates/etersoft/images/logo.png
ipfs_checkQm="QmYwf2GAMvHxfFiUFL2Mr6KUG6QrDiupqGc8ms785ktaYw"
get_ipfs_brave()
{
local ipfs_brave="$(ls ~/.config/BraveSoftware/Brave-Browser/*/*/go-ipfs_* 2>/dev/null)"
[ -n "$ipfs_brave" ] && [ -x "$ipfs_brave" ] || return
echo "$ipfs_brave"
}
ipfs_access()
{
[ -n "$IPFS_CMD" ] || fatal "IPFS is disabled"
$IPFS_CMD --api $IPFS_API $ipfs_diag_timeout diag sys >/dev/null 2>/dev/null
}
ipfs_check()
{
[ -n "$IPFS_CMD" ] || fatal "IPFS is disabled"
$IPFS_CMD --api $IPFS_API $ipfs_diag_timeout cat "$1" >/dev/null
}
select_ipfs_mode()
{
IPFS_CMD="$(get_ipfs_brave)"
# if no EGET_IPFS_API, check brave
if [ -z "$EGET_IPFS_API" ] && [ -n "$IPFS_CMD" ] ; then
IPFS_API="$ipfs_api_brave"
if ipfs_access ; then
if ipfs_check "$ipfs_checkQm" ; then
ipfs_mode="brave" && return
else
info "Skipped Brave: it is accessible via $IPFS_CMD --api $IPFS_API, but can't return shared $ipfs_checkQm"
fi
fi
fi
IPFS_CMD="$(print_command_path ipfs)"
if [ -n "$IPFS_CMD" ] ; then
IPFS_API="$ipfs_api_local"
if ipfs_access ; then
if ipfs_check "$ipfs_checkQm" ; then
ipfs_mode="local" && return
else
info "Skipped local: it is accessible via $IPFS_CMD --api $IPFS_API, but can't return shared $ipfs_checkQm"
fi
fi
fi
# TODO: check checksum
if docmd eget --check "$ipfs_gateway/$ipfs_checkQm" ; then
ipfs_mode="gateway"
return
fi
IPFS_GATEWAY=''
if docmd eget --check "$(dirname $ipfs_gateway)" ; then
info "IPFS gateway $ipfs_gateway is accessible, but can't return shared $ipfs_checkQm"
else
info "IPFS gateway $(dirname $ipfs_gateway) is not accessible"
fi
ipfs_mode="disabled"
}
# Functions for work with eget ipfs db
get_cid_by_url()
{
local URL="$1"
[ -r "$EGET_IPFS_DB" ] || return
is_fileurl "$URL" && return 1
grep -F "$URL Qm" "$EGET_IPFS_DB" | head -n1 | cut -f2 -d" "
}
put_cid_and_url()
{
local URL="$1"
local CID="$2"
local FN="$3"
[ -w "$EGET_IPFS_DB" ] || return
is_fileurl "$URL" && return
echo "$URL $CID $FN" >> "$EGET_IPFS_DB"
echo "Placed in $EGET_IPFS_DB: $URL $CID $FN"
}
get_filename_by_cid()
{
local CID="$1"
[ -z "$EGET_IPFS_DB" ] && echo "$CID" && return
grep -F " $CID " "$EGET_IPFS_DB" | head -n1 | cut -f3 -d" "
}
get_url_by_cid()
{
local CID="$1"
[ -z "$EGET_IPFS_DB" ] && echo "$CID" && return
grep -F " $CID " "$EGET_IPFS_DB" | head -n1 | cut -f1 -d" "
}
###################
ipfs_mode="$EGET_IPFS"
# enable auto mode when set $EGET_IPFS_DB
[ -z "$ipfs_mode" ] && [ -n "$EGET_IPFS_DB" ] && ipfs_mode="auto"
if [ -n "$LISTONLY$CHECKURL" ] ; then
ipfs_mode="disabled"
EGET_IPFS_DB=''
fi
if [ "$ipfs_mode" != "disabled" ] && [ -n "$EGET_IPFS_DB" ] ; then
ddb="$(dirname "$EGET_IPFS_DB")"
if [ -d "$ddb" ] ; then
info "Using eget IPFS db $EGET_IPFS_DB"
[ -r "$EGET_IPFS_DB" ] || touch "$EGET_IPFS_DB"
else
EGET_IPFS_DB=''
fi
fi
# detect if we run with ipfs:// or with auto
if is_ipfsurl "$1" && [ -z "$ipfs_mode" ] || [ "$ipfs_mode" = "auto" ] ; then
select_ipfs_mode
info "Auto selected IPFS mode: $ipfs_mode"
else
[ -n "$ipfs_mode" ] && info "IPFS mode: $ipfs_mode"
fi
IPFS_CMD=''
if [ "$ipfs_mode" = "disabled" ] ; then
ipfs_get()
{
fatal "IPFS is disabled"
}
ipfs_put()
{
fatal "IPFS is disabled"
}
ipfs_cat()
{
fatal "IPFS is disabled"
}
elif [ "$ipfs_mode" = "brave" ] ; then
IPFS_CMD="$(get_ipfs_brave)" || fatal "Can't find ipfs command in Brave"
IPFS_PRETTY_CMD="~Brave-Browser/$(basename $IPFS_CMD)"
IPFS_API="$ipfs_api_brave"
ipfs_access || fatal "Can't access to Brave IPFS API (Brave browser is not running and IPFS is not activated?)"
info "Will use $IPFS_PRETTY_CMD --api $IPFS_API"
elif [ "$ipfs_mode" = "local" ] ; then
IPFS_CMD="$(print_command_path ipfs)" || fatal "Can't find ipfs command"
IPFS_PRETTY_CMD="$IPFS_CMD"
IPFS_API="$ipfs_api_local"
ipfs_access || fatal "Can't access to IPFS API (ipfs daemon is not running?)"
info "Will use $IPFS_PRETTY_CMD --api $IPFS_API"
elif [ "$ipfs_mode" = "gateway" ] ; then
info "Will use eget $IPFS_GATEWAY/HASH"
ipfs_get()
{
[ -n "$IPFS_GATEWAY" ] || fatal "ipfs http gateway is not set"
# FIXME:
if [ -n "$2" ] ; then
docmd eget -O "$2" "$IPFS_GATEWAY/$1"
else
docmd eget "$IPFS_GATEWAY/$1"
fi
}
ipfs_cat()
{
# FIXME:
ipfs_get "$1" "-"
}
ipfs_put()
{
fatal "IPFS add disabled if a gateway is used"
}
elif [ -z "$ipfs_mode" ] ; then
:
else
fatal "Unsupported eget ipfs mode $ipfs_mode"
fi
if [ -n "$IPFS_CMD" ] ; then
ipfs_get()
{
[ -n "$IPFS_CMD" ] || fatal "ipfs api is not usable"
if [ -n "$2" ] ; then
showcmd $IPFS_PRETTY_CMD --api $IPFS_API get -o "$2" "$1"
$IPFS_CMD --api $IPFS_API get -o "$2" "$1"
else
showcmd $IPFS_PRETTY_CMD --api $IPFS_API get "$1"
$IPFS_CMD --api $IPFS_API get "$1"
fi
}
ipfs_put()
{
[ -n "$IPFS_CMD" ] || fatal "ipfs api is not usable"
# detect if -q is used (will output Qm instead of addded Qm)
local qu="$1"
[ "$qu" = "-q" ] || qu=''
showcmd $IPFS_PRETTY_CMD --api $IPFS_API add "$@"
local res
res="$($IPFS_CMD --api $IPFS_API add "$@")" || return
if [ -z "$qu" ] ; then
res="$(echo "$res" | grep "^added Qm")" || return
res="$(echo "$res" | cut -f2 -d" ")"
fi
is_ipfs_hash "$res" && echo "$res" && return
fatal "Can't recognize $res IPFS hash"
}
ipfs_cat()
{
[ -n "$IPFS_CMD" ] || fatal "ipfs api is not usable"
showcmd $IPFS_PRETTY_CMD --api $IPFS_API cat "$1"
$IPFS_CMD --api $IPFS_API cat "$1"
}
fi
###############################
WGET="$(print_command_path wget)"
CURL="$(print_command_path curl)"
if is_fileurl "$1" ; then
EGET_BACKEND="file"
elif is_ipfsurl "$1" ; then
EGET_BACKEND="ipfs"
fi
case "$EGET_BACKEND" in
file|ipfs)
;;
wget)
[ -n "$WGET" ] || fatal "There are no wget in the system but you forced using it via EGET_BACKEND. Install it with $ epm install wget"
;;
curl)
[ -n "$CURL" ] || fatal "There are no curl in the system but you forced using it via EGET_BACKEND. Install it with $ epm install curl"
;;
'')
[ -n "$WGET" ] && EGET_BACKEND="wget"
[ -z "$EGET_BACKEND" ] && [ -n "$CURL" ] && EGET_BACKEND="curl"
[ -n "$EGET_BACKEND" ] || fatal "There are no wget nor curl in the system. Install something with $ epm install wget"
;;
*)
fatal "Uknown EGET_BACKEND $EGET_BACKEND"
;;
esac
if [ "$EGET_BACKEND" = "file" ] ; then
# put remote content to stdout
scat()
url_scat()
{
local URL="$1"
cat "$(dir_from_url "$URL")"
cat "$(path_from_url "$URL")"
}
# download to default name of to $2
sget()
url_sget()
{
local URL="$1"
if [ "$2" = "/dev/stdout" ] || [ "$2" = "-" ] ; then
scat "$URL"
return
elif [ -n "$2" ] ; then
cp -av "$(dir_from_url "$URL")" "$2"
cp -av "$(path_from_url "$URL")" "$2"
return
fi
cp -av "$(dir_from_url "$URL")" .
cp -av "$(path_from_url "$URL")" .
}
check_url_is_accessible()
url_check()
{
local URL="$1"
test -f "$(dir_from_url "$URL")"
test -f "$(path_from_url "$URL")"
}
url_get_filename()
{
basename "$1"
}
url_get_real_url()
{
echo "$1"
}
elif [ -n "$WGET" ] ; then
elif [ "$EGET_BACKEND" = "ipfs" ] ; then
# put remote content to stdout
url_scat()
{
local URL="$1"
ipfs_cat "$(cid_from_url "$URL")"
}
# download to default name of to $2
url_sget()
{
local URL="$1"
if [ "$2" = "/dev/stdout" ] || [ "$2" = "-" ] ; then
scat "$URL"
return
elif [ -n "$2" ] ; then
ipfs_get "$(cid_from_url "$URL")" "$2"
return
fi
ipfs_get "$(cid_from_url "$URL")"
}
url_check()
{
local URL="$1"
# TODO: improve me
scat "$URL" >/dev/null
}
url_get_filename()
{
local URL="$1"
local CID="$(cid_from_url "$URL")"
get_filename_by_cid "$CID"
}
url_get_real_url()
{
local URL="$1"
local CID="$(cid_from_url "$URL")"
get_url_by_cid "$CID"
}
elif [ "$EGET_BACKEND" = "wget" ] ; then
__wget()
{
if [ -n "$WGETUSERAGENT" ] ; then
......@@ -12770,13 +13282,13 @@ __wget()
}
# put remote content to stdout
scat()
url_scat()
{
local URL="$1"
download_with_mirroring __wget "$URL" -O-
}
# download to default name of to $2
sget()
url_sget()
{
local URL="$1"
if [ "$2" = "/dev/stdout" ] || [ "$2" = "-" ] ; then
......@@ -12793,15 +13305,22 @@ sget()
download_with_mirroring __wget "$URL" $WGETNAMEOPTIONS
}
check_url_is_accessible()
url_get_response()
{
local URL="$1"
__wget --spider -S "$URL" 2>&1 | grep "HTTP/" | tail -n1 | grep -q "200"
local answer
answer="$(__wget --spider -S "$URL" 2>&1)"
# HTTP/1.1 405 Method Not Allowed
if echo "$answer" | grep -q "^ *HTTP/[12.]* 405" ; then
__wget --start-pos=5000G -S "$URL" 2>&1
return
fi
echo "$answer"
}
else
CURL="$(print_command_path curl)"
[ -n "$CURL" ] || fatal "There are no wget nor curl in the system. Install it with $ epm install curl"
elif [ "$EGET_BACKEND" = "curl" ] ; then
__curl()
{
if [ -n "$CURLUSERAGENT" ] ; then
......@@ -12811,13 +13330,13 @@ __curl()
fi
}
# put remote content to stdout
scat()
url_scat()
{
local URL="$1"
download_with_mirroring __curl "$URL" --output -
}
# download to default name of to $2
sget()
url_sget()
{
local URL="$1"
local res
......@@ -12832,15 +13351,279 @@ sget()
download_with_mirroring __curl "$URL" $CURLNAMEOPTIONS
}
check_url_is_accessible()
url_get_response()
{
local URL="$1"
local answer
answer="$(__curl -LI "$URL" 2>&1)"
# HTTP/1.1 405 Method Not Allowed
if echo "$answer" | grep -q "^ *HTTP/[12.]* 405" ; then
__curl -L -i -r0-0 "$URL" 2>&1
return
fi
echo "$answer"
}
fi
# Common code for both wget and curl (http related)
if [ "$EGET_BACKEND" = "wget" ] || [ "$EGET_BACKEND" = "curl" ] ; then
url_get_headers()
{
local URL="$1"
url_get_response "$URL" | grep -i "^ *[[:alpha:]].*: " | sed -e 's|^ *||' -e 's|\r$||'
}
url_check()
{
local URL="$1"
url_get_response | grep "HTTP/" | tail -n1 | grep -q -w "200\|404"
}
url_get_header()
{
local URL="$1"
local HEADER="$2"
url_get_headers "$URL" | grep -i "^ *$HEADER: " | sed -e "s|^ *$HEADER: ||i"
}
url_get_real_url()
{
local URL="$1"
! is_httpurl "$URL" && echo "$URL" && return
# don't check location if we have made form of the URL
[ -n "$MADEURL" ] && [ "$MADEURL" = "$URL" ] && echo "$URL" && return
local loc
for loc in $(url_get_header "$URL" "Location" | tac) ; do
if ! is_strange_url "$loc" ; then
echo "$loc"
return
fi
done
echo "$URL"
}
url_get_filename()
{
local URL="$1"
__curl -LI "$URL" 2>&1 | grep "HTTP/" | tail -n1 | grep -q -w "200\|404"
! is_httpurl "$URL" && basename "$URL" && return
# FIXME with wget
local cd="$(url_get_header "$URL" "Content-Disposition")"
if echo "$cd" | grep -q "filename=" ; then
#Content-Disposition: attachment; filename=postman-linux-x64.tar.gz
#content-disposition: attachment; filename="code-1.77.1-1680651749.el7.x86_64.rpm"
echo "$cd" | sed -e 's|.*filename=||' -e 's|^"||' -e 's|";$||' -e 's|"$||'
return
fi
basename "$(url_get_real_url "$URL")"
}
fi
if [ "$ipfs_mode" != "disabled" ] && [ -n "$EGET_IPFS_DB" ] && ! is_ipfsurl "$1" ; then
download_to_ipfs()
{
local URL="$1"
local res
#res="$(url_scat "$URL" | ipfs_put )" || return
#res="$(echo "$res" | grep "^added Qm")" || return 1
#CID="$(echo "$res" | cut -f2 -d" ")"
# with -q to disable progress (mixed with download progress)
res="$(url_scat "$URL" | ipfs_put -q)" || return
is_ipfs_hash "$res" || return 1
echo "$res"
}
# put remote content to stdout
scat()
{
local URL="$1"
url_scat "$URL"
# It is list only function. Don't save to IPFS
return
###################
local CID="$(get_cid_by_url "$URL")"
if [ -n "$CID" ] ; then
info "$URL -> $CID"
ipfs_cat "$CID"
return
fi
CID="$(download_to_ipfs "$URL")" || return
ipfs_cat "$CID" || return
local FN="$(url_get_filename "$URL")" || return
put_cid_and_url "$URL" "$CID" "$FN"
}
# download to default name of to $2
sget()
{
local URL="$1"
local TARGET="$2"
if [ -n "$GETFILENAME" ] ; then
get_filename "$URL"
return
fi
local REALURL="$(get_real_url "$URL")" || return
if [ -n "$GETREALURL" ] ; then
echo "$REALURL"
return
fi
# skip ipfs for cat
if [ "$TARGET" = "/dev/stdout" ] || [ "$TARGET" = "-" ] ; then
url_scat "$URL"
return
fi
#if is_strange_url "$REALURL" ; then
# info "Just download strange URL $REALURL, skipping IPFS"
# url_sget "$REALURL" "$TARGET"
# return
#fi
local CID="$(get_cid_by_url "$REALURL")"
if [ -n "$CID" ] ; then
if [ -n "$GETIPFSCID" ] ; then
echo "$CID"
return
fi
if [ -n "$GETFILENAME" ] ; then
get_filename_by_cid "$CID"
return
fi
if [ -n "$GETREALURL" ] ; then
get_url_by_cid "$CID"
return
fi
if [ -z "$TARGET" ] ; then
# TODO: in some cases we can get name from URL...
TARGET="$(get_filename_by_cid "$CID")"
if [ -z "$TARGET" ] ; then
TARGET="$CID"
fi
fi
[ "$URL" = "$REALURL" ] && info "$URL -> $CID -> $TARGET" || info "$URL -> $REALURL -> $CID -> $TARGET"
ipfs_get "$CID" "$TARGET" && return
# fail get from IPFS, fallback
url_sget "$REALURL" "$TARGET"
return
fi
# download and put to IPFS
local FN="$(url_get_filename "$REALURL")" || return
if [ -z "$TARGET" ] ; then
TARGET="$FN"
fi
if [ -n "$GETIPFSCID" ] ; then
# add to IPFS and print out CID
CID="$(ipfs_put --progress "$REALURL")" || return
echo "$CID"
return
fi
# download file and add to IPFS
url_sget "$REALURL" "$TARGET" || return
CID="$(ipfs_put --progress "$TARGET")" || return
put_cid_and_url "$REALURL" "$CID" "$FN"
}
check_url_is_accessible()
{
local URL="$1"
local REALURL="$(get_real_url "$URL")" || return
local CID="$(get_cid_by_url "$REALURL")"
if [ -n "$CID" ] ; then
[ "$URL" = "$REALURL" ] && info "$URL -> $CID" || info "$URL -> $REALURL -> $CID"
ipfs_check "$CID"
return
fi
CID="$(download_to_ipfs "$REALURL")" || return
local FN="$(url_get_filename "$REALURL")" || return
ipfs_cat "$CID" >/dev/null || return
put_cid_and_url "$REALURL" "$CID" "$FN"
}
get_filename()
{
url_get_filename "$1"
}
get_real_url()
{
url_get_real_url "$1"
}
else
scat()
{
url_scat "$@"
}
sget()
{
if [ -n "$GETFILENAME" ] ; then
get_filename "$1"
return
fi
if [ -n "$GETREALURL" ] ; then
get_real_url "$1"
return
fi
url_sget "$@"
}
check_url_is_accessible()
{
url_check "$@"
}
get_filename()
{
url_get_filename "$1"
}
get_real_url()
{
url_get_real_url "$1"
}
fi
get_github_urls()
{
......@@ -12868,6 +13651,9 @@ concatenate_url_and_filename()
echo "$(echo "$url" | sed -e 's|/*$||' )/$fn"
}
# MADEURL filled with latest made URL as flag it is end form of URL
MADEURL=''
# Args: URL filename
make_fileurl()
{
......@@ -12887,13 +13673,14 @@ make_fileurl()
url="$(dirname "$url")"
fi
concatenate_url_and_filename "$url" "$fn"
MADEURL="$(concatenate_url_and_filename "$url" "$fn")"
echo "$MADEURL"
}
get_urls()
{
if is_fileurl "$URL" ; then
ls -1 "$(dir_from_url "$URL")"
ls -1 "$(path_from_url "$URL")"
return
fi
......@@ -12903,13 +13690,17 @@ get_urls()
}
if [ -n "$CHECKURL" ] ; then
#set_quiet
check_url_is_accessible "$1"
return
fi
if [ -n "$GETRESPONSE" ] ; then
url_get_response "$1"
return
fi
# separate part for github downloads
if echo "$1" | grep -q "^https://github.com/" && \
......@@ -12923,12 +13714,18 @@ if echo "$1" | grep -q "^https://github.com/" && \
ERROR=0
for fn in $(get_github_urls "$1" | filter_glob "$MASK" | filter_order) ; do
MADEURL="$fn" # mark it is the end form of the URL
sget "$fn" "$TARGETFILE" || ERROR=1
[ -n "$TARGETFILE" ] && [ "$ERROR" = "0" ] && break
done
return
fi
if is_ipfsurl "$1" ; then
[ -n "$2" ] && fatal "too many args when ipfs://Qm... used: extra '$2' arg"
sget "$1" "$TARGETFILE"
return
fi
# if mask is the second arg
if [ -n "$2" ] ; then
......@@ -12973,10 +13770,6 @@ fi
# If there is no wildcard symbol like asterisk, just download
if echo "$MASK" | grep -qv "[*?]" || echo "$MASK" | grep -q "[?].*="; then
if is_fileurl "$1" ; then
sget "$(dir_from_url "$1")" "$TARGEFILE"
return
fi
sget "$1" "$TARGETFILE"
return
fi
......@@ -14152,6 +14945,9 @@ pkg_urls=
quoted_args=
direct_args=
eget_backend=$EGET_BACKEND
eget_ipfs_db=/var/lib/eepm/eget-ipfs-db.txt
# load system wide config
[ -f $CONFIGDIR/eepm.conf ] && . $CONFIGDIR/eepm.conf
......@@ -14351,6 +15147,10 @@ check_command()
epm_cmd=remove_old_kernels
direct_args=1
;;
stats) # HELPCMD: show statistics about repositories and installations
epm_cmd=stats
direct_args=1
;;
# HELPCMD: PART: Other commands:
clean|delete-cache|dc) # HELPCMD: clean local package cache
......@@ -14594,7 +15394,7 @@ if [ -n "$quiet" ] ; then
fi
# fill
export EPM_OPTIONS="$nodeps $force $verbose $quiet $non_interactive $save_only $download_only"
export EPM_OPTIONS="$nodeps $force $verbose $quiet $interactive $non_interactive $save_only $download_only"
# if input is not console and run script from file, get pkgs from stdin too
if [ ! -n "$inscript" ] && ! inputisatty && [ -n "$PROGDIR" ] ; then
......
......@@ -492,7 +492,7 @@ disabled_eget()
local EGET
# use internal eget only if exists
if [ -s $SHAREDIR/tools_eget ] ; then
$SHAREDIR/tools_eget "$@"
( EGET_BACKEND=$eget_backend $SHAREDIR/tools_eget "$@" )
return
fi
fatal "Internal error: missed tools_eget"
......@@ -1512,6 +1512,7 @@ is_command()
firstupper()
{
# FIXME: works with GNU sed only
echo "$*" | sed 's/.*/\u&/'
}
......@@ -1648,7 +1649,7 @@ case $DISTRIB_ID in
Cygwin)
CMD="aptcyg"
;;
alpine)
AlpineLinux)
CMD="apk"
;;
TinyCoreLinux)
......@@ -1766,7 +1767,8 @@ normalize_name()
;;
*)
#echo "${1// /}"
firstupper "$1" | sed -e "s/ //g" -e 's|(.*||'
#firstupper "$1" | sed -e "s/ //g" -e 's|(.*||'
echo "$1" | sed -e "s/ //g" -e 's|(.*||'
;;
esac
}
......@@ -2462,7 +2464,7 @@ case "$1" in
;;
--bug-report-url)
print_bug_report_url
exit
return
;;
-s|-n|--vendor-name)
override_distrib "$2"
......@@ -2562,7 +2564,7 @@ print_version()
local on_text="(host system)"
local virt="$($DISTRVENDOR -i)"
[ "$virt" = "(unknown)" ] || [ "$virt" = "(host system)" ] || on_text="(under $virt)"
echo "Service manager version 3.42.0 https://wiki.etersoft.ru/Epm"
echo "Service manager version 3.50.0 https://wiki.etersoft.ru/Epm"
echo "Running on $($DISTRVENDOR -e) $on_text with $SERVICETYPE"
echo "Copyright (c) Etersoft 2012-2021"
echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment