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