added check package versions #11

This commit is contained in:
wt committed 2025-05-19 17:17:35 +07:00
1 parent d1164975e3
commit fa04c30d6c
2 files changed
+144 -138

No files matched your search

+1 -3
View File
@@ -4,7 +4,6 @@ DESTDIR=/
install: install:
@if [ ! -d ${DESTDIR}/etc/pm ]; then \ @if [ ! -d ${DESTDIR}/etc/pm ]; then \
mkdir -p ${DESTDIR}/etc/pm; \ mkdir -p ${DESTDIR}/etc/pm; \
# touch ${DESTDIR}/etc/pm/repo; \
fi fi
@if [ ! -d ${DESTDIR}/tmp ]; then \ @if [ ! -d ${DESTDIR}/tmp ]; then \
mkdir -p ${DESTDIR}/tmp; \ mkdir -p ${DESTDIR}/tmp; \
@@ -14,7 +13,6 @@ install:
fi fi
@if [ ! -d ${DESTDIR}/usr/share/pm ]; then \ @if [ ! -d ${DESTDIR}/usr/share/pm ]; then \
mkdir -p ${DESTDIR}/usr/share/pm/{packages,repos}; \ mkdir -p ${DESTDIR}/usr/share/pm/{packages,repos}; \
# touch ${DESTDIR}/usr/share/pm/query; \
fi fi
@if [ ! -d ${DESTDIR}/var/cache/pm/pkg ]; then \ @if [ ! -d ${DESTDIR}/var/cache/pm/pkg ]; then \
mkdir -p ${DESTDIR}/var/cache/pm/pkg; \ mkdir -p ${DESTDIR}/var/cache/pm/pkg; \
@@ -51,4 +49,4 @@ clean:
fi fi
@if [ -f pm.pkg.gz ]; then \ @if [ -f pm.pkg.gz ]; then \
rm pm.pkg.gz; \ rm pm.pkg.gz; \
fi fi
+143 -135
View File
@@ -34,56 +34,40 @@ BGREEN="\033[1;32m"
#------------ check status function ------------ #------------ check status function ------------
check() { check() {
if [ $1 -ne 0 ]; then [ $1 -ne 0 ] \
printf "$BBLUE**$BWHITE $2 [$BRED ERROR $BWHITE]\n$RESET" && printf "$BBLUE**$BWHITE $2 [$BRED ERROR $BWHITE]\n$RESET" \
exit $1 && exit $1
fi
printf "$BBLUE**$BWHITE $2 [$BGREEN SUCCESS $BWHITE]\n$RESET" printf "$BBLUE**$BWHITE $2 [$BGREEN SUCCESS $BWHITE]\n$RESET"
} }
#----------------------------------------------- #-----------------------------------------------
#---------------- check root priveleges function ------------------------ #---------------- check root priveleges function ------------------------
checkroot() { checkroot() {
if [[ $(id -u) != 0 ]]; then [[ $(id -u) != 0 ]] \
printf "$BBLUE**$BWHITE You must be root [$BRED ERROR $BWHITE]\n$RESET" && printf "$BBLUE**$BWHITE You must be root [$BRED ERROR $BWHITE]\n$RESET" \
exit 1 && exit 1
fi
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# check non root priveleges function
checknonroot() {
[[ $(id -u) == 0 ]] \
&& printf "$BBLUE**$BWHITE You must be non root [$BRED ERROR $BWHITE]\n$RESET" \
&& exit 1
}
# ----------------------------------
#----------------- add(install) package function ------------------------ #----------------- add(install) package function ------------------------
add() { add() {
shift 1 shift 1
if [[ "$1" == "" ]]; then [[ "$1" == "" ]] \
help && help \
exit 0 && exit 0
fi
for i in $@; do for i in $@; do
case $i in down $i
add|a)
continue
;;
esac
done done
for i in $@; do for i in $@; do
case $i in unpack $cachedpkgdir/$i*.pkg.gz
add|a)
continue
;;
*)
down $i
;;
esac
done
for i in $@; do
case $i in
add|a)
continue
;;
*)
unpack $cachedpkgdir/$i.pkg.gz
;;
esac
done done
} }
a() { a() {
@@ -93,10 +77,9 @@ a() {
#-------------------- download package without install function --------- #-------------------- download package without install function ---------
down() { down() {
if [[ ! $1 ]]; then [[ ! $1 ]] \
help && help \
exit 0 && exit 0
fi
servers=$(/usr/bin/cat $repofile) servers=$(/usr/bin/cat $repofile)
check $? "Read repositories" check $? "Read repositories"
for i in $servers; do for i in $servers; do
@@ -104,24 +87,25 @@ down() {
serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///") serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///")
repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///') repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
for j in $repoquery; do for j in $repoquery; do
if [[ $j == $1 ]]; then # echo $(get_pkgname $j) $(get_pkgname $1)
if [ ! -f $cachedpkgdir/$1.pkg.gz ]; then if [[ "$(get_pkgname $j)" == "$1" ]]; then
if [ ! -f $cachedpkgdir/$j.pkg.gz ]; then
printf "$YELLOW**$RESET Downloading $YELLOW$serverdir: $Bwhite$j\n$RESET" printf "$YELLOW**$RESET Downloading $YELLOW$serverdir: $Bwhite$j\n$RESET"
echo $i/$1.pkg.gz echo $i/$j.pkg.gz
wget $i/$1.pkg.gz -P $cachedpkgdir wget $i/$j.pkg.gz -P $cachedpkgdir
check $? "Download package" check $? "Download package"
# if [[ "$?" == "0" ]]; then # if [[ "$?" == "0" ]]; then
# printf "$YELLOW**$GREEN successful downloaded $1\n$RESET" # printf "$YELLOW**$GREEN successful downloaded $1\n$RESET"
# return # return
# else # else
# printf "$YELLOW**$RED error:$RESET can't download package\n" # printf "$YELLOW**$RED error:$RESET can't download package\n"
# exit 1 # exit 1
# fi # fi
else else
printf "$YELLOW**$GREEN successful downloaded $1\n$RESET" printf "$YELLOW**$GREEN successful downloaded $1\n$RESET"
return return
fi fi
return return
fi fi
done done
done done
@@ -135,28 +119,32 @@ download() {
#-------------------- unpack local package archive ---------------------- #-------------------- unpack local package archive ----------------------
unpack() { unpack() {
[[ "$1" == "" ]] \
&& printf "$BBLUE**$BWHITE Specify package name [$BRED ERROR $BWHITE]\n$RESET" \
&& exit 1
packagename=$(echo $1 | sed -e "/.gz/s///") packagename=$(echo $1 | sed -e "/.gz/s///")
packagename=${packagename#*pkg/} packagename=${packagename#*pkg/}
printf "$YELLOW**$GREEN Installing ${packagename%.pkg*}\n$RESET" printf "$YELLOW**$GREEN Installing ${packagename%.pkg*}\n$RESET"
if [ ! -f $packagesqueryfile ]; then [ ! -f $packagesqueryfile ] \
printf "$BBLUE**$BWHITE Can't find $packagesqueryfile [$BRED ERROR $BWHITE]\n$RESET" && printf "$BBLUE**$BWHITE Can't find $packagesqueryfile [$BRED ERROR $BWHITE]\n$RESET" \
fi && exit 1
installed=false installed=false
for i in $(/usr/bin/cat $packagesqueryfile); do for i in $(/usr/bin/cat $packagesqueryfile); do
if [ "$i" = "${packagename%.pkg*}" ]; then [ "$i" = "${packagename%.pkg*}" ] \
export installed=true && export installed=true \
break && break
fi
done done
if [[ "$installed" == "true" ]]; then [[ "$installed" == "true" ]] \
printf "$YELLOW**$RESET Package already installed:$YELLOW reinstalling\n$RESET" && printf "$YELLOW**$RESET Package already installed:$YELLOW reinstalling\n$RESET"
fi
tar -xvf $1 -C $rootdir/tmp &> /dev/null tar -xvf $1 -C $rootdir/tmp &> /dev/null
cd $rootdir/tmp/$packagename cd $rootdir/tmp/$packagename
[ -f pre_install ] \
&& /usr/bin/sh -c ./pre_install \
&& rm -v pre_install &> /dev/null
if [ -f deps ]; then if [ -f deps ]; then
printf "$YELLOW**$GREEN Checking deps\n$RESET" printf "$YELLOW**$GREEN Checking deps\n$RESET"
deps=$(/usr/bin/cat deps) deps=$(/usr/bin/cat deps)
for dep in $deps; do for dep in $deps; do
have=false have=false
for pack in $(/usr/bin/cat $packagesqueryfile); do for pack in $(/usr/bin/cat $packagesqueryfile); do
if [ $pack = $dep ]; then if [ $pack = $dep ]; then
@@ -176,17 +164,18 @@ unpack() {
fi fi
mkdir $installedpackagesdir/$packagename &> /dev/null mkdir $installedpackagesdir/$packagename &> /dev/null
mv -v list $installedpackagesdir/$packagename &> /dev/null mv -v list $installedpackagesdir/$packagename &> /dev/null
[ -f pre_delete ] \
&& mv -v pre_delete $installedpackagesdir/$packagename &> /dev/null
[ -f post_delete ] \
&& mv -v post_delete $installedpackagesdir/$packagename &> /dev/null
cp -r ./* $rootdir/ cp -r ./* $rootdir/
if [ -f $rootdir/post_install ]; then [ -f $rootdir/post_install ] \
rm $rootdir/post_install && rm $rootdir/post_install
fi [ -f $rootdir/tmp/$packagename/post_install ] \
if [ -f $rootdir/tmp/$packagename/post_install ]; then && printf "$YELLOW**$GREEN post_install script ${packagename%.pkg*}\n$RESET" \
printf "$YELLOW**$GREEN post_install script ${packagename%.pkg*}\n$RESET" && /usr/bin/sh -c $rootdir/tmp/$packagename/post_install &> /dev/null
/usr/bin/sh -c $rootdir/tmp/$packagename/post_install &> /dev/null [[ "$installed" == "false" ]] \
fi && echo ${packagename%.pkg*} >> $packagesqueryfile
if [[ "$installed" == "false" ]]; then
echo ${packagename%.pkg*} >> $packagesqueryfile
fi
rm -rv $rootdir/tmp/$packagename &> /dev/null rm -rv $rootdir/tmp/$packagename &> /dev/null
printf "$YELLOW**$GREEN Installed ${packagename%.pkg*} successful\n$RESET" printf "$YELLOW**$GREEN Installed ${packagename%.pkg*} successful\n$RESET"
} }
@@ -201,24 +190,25 @@ del() {
shift 1 shift 1
for i in $@; do for i in $@; do
printf "$YELLOW**$GREEN deleting $i\n$RESET" printf "$YELLOW**$GREEN deleting $i\n$RESET"
if [ ! -f $installedpackagesdir/$i.pkg/list ]; then [ ! -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" \
exit 1 && exit 1
fi [ -f $installedpackagesdir/$i*.pkg/pre_delete ] \
for file in $(/usr/bin/cat $installedpackagesdir/$i.pkg/list); do && /usr/bin/sh -c $installedpackagesdir/$i*.pkg/pre_delete
for file in $(/usr/bin/cat $installedpackagesdir/$i*.pkg/list); do
rm -v $rootdir/$file rm -v $rootdir/$file
done done
# rm -v $rootdir/$(/usr/bin/cat $installedpackagesdir/$i.pkg/list) rm -rv $installedpackagesdir/$i*.pkg &> /dev/null
rm -rv $installedpackagesdir/$i.pkg &> /dev/null
packs=$(cat $packagesqueryfile) packs=$(cat $packagesqueryfile)
rm $packagesqueryfile rm $packagesqueryfile
for pack in $packs; do for pack in $packs; do
if [ "$pack" = "$i" ]; then if [ "$(get_pkgname $pack)" = "$i" ]; then
continue continue
fi fi
echo $pack >> $packagesqueryfile echo $pack >> $packagesqueryfile
done done
# sed -i "s/$i/d" $packagesqueryfile [ -f $installedpackagesdir/$i*.pkg/post_delete ] \
&& /usr/bin/sh -c $installedpackagesdir/$i*.pkg/post_delete
printf "$YELLOW**$GREEN delete $i successful\n$RESET" printf "$YELLOW**$GREEN delete $i successful\n$RESET"
done done
} }
@@ -231,18 +221,17 @@ d() {
list() { list() {
if [[ "$1" == "" ]]; then if [[ "$1" == "" ]]; 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) filelist=$(/usr/bin/cat $installedpackagesdir/$i*.pkg/list)
for j in $filelist; do for j in $filelist; do
printf "$YELLOW$i: $BWHITE$j$RESET\n" printf "$YELLOW$i: $BWHITE$j$RESET\n"
done done
done done
exit 0 exit 0
fi fi
if [[ "$(/usr/bin/cat $packagesqueryfile | grep $1)" == "" ]]; then [[ "$(/usr/bin/cat $packagesqueryfile | grep $1)" == "" ]] \
printf "$BBLUE**$BWHITE Package is not installed [$BRED ERROR $BWHITE]\n$RESET" && printf "$BBLUE**$BWHITE Package is not installed [$BRED ERROR $BWHITE]\n$RESET" \
exit 1 && exit 1
fi filelist=$(/usr/bin/cat $installedpackagesdir/$1*.pkg/list)
filelist=$(/usr/bin/cat $installedpackagesdir/$1.pkg/list)
for i in $filelist; do for i in $filelist; do
printf "$YELLOW$1: $BWHITE$i$RESET\n" printf "$YELLOW$1: $BWHITE$i$RESET\n"
done done
@@ -251,16 +240,30 @@ l() {
list $1 list $1
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
get_pkgrel() {
echo $(echo $1 | awk -F'-' '{ print $NF }')
}
get_pkgver() {
echo $(echo $1 | awk -F'-' '{ print $(NF-1) }')
}
get_pkgname() {
echo $( echo $(echo $1 | awk -F'-' '{ for (i=NF-2; i>=1; i--) print $i }') | awk -F' ' '{ if (NF==1) { print $NF } else { for (i=NF; i >= 1; i--) { if (i-1 >= 1) { printf $i "-" } else { printf $i } } } }')
}
printpkg() {
printf "$BWHITE$(get_pkgname $1) $BGREEN$(get_pkgver $1)-$(get_pkgrel $1)\n$RESET"
}
#------------------- show installed packages function ------------------- #------------------- show installed packages function -------------------
query() { query() {
packagesquery=$(/usr/bin/cat $packagesqueryfile) packagesquery=$(/usr/bin/cat $packagesqueryfile)
if [[ "$packagesquery" == "" ]]; then [[ "$packagesquery" == "" ]] \
printf "$YELLOW**$BWHITE No installed packages\n$RESET" && printf "$YELLOW**$BWHITE No installed packages\n$RESET" \
exit 0 && exit 0
fi
for i in $packagesquery; do for i in $packagesquery; do
printf "$BWHITE$i\n$RESET" printpkg $i
done done
} }
q() { q() {
@@ -283,18 +286,7 @@ help() {
clear - clear all package archives from cached packages directory clear - clear all package archives from cached packages directory
sync, s - synchronize repository sync, s - synchronize repository
deps [package name] - show package dependencies deps [package name] - show package dependencies
build - build package (./ must contain PMBUILD)
$YELLOW**$GREEN examples$RESET :
$BWHITE pm add dnsmasq
pm unpack ./dnsmasq.pkg.gz
pm down dnsmasq
pm search dnsmasq
pm help
pm clear
pm sync
pm del dnsmasq
pm list dnsmasq
pm query
\n$RESET" \n$RESET"
} }
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -325,7 +317,17 @@ search() {
serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///") serverdir=$(echo $serverdir | sed -e "/ftp:\/\//s///")
repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///') repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
for j in $repoquery; do for j in $repoquery; do
printf "$YELLOW$serverdir: $BWHITE$j\n$RESET" installed=false
for inst in $(/usr/bin/cat $packagesqueryfile); do
# echo $inst
[ "$(get_pkgname $inst)" = "$(get_pkgname $j)" ] \
&& export installed=true \
&& break
done
printf "$YELLOW$serverdir: $BWHITE$(get_pkgname $j) $BGREEN$(get_pkgver $j)-$(get_pkgrel $j) $RESET"
[[ "$installed" == "true" ]] \
&& printf "$BBLUE[installed]\n$RESET" \
|| echo ""
done done
done done
exit 0 exit 0
@@ -357,14 +359,12 @@ clear() {
#--- show package dependencies function --- #--- show package dependencies function ---
deps() { deps() {
if [ "$1" = "" ]; then [ "$1" = "" ] \
help && help \
exit 1 && exit 1
fi [ ! -f $installedpackagesdir/$1.pkg/deps ] \
if [ ! -f $installedpackagesdir/$1.pkg/deps ]; then && printf "$YELLOW**$BWHITE No deps\n$RESET" \
printf "$YELLOW**$BWHITE No deps\n$RESET" && exit 0
exit 0
fi
cat $installedpackagesdir/$1.pkg/deps cat $installedpackagesdir/$1.pkg/deps
} }
#------------------------------------------ #------------------------------------------
@@ -376,6 +376,7 @@ buildpkg() {
source $1 source $1
else else
printf "$BBLUE**$BWHITE Can't find PMBUILD [$BRED ERROR $BWHITE]\n$RESET" printf "$BBLUE**$BWHITE Can't find PMBUILD [$BRED ERROR $BWHITE]\n$RESET"
exit 1
fi fi
else else
source ./PMBUILD source ./PMBUILD
@@ -388,26 +389,25 @@ buildpkg() {
else else
[ -d pkg ] && rm -r pkg [ -d pkg ] && rm -r pkg
[ -d src ] && rm -r src [ -d src ] && rm -r src
[ -f $pkgname-$pkgver-$pkgrel.pkg.gz ] && rm -r $pkgname-$pkgver-$pkgrel.pkg.gz [ -f $pkgname-$pkgver-$pkgrel.pkg.gz ] \
&& rm -r $pkgname-$pkgver-$pkgrel.pkg.gz
fi fi
fi fi
[ ! -d src ] && mkdir -p src [ ! -d src ] && mkdir -p src
[ ! -d pkg/$pkgname-$pkgver-$pkgrel.pkg ] && mkdir -p pkg/$pkgname-$pkgver-$pkgrel.pkg [ ! -d pkg/$pkgname-$pkgver-$pkgrel.pkg ] \
&& mkdir -p pkg/$pkgname-$pkgver-$pkgrel.pkg
export pkgdir=$buildroot/pkg/$pkgname-$pkgver-$pkgrel.pkg export pkgdir=$buildroot/pkg/$pkgname-$pkgver-$pkgrel.pkg
if [ "$srcdir" = "" ]; then [ "$srcdir" = "" ] && export srcdir=$buildroot/src/$pkgname
export srcdir=$buildroot/src/$pkgname [ "$gitsource" != "" ] \
fi && printf "$BBLUE**$BWHITE Downloading sources\n$RESET" \
if [ "$gitsource" != "" ]; then && git clone $gitsource $srcdir \
printf "$BBLUE**$BWHITE Downloading sources\n$RESET" && check $? "Download sources"
git clone $gitsource $srcdir
check $? "Download sources"
fi
if [ "$source" != "" ]; then if [ "$source" != "" ]; then
printf "$BBLUE**$BWHITE Downloading sources\n$RESET" printf "$BBLUE**$BWHITE Downloading sources\n$RESET"
[ ! -d $srcdir ] && mkdir -p $srcdir [ ! -d $srcdir ] && mkdir -p $srcdir
cd $srcdir cd $srcdir
[ ! -f $pkgname-$pkgver.tar.* ] && wget $source [ ! -f $pkgname-$pkgver.tar.* ] && wget $source
cd - cd -
fi fi
if [[ $(type -t configure) = function ]]; then if [[ $(type -t configure) = function ]]; then
printf "$BBLUE**$BWHITE Configuring package\n$RESET" printf "$BBLUE**$BWHITE Configuring package\n$RESET"
@@ -457,20 +457,28 @@ buildpkg() {
#----------------------------------------------------- #-----------------------------------------------------
#--- main --- #--- main ---
case "$1" in main() {
add|a|del|d) case "$1" in
checkroot add|a|del|d)
"$1" $@ checkroot
;; "$1" $@
query|q|s|sync|clear|ss|search|list|l|unpack|u|down|download|deps) ;;
checkroot s|sync|clear|unpack|u|down|download)
"$1" $2 checkroot
;; "$1" $2
build) ;;
buildpkg $2 query|q|search|ss|list|l|deps)
;; "$1" $2
*) ;;
help build)
;; checknonroot
esac buildpkg $2
;;
*)
help
;;
esac
}
#------------ #------------
main $@