up #14

Merged
wt merged 3 commits from up into version-support 2025-09-29 12:52:39 +00:00
+306 -162
View File
@@ -19,6 +19,9 @@ packagesqueryfile=$rootdir/usr/share/pm/query
reposquerydir=$rootdir/usr/share/pm/repos reposquerydir=$rootdir/usr/share/pm/repos
cachedpkgdir=$rootdir/var/cache/pm/pkg cachedpkgdir=$rootdir/var/cache/pm/pkg
installedpackagesdir=$rootdir/usr/share/pm/packages installedpackagesdir=$rootdir/usr/share/pm/packages
command=""
packages=""
archives=""
#----------------------------------------------------- #-----------------------------------------------------
#----- colors ------- #----- colors -------
@@ -59,136 +62,137 @@ checknonroot() {
#----------------- add(install) package function ------------------------ #----------------- add(install) package function ------------------------
add() { add() {
shift 1 [[ "$packages" == "" ]] \
[[ "$1" == "" ]] \
&& help \ && help \
&& exit 0 && exit 0
for i in $@; do down
down $i for i in $packages; do
done archives="$archives $(echo $cachedpkgdir/$i*.pkg.gz)"
for i in $@; do
unpack $cachedpkgdir/$i*.pkg.gz
done done
unpack
} }
a() { a() {
add $@ add
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#-------------------- download package without install function --------- #-------------------- download package without install function ---------
down() { down() {
[[ ! $1 ]] \ [[ "$packages" == "" ]] \
&& help \ && help \
&& exit 0 && exit 0
servers=$(/usr/bin/cat $repofile) for k in $packages; do
check $? "Read repositories" downloaded=n
for i in $servers; do servers=$(/usr/bin/cat $repofile)
serverdir=$(echo $i | sed -e "/http:\/\//s///") check $? "Read repositories"
serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///") for i in $servers; do
repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///') serverdir=$(echo $i | sed -e "/http:\/\//s///")
for j in $repoquery; do serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///")
# echo $(get_pkgname $j) $(get_pkgname $1) repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
if [[ "$(get_pkgname $j)" == "$1" ]]; then for j in $repoquery; do
if [ ! -f $cachedpkgdir/$j.pkg.gz ]; then if [[ "$(get_pkgname $j)" == "$k" ]]; then
printf "$YELLOW**$RESET Downloading $YELLOW$serverdir: $Bwhite$j\n$RESET" if [ ! -f $cachedpkgdir/$j.pkg.gz ]; then
echo $i/$j.pkg.gz printf "$YELLOW**$RESET Downloading $YELLOW$serverdir: $Bwhite$j\n$RESET"
wget $i/$j.pkg.gz -P $cachedpkgdir echo $i/$j.pkg.gz
check $? "Download package" wget $i/$j.pkg.gz -P $cachedpkgdir
# if [[ "$?" == "0" ]]; then check $? "Download package"
# printf "$YELLOW**$GREEN successful downloaded $1\n$RESET" else
# return printf "$YELLOW**$GREEN successful downloaded $k\n$RESET"
# else downloaded=y
# printf "$YELLOW**$RED error:$RESET can't download package\n" fi
# exit 1 downloaded=y
# fi
else
printf "$YELLOW**$GREEN successful downloaded $1\n$RESET"
return
fi fi
return done
fi
done done
if [ "$downloaded" == "n" ]; then
printf "$BBLUE**$BWHITE Can't find package $k [$BRED ERROR $BWHITE]\n$RESET"
fi
continue
done done
printf "$BBLUE**$BWHITE Can't find package $1 [$BRED ERROR $BWHITE]\n$RESET"
exit 1
} }
download() { download() {
down $1 down
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#-------------------- unpack local package archive ---------------------- #-------------------- unpack local package archive ----------------------
unpack() { unpack() {
[[ "$1" == "" ]] \ [[ "$archives" == "" ]] \
&& printf "$BBLUE**$BWHITE Specify package name [$BRED ERROR $BWHITE]\n$RESET" \ && printf "$BBLUE**$BWHITE Specify package name [$BRED ERROR $BWHITE]\n$RESET" \
&& exit 1 && exit 1
packagename=$(echo $1 | sed -e "/.gz/s///") for i in $archives; do
packagename=${packagename#*pkg/} if [ ! -f $i ]; then
printf "$YELLOW**$GREEN Installing ${packagename%.pkg*}\n$RESET" printf "$BBLUE**$BWHITE File $i not found [$BRED ERROR $BWHITE]\n$RESET" \
[ ! -f $packagesqueryfile ] \ && exit 1
&& printf "$BBLUE**$BWHITE Can't find $packagesqueryfile [$BRED ERROR $BWHITE]\n$RESET" \ fi
&& exit 1 packagename=$(echo $i | sed -e "/.gz/s///")
installed=false packagename=${packagename#*pkg/}
for i in $(/usr/bin/cat $packagesqueryfile); do printf "$YELLOW**$GREEN Installing ${packagename%.pkg*}\n$RESET"
[ "$i" = "${packagename%.pkg*}" ] \ [ ! -f $packagesqueryfile ] \
&& export installed=true \ && printf "$BBLUE**$BWHITE Can't find $packagesqueryfile [$BRED ERROR $BWHITE]\n$RESET" \
&& break && exit 1
done installed=false
[[ "$installed" == "true" ]] \ for i in $(/usr/bin/cat $packagesqueryfile); do
&& printf "$YELLOW**$RESET Package already installed:$YELLOW reinstalling\n$RESET" [ "$i" = "${packagename%.pkg*}" ] \
tar -xvf $1 -C $rootdir/tmp &> /dev/null && export installed=true \
cd $rootdir/tmp/$packagename && break
[ -f pre_install ] \ done
&& /usr/bin/sh -c ./pre_install \ [[ "$installed" == "true" ]] \
&& rm -v pre_install &> /dev/null && printf "$YELLOW**$RESET Package already installed:$YELLOW reinstalling\n$RESET"
if [ -f deps ]; then tar -xf $cachedpkgdir/$packagename.gz -C $rootdir/tmp
printf "$YELLOW**$GREEN Checking deps\n$RESET" cd $rootdir/tmp/$packagename
deps=$(/usr/bin/cat deps) [ -f pre_install ] \
for dep in $deps; do && /usr/bin/sh -c ./pre_install \
have=false && rm -v pre_install &> /dev/null
for pack in $(/usr/bin/cat $packagesqueryfile); do if [ -f deps ]; then
if [ $pack = $dep ]; then printf "$YELLOW**$GREEN Checking deps\n$RESET"
have=yes deps=$(/usr/bin/cat deps)
break for dep in $deps; do
have=false
for pack in $(/usr/bin/cat $packagesqueryfile); do
if [ $pack = $dep ]; then
have=yes
break
fi
done
if [ "$have" = "false" ]; then
pkgnow=$packagename
add "" $dep
unpack $cachedpkgdir/$pkgnow.gz
return
fi fi
done done
if [ "$have" = "false" ]; then mkdir $installedpackagesdir/$packagename &> /dev/null
pkgnow=$packagename mv -v deps $installedpackagesdir/$packagename &> /dev/null
add "" $dep fi
unpack $cachedpkgdir/$pkgnow.gz
return
fi
done
mkdir $installedpackagesdir/$packagename &> /dev/null mkdir $installedpackagesdir/$packagename &> /dev/null
mv -v deps $installedpackagesdir/$packagename &> /dev/null mv -v list $installedpackagesdir/$packagename &> /dev/null
fi [ -f pre_delete ] \
mkdir $installedpackagesdir/$packagename &> /dev/null && mv -v pre_delete $installedpackagesdir/$packagename &> /dev/null
mv -v list $installedpackagesdir/$packagename &> /dev/null [ -f post_delete ] \
[ -f pre_delete ] \ && mv -v post_delete $installedpackagesdir/$packagename &> /dev/null
&& mv -v pre_delete $installedpackagesdir/$packagename &> /dev/null cp -r ./* $rootdir/
[ -f post_delete ] \ [ -f $rootdir/post_install ] \
&& mv -v post_delete $installedpackagesdir/$packagename &> /dev/null && rm $rootdir/post_install
cp -r ./* $rootdir/ [ -f $rootdir/tmp/$packagename/post_install ] \
[ -f $rootdir/post_install ] \ && printf "$YELLOW**$GREEN post_install script ${packagename%.pkg*}\n$RESET" \
&& rm $rootdir/post_install && /usr/bin/sh -c $rootdir/tmp/$packagename/post_install &> /dev/null
[ -f $rootdir/tmp/$packagename/post_install ] \ [[ "$installed" == "false" ]] \
&& printf "$YELLOW**$GREEN post_install script ${packagename%.pkg*}\n$RESET" \ && echo ${packagename%.pkg*} >> $packagesqueryfile
&& /usr/bin/sh -c $rootdir/tmp/$packagename/post_install &> /dev/null rm -rv $rootdir/tmp/$packagename &> /dev/null
[[ "$installed" == "false" ]] \ printf "$YELLOW**$GREEN Installed ${packagename%.pkg*} successful\n$RESET"
&& echo ${packagename%.pkg*} >> $packagesqueryfile cd - &> /dev/null
rm -rv $rootdir/tmp/$packagename &> /dev/null done
printf "$YELLOW**$GREEN Installed ${packagename%.pkg*} successful\n$RESET"
} }
u() { u() {
unpack $1 unpack
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#------------------ delete package function ----------------------------- #------------------ delete package function -----------------------------
del() { del() {
printf "$YELLOW**$GREEN deleting\n$RESET" printf "$YELLOW**$GREEN deleting\n$RESET"
shift 1 for i in $packages; do
for i in $@; do
printf "$YELLOW**$GREEN deleting $i\n$RESET" printf "$YELLOW**$GREEN deleting $i\n$RESET"
[ ! -f $installedpackagesdir/$i*.pkg/list ] \ [ ! -f $installedpackagesdir/$i*.pkg/list ] \
&& printf "$BBLUE**$BWHITE package not installed ($i) [$BRED ERROR $BWHITE]\n$RESET" \ && printf "$BBLUE**$BWHITE package not installed ($i) [$BRED ERROR $BWHITE]\n$RESET" \
@@ -213,31 +217,46 @@ del() {
done done
} }
d() { d() {
del $@ del
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#------------------- list files in package function --------------------- #------------------- list files in package function ---------------------
list() { list() {
if [[ "$1" == "" ]]; then if [[ "$packages" == "" ]]; then
for i in $(/usr/bin/cat $packagesqueryfile); do for i in $(/usr/bin/cat $packagesqueryfile); do
filelist=$(/usr/bin/cat $installedpackagesdir/$i*.pkg/list) cd $installedpackagesdir
pkgname=$(echo $(find . -name "$i*") | sed -e "/.\//s///" | sed -e "/.pkg/s///")
cd - &>/dev/null
if [[ "$(/usr/bin/cat $packagesqueryfile | grep $i)" == "" ]]; then
printf "$BBLUE**$BWHITE Package "$i" is not installed [$BRED ERROR $BWHITE]\n$RESET"
continue
fi
filelist=$(/usr/bin/cat $installedpackagesdir/$pkgname*.pkg/list)
for j in $filelist; do for j in $filelist; do
printf "$YELLOW$i: $BWHITE$j$RESET\n" printf "$YELLOW$(get_pkgname $pkgname) $BGREEN$(get_pkgver $pkgname)-$(get_pkgrel $pkgname): $BWHITE$j$RESET\n"
done done
unset pkgname
done done
exit 0 exit 0
fi fi
[[ "$(/usr/bin/cat $packagesqueryfile | grep $1)" == "" ]] \ for i in $packages; do
&& printf "$BBLUE**$BWHITE Package is not installed [$BRED ERROR $BWHITE]\n$RESET" \ cd $installedpackagesdir
&& exit 1 pkgname=$(echo $(find . -name "$i*") | sed -e "/.\//s///" | sed -e "/.pkg/s///")
filelist=$(/usr/bin/cat $installedpackagesdir/$1*.pkg/list) cd - &>/dev/null
for i in $filelist; do if [[ "$(/usr/bin/cat $packagesqueryfile | grep $i)" == "" ]]; then
printf "$YELLOW$1: $BWHITE$i$RESET\n" printf "$BBLUE**$BWHITE Package "$i" is not installed [$BRED ERROR $BWHITE]\n$RESET"
continue
fi
filelist=$(/usr/bin/cat $installedpackagesdir/"${pkgname}".pkg/list)
for j in $filelist; do
printf "$YELLOW$(get_pkgname $pkgname) $BGREEN$(get_pkgver $pkgname)-$(get_pkgrel $pkgname): $BWHITE$j$RESET\n"
done
unset pkgname
done done
} }
l() { l() {
list $1 list
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
get_pkgrel() { get_pkgrel() {
@@ -274,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"
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -311,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///")
@@ -319,8 +340,9 @@ search() {
for j in $repoquery; do for j in $repoquery; do
installed=false installed=false
for inst in $(/usr/bin/cat $packagesqueryfile); do for inst in $(/usr/bin/cat $packagesqueryfile); do
# echo $inst
[ "$(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
@@ -332,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
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -355,18 +379,50 @@ ss() {
clear() { clear() {
rm -v $cachedpkgdir/* rm -v $cachedpkgdir/*
} }
clean() {
clear
}
c() {
clear
}
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#--- show package dependencies function --- #--- show package dependencies function ---
deps() { deps() {
[ "$1" = "" ] \ if [[ "$packages" == "" ]]; then
&& help \ for i in $(/usr/bin/cat $packagesqueryfile); do
&& exit 1 cd $installedpackagesdir
[ ! -f $installedpackagesdir/$1*.pkg/deps ] \ pkgname=$(echo $(find . -name "$i*") | sed -e "/.\//s///" | sed -e "/.pkg/s///")
&& printf "$YELLOW**$BWHITE No deps\n$RESET" \ cd - &>/dev/null
&& exit 0 printf "$YELLOW$(get_pkgname $pkgname) $BGREEN$(get_pkgver $pkgname)-$(get_pkgrel $pkgname)$BWHITE deps: \n$RESET"
for i in $(cat $installedpackagesdir/$1*.pkg/deps); do [ ! -f $installedpackagesdir/${pkgname}.pkg/deps ] \
printpkg $i && printf "\t$YELLOW**$BWHITE No deps\n$RESET" \
&& continue
for j in $(cat $installedpackagesdir/${pkgname}.pkg/deps); do
printf "\t"
printpkg $j
done
unset pkgname
done
exit 0
fi
for i in $packages; do
cd $installedpackagesdir
pkgname=$(echo $(find . -name "$i*") | sed -e "/.\//s///" | sed -e "/.pkg/s///")
cd - &>/dev/null
if [ "$pkgname" = "" ]; then
printf "$BBLUE**$BWHITE Package $i not found [$BRED ERROR $BWHITE]\n$RESET"
continue
fi
printf "$YELLOW$(get_pkgname $pkgname) $BGREEN$(get_pkgver $pkgname)-$(get_pkgrel $pkgname)$BWHITE deps: \n$RESET"
[ ! -f $installedpackagesdir/${pkgname}.pkg/deps ] \
&& printf "\t$YELLOW**$BWHITE No deps\n$RESET" \
&& continue
for j in $(cat $installedpackagesdir/${pkgname}.pkg/deps); do
printf "\t"
printpkg $j
done
unset pkgname
done done
} }
#------------------------------------------ #------------------------------------------
@@ -462,28 +518,116 @@ buildpkg() {
} }
#----------------------------------------------------- #-----------------------------------------------------
# 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
add|a|del|d)
command=$1
shift
packages=$@
break;
;;
s|sync|clear|down|download)
command=$1
shift
packages=$@
break;
;;
unpack|u|up|upgrade|i|index)
command=$1
shift
archives=$@
break;
;;
query|q|search|ss|list|l|deps)
command=$1
shift
packages=$@
break
;;
build)
checknonroot
buildpkg $@
;;
*)
shift
;;
esac
done
}
parse_opts() {
while [ $1 ]; do
case "$1" in
-h|--help)
help
exit 0
;;
-r|--rootdir)
rootdir=$2
shift 2
;;
*)
if [ "${1#--}" != "$1" ]; then
echo "Invalid option: $1" >&2
help
exit 1
fi
shift
;;
esac
done
}
#--- main --- #--- main ---
main() { main() {
case "$1" in parse_command "$@"
add|a|del|d) parse_opts "$@"
checkroot if [ -z "$command" ]; then
"$1" $@ help
;; exit 1
s|sync|clear|unpack|u|down|download) fi
checkroot $command
"$1" $2
;;
query|q|search|ss|list|l|deps)
"$1" $2
;;
build)
checknonroot
buildpkg $2
;;
*)
help
;;
esac
} }
#------------ #------------