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 ------------------------------- #--------------------- show help function -------------------------------
help() { help() {
printf " printf "
$YELLOW**$GREEN pm usage$RESET : $YELLOW**$GREEN pm usage$RESET:
$BWHITE add, a [package name] - download and install from repository ${BWHITE}add, a [package name] - download and install from repository
unpack, u [/path/to/package/archive] - unpack(install) from local package archive unpack, u [/path/to/package/archive] - unpack(install) from local package archive
down, download [package name] - download package from repository without install down, download [package name] - download package from repository without install
del, d [package name] - delete package up, upgrade - upgrade packages
list, l [package name] - list files in package del, d [package name] - delete package
search, ss [package name] - search package in repository list, l [package name] - list files in package
query, q - show installed packages search, ss [package name] - search package in repository
help - this help message query, q - show installed packages
clear - clear all package archives from cached packages directory help - this help message
sync, s - synchronize repository clear, c - clear all package archives from cached packages directory
deps [package name] - show package dependencies sync, s - synchronize repository
build - build package (./ must contain PMBUILD) deps [package name] - show package dependencies
\n$RESET" 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 package in repo function ----------------------
search() { search() {
servers=$(/usr/bin/cat $repofile) servers=$(/usr/bin/cat $repofile)
if [[ ! $1 ]]; then if [[ "$packages" == "" ]]; then
for i in $servers; do for i in $servers; do
serverdir=$(echo $i | sed -e "/http:\/\//s///") serverdir=$(echo $i | sed -e "/http:\/\//s///")
serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///") serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///")
@@ -339,6 +341,8 @@ search() {
installed=false installed=false
for inst in $(/usr/bin/cat $packagesqueryfile); do for inst in $(/usr/bin/cat $packagesqueryfile); do
[ "$(get_pkgname $inst)" = "$(get_pkgname $j)" ] \ [ "$(get_pkgname $inst)" = "$(get_pkgname $j)" ] \
&& [ "$(get_pkgver $inst)" = "$(get_pkgver $j)" ] \
&& [ "$(get_pkgrel $inst)" = "$(get_pkgrel $j)" ] \
&& export installed=true \ && export installed=true \
&& break && break
done done
@@ -350,22 +354,24 @@ search() {
done done
exit 0 exit 0
fi fi
found=false for k in $packages; do
for i in $servers; do found=false
serverdir=$(echo $i | sed -e "/http:\/\//s///") for i in $servers; do
serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///") serverdir=$(echo $i | sed -e "/http:\/\//s///")
repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///') serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///")
for j in $repoquery; do repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
if [[ $j =~ $1 ]]; then for j in $repoquery; do
printf "$YELLOW$serverdir: $BWHITE$j\n$RESET" if [[ $j =~ $k ]]; then
found=true printf "$YELLOW$serverdir: $BWHITE$j\n$RESET"
fi found=true
fi
done
done done
[ "$found" = "false" ] && printf "$YELLOW**$RED error:$RESET can't find package ($k)\n"
done done
[ "$found" = "false" ] && printf "$YELLOW**$RED error:$RESET can't find package ($1)\n"
} }
ss() { ss() {
search $1 search
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -373,6 +379,12 @@ ss() {
clear() { clear() {
rm -v $cachedpkgdir/* rm -v $cachedpkgdir/*
} }
clean() {
clear
}
c() {
clear
}
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#--- show package dependencies function --- #--- show package dependencies function ---
@@ -505,6 +517,48 @@ buildpkg() {
unset pkgdir srcdir buildroot 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() { parse_command() {
while [ $1 ]; do while [ $1 ]; do
case "$1" in case "$1" in
@@ -520,7 +574,7 @@ parse_command() {
packages=$@ packages=$@
break; break;
;; ;;
unpack|u) unpack|u|up|upgrade|i|index)
command=$1 command=$1
shift shift
archives=$@ archives=$@