added check function and some fixes in display error
This commit is contained in:
1 parent
d1c5ba1e05
commit
ff282a0469
2 files changed
+53
-42
No files matched your search
@@ -11,7 +11,6 @@ install:
|
|||||||
fi
|
fi
|
||||||
if [ ! -d ${DESTDIR}/usr/bin ]; then \
|
if [ ! -d ${DESTDIR}/usr/bin ]; then \
|
||||||
mkdir -pv ${DESTDIR}/usr/bin; \
|
mkdir -pv ${DESTDIR}/usr/bin; \
|
||||||
cp -v src/pm ${DESTDIR}/usr/bin/pm; \
|
|
||||||
fi
|
fi
|
||||||
if [ ! -d ${DESTDIR}/usr/share/pm ]; then \
|
if [ ! -d ${DESTDIR}/usr/share/pm ]; then \
|
||||||
mkdir -pv ${DESTDIR}/usr/share/pm/{packages,repos}; \
|
mkdir -pv ${DESTDIR}/usr/share/pm/{packages,repos}; \
|
||||||
@@ -20,6 +19,7 @@ install:
|
|||||||
if [ ! -d ${DESTDIR}/var/cache/pm/pkg ]; then \
|
if [ ! -d ${DESTDIR}/var/cache/pm/pkg ]; then \
|
||||||
mkdir -pv ${DESTDIR}/var/cache/pm/pkg; \
|
mkdir -pv ${DESTDIR}/var/cache/pm/pkg; \
|
||||||
fi
|
fi
|
||||||
|
cp -v src/pm ${DESTDIR}/usr/bin/pm;
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
if [ -d ${DESTDIR}/etc/pm ]; then \
|
if [ -d ${DESTDIR}/etc/pm ]; then \
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
## ## ##
|
## ## ##
|
||||||
|
|
||||||
#---------------- variables --------------------------
|
#---------------- variables --------------------------
|
||||||
|
version="1.0.0"
|
||||||
export rootdir=/
|
export rootdir=/
|
||||||
repofile=$rootdir/etc/pm/repo
|
repofile=$rootdir/etc/pm/repo
|
||||||
packagesqueryfile=$rootdir/usr/share/pm/query
|
packagesqueryfile=$rootdir/usr/share/pm/query
|
||||||
@@ -27,8 +28,20 @@ RED="\033[0;31m"
|
|||||||
BRED="\033[1;31m"
|
BRED="\033[1;31m"
|
||||||
YELLOW="\033[1;33m"
|
YELLOW="\033[1;33m"
|
||||||
BWHITE="\033[1;37m"
|
BWHITE="\033[1;37m"
|
||||||
|
BBLUE="\033[1;34m"
|
||||||
|
BGREEN="\033[1;32m"
|
||||||
#--------------------
|
#--------------------
|
||||||
|
|
||||||
|
#------------ check status function ------------
|
||||||
|
check() {
|
||||||
|
if [ $1 -ne 0 ]; then
|
||||||
|
printf "$BBLUE**$BWHITE $2 [$BRED ERROR $RESET]\n$RESET"
|
||||||
|
exit $1
|
||||||
|
fi
|
||||||
|
printf "$BBLUE**$BWHITE $2 [$BGREEN SUCCESS $RESET]\n$RESET"
|
||||||
|
}
|
||||||
|
#-----------------------------------------------
|
||||||
|
|
||||||
#---------------- check root priveleges function ------------------------
|
#---------------- check root priveleges function ------------------------
|
||||||
checkroot() {
|
checkroot() {
|
||||||
if [[ $(id -u) != 0 ]]; then
|
if [[ $(id -u) != 0 ]]; then
|
||||||
@@ -65,6 +78,9 @@ add() {
|
|||||||
unpack $cachedpkgdir/$i.pkg.gz
|
unpack $cachedpkgdir/$i.pkg.gz
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
a() {
|
||||||
|
add $*
|
||||||
|
}
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
#-------------------- download package without install function ---------
|
#-------------------- download package without install function ---------
|
||||||
@@ -74,6 +90,7 @@ down() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
servers=$(/usr/bin/cat $repofile)
|
servers=$(/usr/bin/cat $repofile)
|
||||||
|
check $? "Read repositories"
|
||||||
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 $i | sed -e "/ftp:\/\//s///")
|
serverdir=$(echo $i | sed -e "/ftp:\/\//s///")
|
||||||
@@ -83,13 +100,14 @@ down() {
|
|||||||
if [ ! -f $cachedpkgdir/$1.pkg.gz ]; then
|
if [ ! -f $cachedpkgdir/$1.pkg.gz ]; then
|
||||||
printf "$YELLOW**$RESET Downloading $YELLOW$serverdir: $Bwhite$j\n$RESET"
|
printf "$YELLOW**$RESET Downloading $YELLOW$serverdir: $Bwhite$j\n$RESET"
|
||||||
wget $i/$1.pkg.gz -P $cachedpkgdir
|
wget $i/$1.pkg.gz -P $cachedpkgdir
|
||||||
if [[ "$?" == "0" ]]; then
|
check $? "Download package"
|
||||||
printf "$YELLOW**$GREEN successful downloaded $1\n$RESET"
|
# if [[ "$?" == "0" ]]; then
|
||||||
return
|
# printf "$YELLOW**$GREEN successful downloaded $1\n$RESET"
|
||||||
else
|
# return
|
||||||
printf "$YELLOW**$RED error:$RESET can't download package\n"
|
# else
|
||||||
exit 1
|
# printf "$YELLOW**$RED error:$RESET can't download package\n"
|
||||||
fi
|
# exit 1
|
||||||
|
# fi
|
||||||
else
|
else
|
||||||
printf "$YELLOW**$GREEN successful downloaded $1\n$RESET"
|
printf "$YELLOW**$GREEN successful downloaded $1\n$RESET"
|
||||||
return
|
return
|
||||||
@@ -98,9 +116,12 @@ down() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
printf "$YELLOW**$RED error:$RESET can't find package $1\n"
|
printf "$BBLUE**$BWHITE Can't find package $1 [$BRED ERROR $RESET]\n$RESET"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
download() {
|
||||||
|
down $1
|
||||||
|
}
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
#-------------------- unpack local package archive ----------------------
|
#-------------------- unpack local package archive ----------------------
|
||||||
@@ -108,7 +129,9 @@ unpack() {
|
|||||||
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 [[ "$(/usr/bin/cat $packagesqueryfile | grep ${packagename%.pkg*})" != "" ]]; then
|
installed=$(/usr/bin/cat $packagesqueryfile | grep ${packagename%.pkg*})
|
||||||
|
check $? "Read $packagesqueryfile"
|
||||||
|
if [[ "$installed" != "" ]]; then
|
||||||
printf "$YELLOW**$RESET Package already installed:$YELLOW reinstalling\n$RESET"
|
printf "$YELLOW**$RESET Package already installed:$YELLOW reinstalling\n$RESET"
|
||||||
fi
|
fi
|
||||||
tar -xvf $1 -C $rootdir/tmp &> /dev/null
|
tar -xvf $1 -C $rootdir/tmp &> /dev/null
|
||||||
@@ -119,8 +142,8 @@ unpack() {
|
|||||||
if [ -f $rootdir/post_install ]; then
|
if [ -f $rootdir/post_install ]; then
|
||||||
rm $rootdir/post_install
|
rm $rootdir/post_install
|
||||||
fi
|
fi
|
||||||
printf "$YELLOW**$GREEN post_install script ${packagename%.pkg*}\n$RESET"
|
|
||||||
if [ -f $rootdir/tmp/$packagename/post_install ]; then
|
if [ -f $rootdir/tmp/$packagename/post_install ]; then
|
||||||
|
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
|
||||||
fi
|
fi
|
||||||
if [[ "$(/usr/bin/cat $packagesqueryfile | grep ${packagename%.pkg*})" == "" ]]; then
|
if [[ "$(/usr/bin/cat $packagesqueryfile | grep ${packagename%.pkg*})" == "" ]]; then
|
||||||
@@ -129,6 +152,9 @@ unpack() {
|
|||||||
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"
|
||||||
}
|
}
|
||||||
|
u() {
|
||||||
|
unpack $1
|
||||||
|
}
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
#------------------ delete package function -----------------------------
|
#------------------ delete package function -----------------------------
|
||||||
@@ -140,8 +166,8 @@ del() {
|
|||||||
fi
|
fi
|
||||||
printf "$YELLOW**$GREEN deleting $i\n$RESET"
|
printf "$YELLOW**$GREEN deleting $i\n$RESET"
|
||||||
if [ ! -f $installedpackagesdir/$i.pkg/list ]; then
|
if [ ! -f $installedpackagesdir/$i.pkg/list ]; then
|
||||||
printf "$YELLOW**$BRED error:$RESET package not installed\n"
|
printf "$BBLUE**$BWHITE package not installed ($i) [$BRED ERROR $RESET]\n$RESET"
|
||||||
exit 0
|
exit 1
|
||||||
fi
|
fi
|
||||||
for file in $(/usr/bin/cat $installedpackagesdir/$i.pkg/list); do
|
for file in $(/usr/bin/cat $installedpackagesdir/$i.pkg/list); do
|
||||||
rm -v $rootdir/$file
|
rm -v $rootdir/$file
|
||||||
@@ -152,6 +178,9 @@ del() {
|
|||||||
printf "$YELLOW**$GREEN delete $i successful\n$RESET"
|
printf "$YELLOW**$GREEN delete $i successful\n$RESET"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
d() {
|
||||||
|
del $*
|
||||||
|
}
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
#------------------- list files in package function ---------------------
|
#------------------- list files in package function ---------------------
|
||||||
@@ -161,7 +190,7 @@ list() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
if [[ "$(/usr/bin/cat $packagesqueryfile | grep $1)" == "" ]]; then
|
if [[ "$(/usr/bin/cat $packagesqueryfile | grep $1)" == "" ]]; then
|
||||||
printf "$YELLOW**$BRED error:$RESET package is not installed\n"
|
printf "$BBLUE**$BWHITE Package is not installed [$BRED ERROR $RESET]\n$RESET"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
filelist=$(/usr/bin/cat $installedpackagesdir/$1.pkg/list)
|
filelist=$(/usr/bin/cat $installedpackagesdir/$1.pkg/list)
|
||||||
@@ -169,6 +198,9 @@ list() {
|
|||||||
printf "$YELLOW$1: $BWHITE$i$RESET\n"
|
printf "$YELLOW$1: $BWHITE$i$RESET\n"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
l() {
|
||||||
|
list $1
|
||||||
|
}
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
#------------------- show installed packages function -------------------
|
#------------------- show installed packages function -------------------
|
||||||
@@ -180,6 +212,9 @@ query() {
|
|||||||
fi
|
fi
|
||||||
printf "$packagesquery\n"
|
printf "$packagesquery\n"
|
||||||
}
|
}
|
||||||
|
q() {
|
||||||
|
query
|
||||||
|
}
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
#--------------------- show help function -------------------------------
|
#--------------------- show help function -------------------------------
|
||||||
@@ -259,35 +294,11 @@ clear() {
|
|||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
add|a|-a)
|
add|a|del|d)
|
||||||
add $*
|
"$1" $*
|
||||||
;;
|
;;
|
||||||
down|download)
|
query|q|help|sync|clear|search|list|l|unpack|u|down|download)
|
||||||
down $2
|
"$1" $2
|
||||||
;;
|
|
||||||
unpack|u|-u)
|
|
||||||
unpack $2
|
|
||||||
;;
|
|
||||||
del|d|-d)
|
|
||||||
del $*
|
|
||||||
;;
|
|
||||||
list|l|-l)
|
|
||||||
list $2
|
|
||||||
;;
|
|
||||||
query|q|-q)
|
|
||||||
query
|
|
||||||
;;
|
|
||||||
help)
|
|
||||||
help
|
|
||||||
;;
|
|
||||||
sync)
|
|
||||||
sync
|
|
||||||
;;
|
|
||||||
search)
|
|
||||||
search $2
|
|
||||||
;;
|
|
||||||
clear)
|
|
||||||
clear
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
help
|
help
|
||||||
|
|||||||
Reference in new issue
Block a user