updated fore functions
This commit is contained in:
@@ -11,9 +11,11 @@
|
||||
## ## ##
|
||||
## ## ##
|
||||
|
||||
set -e
|
||||
|
||||
#---------------- variables --------------------------
|
||||
version="1.0.0"
|
||||
export rootdir=/
|
||||
rootdir=/
|
||||
repofile=$rootdir/etc/pm/repo
|
||||
packagesqueryfile=$rootdir/usr/share/pm/query
|
||||
reposquerydir=$rootdir/usr/share/pm/repos
|
||||
@@ -22,32 +24,44 @@ installedpackagesdir=$rootdir/usr/share/pm/packages
|
||||
command=""
|
||||
packages=""
|
||||
archives=""
|
||||
destdir=""
|
||||
colors=y
|
||||
#-----------------------------------------------------
|
||||
|
||||
#----- colors -------
|
||||
RESET="\033[0m"
|
||||
GREEN="\033[0;32m"
|
||||
RED="\033[0;31m"
|
||||
BRED="\033[1;31m"
|
||||
YELLOW="\033[1;33m"
|
||||
BWHITE="\033[1;37m"
|
||||
BBLUE="\033[1;34m"
|
||||
BGREEN="\033[1;32m"
|
||||
RESET=""
|
||||
GREEN=""
|
||||
RED=""
|
||||
BRED=""
|
||||
YELLOW=""
|
||||
BWHITE=""
|
||||
BBLUE=""
|
||||
BGREEN=""
|
||||
if [ "$colors" = "y" ]; then
|
||||
RESET="\033[0m"
|
||||
GREEN="\033[0;32m"
|
||||
RED="\033[0;31m"
|
||||
BRED="\033[1;31m"
|
||||
YELLOW="\033[1;33m"
|
||||
BWHITE="\033[1;37m"
|
||||
BBLUE="\033[1;34m"
|
||||
BGREEN="\033[1;32m"
|
||||
fi
|
||||
#--------------------
|
||||
|
||||
#------------ check status function ------------
|
||||
check() {
|
||||
[ $1 -ne 0 ] \
|
||||
&& printf "$BBLUE**$BWHITE $2 [$BRED ERROR $BWHITE]\n$RESET" \
|
||||
&& printf "${BBLUE}**${BWHITE} $2 [${BRED} ERROR ${BWHITE}]\n${RESET}" \
|
||||
&& exit $1
|
||||
printf "$BBLUE**$BWHITE $2 [$BGREEN SUCCESS $BWHITE]\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} $2 [${BGREEN} SUCCESS ${BWHITE}]\n${RESET}"
|
||||
}
|
||||
#-----------------------------------------------
|
||||
|
||||
#---------------- check root priveleges function ------------------------
|
||||
checkroot() {
|
||||
[[ $(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
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
@@ -55,7 +69,7 @@ checkroot() {
|
||||
# check non root priveleges function
|
||||
checknonroot() {
|
||||
[[ $(id -u) == 0 ]] \
|
||||
&& printf "$BBLUE**$BWHITE You must be non root [$BRED ERROR $BWHITE]\n$RESET" \
|
||||
&& printf "${BBLUE}**${BWHITE} You must be non root [${BRED} ERROR ${BWHITE}]\n${RESET}" \
|
||||
&& exit 1
|
||||
}
|
||||
# ----------------------------------
|
||||
@@ -92,12 +106,12 @@ down() {
|
||||
for j in $repoquery; do
|
||||
if [[ "$(get_pkgname $j)" == "$k" ]]; 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/$j.pkg.gz
|
||||
wget $i/$j.pkg.gz -P $cachedpkgdir
|
||||
check $? "Download package"
|
||||
else
|
||||
printf "$YELLOW**$GREEN successful downloaded $k\n$RESET"
|
||||
printf "${YELLOW}**${GREEN} successful downloaded $k\n${RESET}"
|
||||
downloaded=y
|
||||
fi
|
||||
downloaded=y
|
||||
@@ -105,7 +119,7 @@ down() {
|
||||
done
|
||||
done
|
||||
if [ "$downloaded" == "n" ]; then
|
||||
printf "$BBLUE**$BWHITE Can't find package $k [$BRED ERROR $BWHITE]\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} Can't find package $k [${BRED} ERROR ${BWHITE}]\n${RESET}"
|
||||
fi
|
||||
continue
|
||||
done
|
||||
@@ -118,18 +132,18 @@ download() {
|
||||
#-------------------- unpack local package archive ----------------------
|
||||
unpack() {
|
||||
[[ "$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
|
||||
for i in $archives; do
|
||||
if [ ! -f $i ]; then
|
||||
printf "$BBLUE**$BWHITE File $i not found [$BRED ERROR $BWHITE]\n$RESET" \
|
||||
printf "${BBLUE}**${BWHITE} File $i not found [${BRED} ERROR ${BWHITE}]\n${RESET}" \
|
||||
&& exit 1
|
||||
fi
|
||||
packagename=$(echo $i | sed -e "/.gz/s///")
|
||||
packagename=${packagename#*pkg/}
|
||||
printf "$YELLOW**$GREEN Installing ${packagename%.pkg*}\n$RESET"
|
||||
printf "${YELLOW}**${GREEN} Installing ${packagename%.pkg*}\n${RESET}"
|
||||
[ ! -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}" \
|
||||
&& exit 1
|
||||
installed=false
|
||||
for i in $(/usr/bin/cat $packagesqueryfile); do
|
||||
@@ -138,14 +152,14 @@ unpack() {
|
||||
&& break
|
||||
done
|
||||
[[ "$installed" == "true" ]] \
|
||||
&& printf "$YELLOW**$RESET Package already installed:$YELLOW reinstalling\n$RESET"
|
||||
&& printf "${YELLOW}**${RESET} Package already installed:${YELLOW} reinstalling\n${RESET}"
|
||||
tar -xf $cachedpkgdir/$packagename.gz -C $rootdir/tmp
|
||||
cd $rootdir/tmp/$packagename
|
||||
[ -f pre_install ] \
|
||||
&& /usr/bin/sh -c ./pre_install \
|
||||
&& rm -v pre_install &> /dev/null
|
||||
if [ -f deps ]; then
|
||||
printf "$YELLOW**$GREEN Checking deps\n$RESET"
|
||||
printf "${YELLOW}**${GREEN} Checking deps\n${RESET}"
|
||||
deps=$(/usr/bin/cat deps)
|
||||
for dep in $deps; do
|
||||
have=false
|
||||
@@ -175,12 +189,12 @@ unpack() {
|
||||
[ -f $rootdir/post_install ] \
|
||||
&& rm $rootdir/post_install
|
||||
[ -f $rootdir/tmp/$packagename/post_install ] \
|
||||
&& 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
|
||||
[[ "$installed" == "false" ]] \
|
||||
&& echo ${packagename%.pkg*} >> $packagesqueryfile
|
||||
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}"
|
||||
cd - &> /dev/null
|
||||
done
|
||||
}
|
||||
@@ -191,11 +205,11 @@ u() {
|
||||
|
||||
#------------------ delete package function -----------------------------
|
||||
del() {
|
||||
printf "$YELLOW**$GREEN deleting\n$RESET"
|
||||
printf "${YELLOW}**${GREEN} deleting\n${RESET}"
|
||||
for i in $packages; do
|
||||
printf "$YELLOW**$GREEN deleting $i\n$RESET"
|
||||
printf "${YELLOW}**${GREEN} deleting $i\n${RESET}"
|
||||
[ ! -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
|
||||
[ -f $installedpackagesdir/$i*.pkg/pre_delete ] \
|
||||
&& /usr/bin/sh -c $installedpackagesdir/$i*.pkg/pre_delete
|
||||
@@ -213,7 +227,7 @@ del() {
|
||||
done
|
||||
[ -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
|
||||
}
|
||||
d() {
|
||||
@@ -229,12 +243,12 @@ list() {
|
||||
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"
|
||||
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"
|
||||
printf "${YELLOW}$(get_pkgname $pkgname) ${BGREEN}$(get_pkgver $pkgname)-$(get_pkgrel $pkgname): ${BWHITE}$j${RESET}\n"
|
||||
done
|
||||
unset pkgname
|
||||
done
|
||||
@@ -245,12 +259,12 @@ list() {
|
||||
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"
|
||||
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"
|
||||
printf "${YELLOW}$(get_pkgname $pkgname) ${BGREEN}$(get_pkgver $pkgname)-$(get_pkgrel $pkgname): ${BWHITE}$j${RESET}\n"
|
||||
done
|
||||
unset pkgname
|
||||
done
|
||||
@@ -259,27 +273,36 @@ l() {
|
||||
list
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
# print pkgrel function
|
||||
get_pkgrel() {
|
||||
echo $(echo $1 | awk -F'-' '{ print $NF }')
|
||||
}
|
||||
#------------------------
|
||||
|
||||
# print pkgver function
|
||||
get_pkgver() {
|
||||
echo $(echo $1 | awk -F'-' '{ print $(NF-1) }')
|
||||
}
|
||||
#------------------------
|
||||
|
||||
# print pkgname function
|
||||
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 } } } }')
|
||||
}
|
||||
#------------------------
|
||||
|
||||
# print package information function
|
||||
printpkg() {
|
||||
printf "$BWHITE$(get_pkgname $1) $BGREEN$(get_pkgver $1)-$(get_pkgrel $1)\n$RESET"
|
||||
printf "${BWHITE}$(get_pkgname $1) ${BGREEN}$(get_pkgver $1)-$(get_pkgrel $1)\n${RESET}"
|
||||
}
|
||||
#-------------------------------------
|
||||
|
||||
#------------------- show installed packages function -------------------
|
||||
query() {
|
||||
packagesquery=$(/usr/bin/cat $packagesqueryfile)
|
||||
[[ "$packagesquery" == "" ]] \
|
||||
&& printf "$YELLOW**$BWHITE No installed packages\n$RESET" \
|
||||
&& printf "${YELLOW}**${BWHITE} No installed packages\n${RESET}" \
|
||||
&& exit 0
|
||||
for i in $packagesquery; do
|
||||
printpkg $i
|
||||
@@ -293,22 +316,30 @@ q() {
|
||||
#--------------------- show help function -------------------------------
|
||||
help() {
|
||||
printf "
|
||||
$YELLOW**$GREEN pm usage$RESET:
|
||||
${BWHITE}add, a [package name] - download and install from repository
|
||||
unpack, u [/path/to/package/archive] - unpack(install) from local package archive
|
||||
down, download [package name] - download package from repository without install
|
||||
up, upgrade - upgrade packages
|
||||
del, d [package name] - delete package
|
||||
list, l [package name] - list files in package
|
||||
search, ss [package name] - search package in repository
|
||||
query, q - show installed packages
|
||||
help - this help message
|
||||
clear, c - clear all package archives from cached packages directory
|
||||
sync, s - synchronize repository
|
||||
deps [package name] - show package dependencies
|
||||
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"
|
||||
${YELLOW}**${GREEN} pm usage${RESET}:
|
||||
${BWHITE}pm <options> <command> [<package name>]
|
||||
|
||||
${YELLOW}Commands:${BWHITE}
|
||||
${BGREEN}add, a, -a, --add [package name]${BWHITE} - download and install from repository
|
||||
${BGREEN}unpack, u, -u, --unpack [/path/to/package/archive]${BWHITE} - unpack(install) from local package archive
|
||||
${BGREEN}down, download, --download [package name]${BWHITE} - download package from repository without install
|
||||
${BGREEN}up, upgrade, -U, --upgrade${BWHITE} - upgrade packages
|
||||
${BGREEN}del, d, -d, --delete, --del [package name]${BWHITE} - delete package
|
||||
${BGREEN}list, l, -L, --list [package name]${BWHITE} - list files in package
|
||||
${BGREEN}search, ss, -s, --search, --ss [package name]${BWHITE} - search package in repository
|
||||
${BGREEN}query, q, -q, --query${BWHITE} - show installed packages
|
||||
${BGREEN}help, -h, --help${BWHITE} - this help message
|
||||
${BGREEN}clear, c, -c, --clear${BWHITE} - clear all package archives from cached packages directory
|
||||
${BGREEN}sync, s, -S, --sync${BWHITE} - synchronize repository
|
||||
${BGREEN}deps, -D, --deps [package name]${BWHITE} - show package dependencies
|
||||
${BGREEN}build${BWHITE} - build package (./ must contain PMBUILD)
|
||||
${BGREEN}index, i, -i, --index${BWHITE} - scan directory with packages and print packages in terminal (to create repository query use pm index > query)
|
||||
${BGREEN}cache, cs, -C, --cache${BWHITE} - show cache size
|
||||
${BGREEN}v, version, -v, --version${BWHITE} - show version
|
||||
|
||||
${YELLOW}Options:${BWHITE}
|
||||
${BGREEN}-r, --rootdir${BWHITE} - set root directory for package manager
|
||||
${RESET}"
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
@@ -316,7 +347,7 @@ $RESET"
|
||||
sync() {
|
||||
servers=$(/usr/bin/cat $repofile)
|
||||
for i in $servers; do
|
||||
printf "$YELLOW**$GREEN Sync $BWHITE$i\n$RESET"
|
||||
printf "${YELLOW}**${GREEN} Sync ${BWHITE}$i\n${RESET}"
|
||||
serverdir=$(echo $i | sed -e "/http:\//s///")
|
||||
serverdir=$(echo $serverdir | sed -e "/ftp:\//s///")
|
||||
mkdir -p $reposquerydir/$serverdir &> /dev/null
|
||||
@@ -346,9 +377,9 @@ search() {
|
||||
&& export installed=true \
|
||||
&& break
|
||||
done
|
||||
printf "$YELLOW$serverdir: $BWHITE$(get_pkgname $j) $BGREEN$(get_pkgver $j)-$(get_pkgrel $j) $RESET"
|
||||
printf "${YELLOW}$serverdir: ${BWHITE}$(get_pkgname $j) ${BGREEN}$(get_pkgver $j)-$(get_pkgrel $j) ${RESET}"
|
||||
[[ "$installed" == "true" ]] \
|
||||
&& printf "$BBLUE[installed]\n$RESET" \
|
||||
&& printf "${BBLUE}[installed]\n${RESET}" \
|
||||
|| echo ""
|
||||
done
|
||||
done
|
||||
@@ -362,12 +393,12 @@ search() {
|
||||
repoquery=$(/usr/bin/cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
|
||||
for j in $repoquery; do
|
||||
if [[ $j =~ $k ]]; then
|
||||
printf "$YELLOW$serverdir: $BWHITE$j\n$RESET"
|
||||
printf "${YELLOW}$serverdir: ${BWHITE}$j\n${RESET}"
|
||||
found=true
|
||||
fi
|
||||
done
|
||||
done
|
||||
[ "$found" = "false" ] && printf "$YELLOW**$RED error:$RESET can't find package ($k)\n"
|
||||
[ "$found" = "false" ] && printf "${YELLOW}**${RED} error:${RESET} can't find package ($k)\n"
|
||||
done
|
||||
}
|
||||
ss() {
|
||||
@@ -377,7 +408,9 @@ ss() {
|
||||
|
||||
#------------------- clear cached packages directory --------------------
|
||||
clear() {
|
||||
rm -v $cachedpkgdir/*
|
||||
printf "${YELLOW}**${BWHITE} clearing cached packages directory "
|
||||
rm -rf $cachedpkgdir/*
|
||||
printf "[${GREEN} OK${BWHITE} ]\n${RESET}"
|
||||
}
|
||||
clean() {
|
||||
clear
|
||||
@@ -394,9 +427,9 @@ deps() {
|
||||
cd $installedpackagesdir
|
||||
pkgname=$(echo $(find . -name "$i*") | sed -e "/.\//s///" | sed -e "/.pkg/s///")
|
||||
cd - &>/dev/null
|
||||
printf "$YELLOW$(get_pkgname $pkgname) $BGREEN$(get_pkgver $pkgname)-$(get_pkgrel $pkgname)$BWHITE deps: \n$RESET"
|
||||
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" \
|
||||
&& printf "\t${YELLOW}**${BWHITE} No deps\n${RESET}" \
|
||||
&& continue
|
||||
for j in $(cat $installedpackagesdir/${pkgname}.pkg/deps); do
|
||||
printf "\t"
|
||||
@@ -411,12 +444,12 @@ deps() {
|
||||
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"
|
||||
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"
|
||||
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" \
|
||||
&& printf "\t${YELLOW}**${BWHITE} No deps\n${RESET}" \
|
||||
&& continue
|
||||
for j in $(cat $installedpackagesdir/${pkgname}.pkg/deps); do
|
||||
printf "\t"
|
||||
@@ -433,7 +466,7 @@ buildpkg() {
|
||||
if [ "$1" != "" ]; then
|
||||
source $1
|
||||
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
|
||||
else
|
||||
@@ -442,7 +475,7 @@ buildpkg() {
|
||||
export buildroot=$(pwd)
|
||||
if [ -f $buildroot/$pkgname-$pkgver-$pkgrel.pkg.gz ]; then
|
||||
if [ "$1" != "-r" ]; then
|
||||
printf "$BBLUE**$BWHITE $pkgname-$pkgver-$pkgrel.pkg.gz already exists please use -r to rebuild [$YELLOW WARNING $BWHITE]\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} $pkgname-$pkgver-$pkgrel.pkg.gz already exists please use -r to rebuild [${YELLOW} WARNING ${BWHITE}]\n${RESET}"
|
||||
exit 0
|
||||
else
|
||||
[ -d pkg ] && rm -rf pkg
|
||||
@@ -457,36 +490,36 @@ buildpkg() {
|
||||
export pkgdir=$buildroot/pkg/$pkgname-$pkgver-$pkgrel.pkg
|
||||
[ "$srcdir" = "" ] && export srcdir=$buildroot/src/$pkgname
|
||||
[ "$gitsource" != "" ] \
|
||||
&& printf "$BBLUE**$BWHITE Downloading sources\n$RESET" \
|
||||
&& printf "${BBLUE}**${BWHITE} Downloading sources\n${RESET}" \
|
||||
&& git clone $gitsource $srcdir \
|
||||
&& check $? "Download sources"
|
||||
if [ "$source" != "" ]; then
|
||||
printf "$BBLUE**$BWHITE Downloading sources\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} Downloading sources\n${RESET}"
|
||||
[ ! -d $srcdir ] && mkdir -p $srcdir
|
||||
cd $srcdir
|
||||
[ ! -f $pkgname-$pkgver.tar.* ] && wget $source
|
||||
cd -
|
||||
fi
|
||||
if [[ $(type -t configure) = function ]]; then
|
||||
printf "$BBLUE**$BWHITE Configuring package\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} Configuring package\n${RESET}"
|
||||
configure
|
||||
check $? "Configure"
|
||||
fi
|
||||
if [[ $(type -t build) = function ]]; then
|
||||
printf "$BBLUE**$BWHITE Building package\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} Building package\n${RESET}"
|
||||
build
|
||||
check $? "Build"
|
||||
else
|
||||
echo "no build"
|
||||
fi
|
||||
if [[ $(type -t package) == function ]]; then
|
||||
printf "$BBLUE**$BWHITE Packaging package\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} Packaging package\n${RESET}"
|
||||
package
|
||||
check $? "Package"
|
||||
else
|
||||
echo "no package"
|
||||
fi
|
||||
printf "$BBLUE**$BWHITE Stripping unneded symbols\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} Stripping unneded symbols\n${RESET}"
|
||||
STRIP=$(which strip)
|
||||
if [ -n "$CROSS_COMPILE" ]; then
|
||||
STRIP=$CROSS_COMPILE-strip
|
||||
@@ -494,7 +527,7 @@ buildpkg() {
|
||||
for execfile in $(find $pkgdir -executable -type f); do
|
||||
$STRIP $execfile
|
||||
done
|
||||
printf "$BBLUE**$BWHITE Strip unneded symbols [$BGREEN SUCCESS $BWHITE]\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} Strip unneded symbols [${BGREEN} SUCCESS ${BWHITE}]\n${RESET}"
|
||||
cd $pkgdir
|
||||
find -type f > $buildroot/list
|
||||
find -type l >> $buildroot/list
|
||||
@@ -510,7 +543,7 @@ buildpkg() {
|
||||
done
|
||||
fi
|
||||
cd $pkgdir
|
||||
printf "$BBLUE**$BWHITE Archiving package\n$RESET"
|
||||
printf "${BBLUE}**${BWHITE} Archiving package\n${RESET}"
|
||||
tar -czf $buildroot/$pkgname-$pkgver-$pkgrel.pkg.gz .. &> /dev/null
|
||||
check $? "Archive package"
|
||||
cd $buildroot
|
||||
@@ -528,7 +561,7 @@ upgrade() {
|
||||
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"
|
||||
printf "${BGREEN}from: $(printf $repo | sed 's/://g')\n${RESET}"
|
||||
total_updates=$((total_updates+1))
|
||||
continue
|
||||
fi
|
||||
@@ -537,18 +570,19 @@ upgrade() {
|
||||
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"
|
||||
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"
|
||||
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() {
|
||||
@@ -559,6 +593,62 @@ i() {
|
||||
}
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
# calculate cache size function
|
||||
cachesize() {
|
||||
printf "${YELLOW}Cache size: ${BWHITE}$(du -sh $cachedpkgdir | awk '{print $1}')\n${RESET}"
|
||||
}
|
||||
cs() {
|
||||
cachesize
|
||||
}
|
||||
#------------------------------
|
||||
|
||||
# print version function
|
||||
version() {
|
||||
printf "
|
||||
${BWHITE}########## #### ####
|
||||
${BWHITE}########## #### ####
|
||||
${BWHITE}## ## ## ## ## ##
|
||||
${BWHITE}## ## ## ## ## ##
|
||||
${BWHITE}########## ## ## ## - ${BGREEN}PACKAGE MANAGER FOR SIMPLE LINUX
|
||||
${BWHITE}########## ## ## ## - ${BGREEN}AUTHOR ${BWHITE}-- TOLA MIRONCENKO
|
||||
${BWHITE}## ## ## - ${BGREEN}VERSION ${BWHITE}-- ${version}
|
||||
${BWHITE}## ## ##
|
||||
${BWHITE}## ## ##
|
||||
${BWHITE}## ## ##
|
||||
${RESET}"
|
||||
}
|
||||
v() {
|
||||
version
|
||||
}
|
||||
#------------------------------
|
||||
|
||||
# install pm to some rootfs directory function
|
||||
selfinstall() {
|
||||
[ -z "$destdir" ] && destdir="rootfs"
|
||||
printf "${BGREEN}Installing pm to ${BWHITE}$destdir ${BGREEN}directory\n${RESET}"
|
||||
printf "${YELLOW}Creating directories... ${RESET}"
|
||||
[ ! -d $destdir ] && mkdir -p $destdir
|
||||
[ ! -d $destdir/etc/pm ] && mkdir -p $destdir/etc/pm
|
||||
[ ! -d $destdir/tmp ] && mkdir -p $destdir/tmp
|
||||
[ ! -d $destdir/usr/bin ] && mkdir -p $destdir/usr/bin
|
||||
[ ! -d $destdir/usr/share/pm ] && mkdir -p $destdir/usr/share/pm
|
||||
[ ! -d $destdir/usr/share/pm/packages ] && mkdir -p $destdir/usr/share/pm/packages
|
||||
[ ! -d $destdir/usr/share/pm/repos ] && mkdir -p $destdir/usr/share/pm/repos
|
||||
[ ! -d $destdir/var/cache/pm/pkg ] && mkdir -p $destdir/var/cache/pm/pkg
|
||||
printf "${BWHITE}[ ${BGREEN}OK ${BWHITE}]${RESET}\n"
|
||||
printf "${YELLOW}Creating files... ${RESET}"
|
||||
[ ! -f $destdir/etc/pm/repo ] && touch $destdir/etc/pm/repo
|
||||
[ ! -f $destdir/usr/share/pm/query ] && touch $destdir/usr/share/pm/query
|
||||
[ ! -f $destdir/usr/bin/pm ] && cp $rootdir/usr/bin/pm $destdir/usr/bin/pm
|
||||
printf "${BWHITE}[ ${BGREEN}OK ${BWHITE}]${RESET}\n"
|
||||
printf "${BGREEN}Installation completed successfully.${RESET}\n"
|
||||
}
|
||||
si() {
|
||||
selfinstall
|
||||
}
|
||||
#--------------------------------------------
|
||||
|
||||
# parse command function
|
||||
parse_command() {
|
||||
while [ $1 ]; do
|
||||
case "$1" in
|
||||
@@ -574,21 +664,26 @@ parse_command() {
|
||||
packages=$@
|
||||
break;
|
||||
;;
|
||||
unpack|u|up|upgrade|i|index)
|
||||
unpack|u|up|upgrade|i|index|v|version)
|
||||
command=$1
|
||||
shift
|
||||
archives=$@
|
||||
break;
|
||||
;;
|
||||
query|q|search|ss|list|l|deps)
|
||||
query|q|search|ss|list|l|deps|cachesize|cs)
|
||||
command=$1
|
||||
shift
|
||||
packages=$@
|
||||
break
|
||||
;;
|
||||
selfinstall|si)
|
||||
command=$1
|
||||
shift
|
||||
;;
|
||||
build)
|
||||
checknonroot
|
||||
buildpkg $@
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
@@ -596,6 +691,9 @@ parse_command() {
|
||||
esac
|
||||
done
|
||||
}
|
||||
#---------------------------
|
||||
|
||||
# parse options function
|
||||
parse_opts() {
|
||||
while [ $1 ]; do
|
||||
case "$1" in
|
||||
@@ -607,8 +705,79 @@ parse_opts() {
|
||||
rootdir=$2
|
||||
shift 2
|
||||
;;
|
||||
-q|--query)
|
||||
command=query
|
||||
shift
|
||||
;;
|
||||
-S|--sync)
|
||||
command=sync
|
||||
shift
|
||||
;;
|
||||
-C|--cache)
|
||||
command=cachesize
|
||||
shift
|
||||
;;
|
||||
-c|--clear)
|
||||
command=clear
|
||||
shift
|
||||
;;
|
||||
-i|--index)
|
||||
command=index
|
||||
shift
|
||||
;;
|
||||
-D|--deps)
|
||||
command=deps
|
||||
shift
|
||||
packages=$@
|
||||
;;
|
||||
-L|--list)
|
||||
command=list
|
||||
shift
|
||||
packages=$@
|
||||
;;
|
||||
-a|--add)
|
||||
command=add
|
||||
shift
|
||||
packages=$@
|
||||
;;
|
||||
-u|--unpack)
|
||||
command=unpack
|
||||
shift
|
||||
archives=$@
|
||||
;;
|
||||
--download)
|
||||
command=download
|
||||
shift
|
||||
packages=$@
|
||||
;;
|
||||
-d|--delete|--del)
|
||||
command=del
|
||||
shift
|
||||
packages=$@
|
||||
;;
|
||||
-U|--upgrade)
|
||||
command=upgrade
|
||||
shift
|
||||
;;
|
||||
-s|--search|--ss)
|
||||
command=search
|
||||
shift
|
||||
packages=$@
|
||||
;;
|
||||
-v|--version)
|
||||
command=version
|
||||
shift
|
||||
;;
|
||||
--si|--selfinstall)
|
||||
command=selfinstall
|
||||
shift
|
||||
;;
|
||||
--dest)
|
||||
destdir=$2
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
if [ "${1#--}" != "$1" ]; then
|
||||
if [ "${1#--}" != "$1" ] || [ "${1#-}" != "$1" ]; then
|
||||
echo "Invalid option: $1" >&2
|
||||
help
|
||||
exit 1
|
||||
@@ -618,6 +787,7 @@ parse_opts() {
|
||||
esac
|
||||
done
|
||||
}
|
||||
#---------------------------
|
||||
|
||||
#--- main ---
|
||||
main() {
|
||||
|
||||
Reference in New Issue
Block a user