added upgrade up and c clean clear

This commit is contained in:
wt committed 2025-09-29 19:51:38 +07:00
1 parent 0c7652fe09
commit 950f6bc0b3
1 file changed
+82 -28
+82 -28
View File
@@ -293,20 +293,22 @@ q() {
#--------------------- show help function -------------------------------
help() {
printf "
$YELLOW**$GREEN pm usage$RESET :
$BWHITE add, a [package name] - download and install from repository
unpack, u [/path/to/package/archive] - unpack(install) from local package archive
down, download [package name] - download package from repository without install
del, d [package name] - delete package
list, l [package name] - list files in package
search, ss [package name] - search package in repository
query, q - show installed packages
help - this help message
clear - clear all package archives from cached packages directory
sync, s - synchronize repository
deps [package name] - show package dependencies
build - build package (./ must contain PMBUILD)
\n$RESET"
$YELLOW**$GREEN pm usage$RESET:
${BWHITE}add, a [package name] - download and install from repository
unpack, u [/path/to/package/archive] - unpack(install) from local package archive
down, download [package name] - download package from repository without install
up, upgrade - upgrade packages
del, d [package name] - delete package
list, l [package name] - list files in package
search, ss [package name] - search package in repository
query, q - show installed packages
help - this help message
clear, c - clear all package archives from cached packages directory
sync, s - synchronize repository
deps [package name] - show package dependencies
build - build package (./ must contain PMBUILD)
index, i - scan directory with packages and print packages in terminal (to create repository query use pm index > query)
$RESET"
}
#------------------------------------------------------------------------
@@ -330,7 +332,7 @@ s() {
#----------------- search package in repo function ----------------------
search() {
servers=$(/usr/bin/cat $repofile)
if [[ ! $1 ]]; then
if [[ "$packages" == "" ]]; then
for i in $servers; do
serverdir=$(echo $i | sed -e "/http:\/\//s///")
serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///")
@@ -339,6 +341,8 @@ search() {
installed=false
for inst in $(/usr/bin/cat $packagesqueryfile); do
[ "$(get_pkgname $inst)" = "$(get_pkgname $j)" ] \
&& [ "$(get_pkgver $inst)" = "$(get_pkgver $j)" ] \
&& [ "$(get_pkgrel $inst)" = "$(get_pkgrel $j)" ] \
&& export installed=true \
&& break
done
@@ -350,22 +354,24 @@ search() {
done
exit 0
fi
found=false
for i in $servers; do
serverdir=$(echo $i | sed -e "/http:\/\//s///")
serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///")
repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
for j in $repoquery; do
if [[ $j =~ $1 ]]; then
printf "$YELLOW$serverdir: $BWHITE$j\n$RESET"
found=true
fi
for k in $packages; do
found=false
for i in $servers; do
serverdir=$(echo $i | sed -e "/http:\/\//s///")
serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///")
repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
for j in $repoquery; do
if [[ $j =~ $k ]]; then
printf "$YELLOW$serverdir: $BWHITE$j\n$RESET"
found=true
fi
done
done
[ "$found" = "false" ] && printf "$YELLOW**$RED error:$RESET can't find package ($k)\n"
done
[ "$found" = "false" ] && printf "$YELLOW**$RED error:$RESET can't find package ($1)\n"
}
ss() {
search $1
search
}
#------------------------------------------------------------------------
@@ -373,6 +379,12 @@ ss() {
clear() {
rm -v $cachedpkgdir/*
}
clean() {
clear
}
c() {
clear
}
#------------------------------------------------------------------------
#--- show package dependencies function ---
@@ -505,6 +517,48 @@ buildpkg() {
unset pkgdir srcdir buildroot
}
#-----------------------------------------------------
# upgrade system packages function
upgrade() {
total_updates=0
for i in $(cat $packagesqueryfile); do
package=$(search $(get_pkgname $i) | awk -F' ' '{ for (i=2; i<=NF; i++) { print $i } }')
repo=$(search $(get_pkgname $i) | awk -F' ' '{ print $1 }')
for j in $package; do
if [ $(get_pkgrel $j) -gt $(get_pkgrel $i) ]; then
printf "${BRED}old: $(printpkg $i)"
printf "${BGREEN}new: $(printpkg $j)"
printf "${BGREEN}from: $(printf $repo | sed 's/://g')\n$RESET"
total_updates=$((total_updates+1))
continue
fi
instver=$(echo $(get_pkgver $i) | awk -F'.' '{ for (i=1; i<=NF; i++) printf $i }')
repover=$(echo $(get_pkgver $j) | awk -F'.' '{ for (i=1; i<=NF; i++) printf $i }')
if [ $repover -gt $instver ]; then
printf "${BRED}old: $(printpkg $i)"
printf "${BGREEN}new: $(printpkg $j)"
printf "${BGREEN}from: $(printf $repo | sed 's/://g')\n$RESET"
total_updates=$((total_updates+1))
continue
fi
done
done
printf "${YELLOW}Total updates: ${BWHITE}$total_updates\n$RESET"
return
}
up() {
upgrade
}
# index packages in directory and create query file for create pm repository
index() {
for i in $(ls | grep .pkg.gz);do echo $i | sed 's/.pkg.gz//g';done
}
i() {
index
}
#---------------------------------------------------------------------------
parse_command() {
while [ $1 ]; do
case "$1" in
@@ -520,7 +574,7 @@ parse_command() {
packages=$@
break;
;;
unpack|u)
unpack|u|up|upgrade|i|index)
command=$1
shift
archives=$@