initial commit
This commit is contained in:
Executable
+281
@@ -0,0 +1,281 @@
|
||||
#!/bin/sh
|
||||
|
||||
########## #### ####
|
||||
########## #### ####
|
||||
## ## ## ## ## ##
|
||||
## ## ## ## ## ##
|
||||
########## ## ## ## - PACKAGE MANAGER FOR SIMPLE LINUX
|
||||
########## ## ## ## - AUTHOR -- TOLA MIRONCENKO
|
||||
## ## ##
|
||||
## ## ##
|
||||
## ## ##
|
||||
## ## ##
|
||||
|
||||
#----- colors -------
|
||||
. /usr/lib/init/colors.sh
|
||||
#--------------------
|
||||
|
||||
#---------------- variables --------------------------
|
||||
rootdir=/
|
||||
repofile=$rootdir/etc/pm/repo
|
||||
packagesqueryfile=$rootdir/usr/share/pm/query
|
||||
reposquerydir=$rootdir/usr/share/pm/repos
|
||||
cachedpkgdir=$rootdir/var/cache/pm/pkg
|
||||
installedpackagesdir=$rootdir/usr/share/pm/packages
|
||||
#-----------------------------------------------------
|
||||
|
||||
#---------------- check root priveleges function ------------------------
|
||||
checkroot() {
|
||||
if [[ $(id -u) != 0 ]]; then
|
||||
printf "$YELLOW**$BRED error:$RESET you must be root\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
checkroot
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#----------------- add(install) package function ------------------------
|
||||
add() {
|
||||
if [[ "$1" == "" ]]; then
|
||||
help
|
||||
exit 0
|
||||
fi
|
||||
for i in $*; do
|
||||
if [[ "$i" == "add" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
done
|
||||
for i in $*; do
|
||||
if [[ "$i" == "add" ]]; then
|
||||
continue
|
||||
fi
|
||||
down $i
|
||||
done
|
||||
for i in $*; do
|
||||
if [[ "$i" == "add" ]]; then
|
||||
continue
|
||||
fi
|
||||
unpack $cachedpkgdir/$i.pkg.gz
|
||||
done
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#-------------------- download package without install function ---------
|
||||
down() {
|
||||
if [[ ! $1 ]]; then
|
||||
help
|
||||
exit 0
|
||||
fi
|
||||
servers=$(cat $repofile)
|
||||
for i in $servers; do
|
||||
serverdir=$(echo $i | sed -e "/http:\/\//s///")
|
||||
repoquery=$(cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
|
||||
for j in $repoquery; do
|
||||
if [[ $j == $1 ]]; then
|
||||
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
|
||||
else
|
||||
printf "$YELLOW**$GREEN successful downloaded $1\n$RESET"
|
||||
return
|
||||
fi
|
||||
# exit 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
printf "$YELLOW**$RED error:$RESET can't find package $1\n"
|
||||
exit 1
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#-------------------- unpack local package archive ----------------------
|
||||
unpack() {
|
||||
packagename=$(echo $1 | sed -e "/.gz/s///")
|
||||
packagename=${packagename#*pkg/}
|
||||
printf "$YELLOW**$GREEN Installing ${packagename%.pkg*}\n$RESET"
|
||||
if [[ "$(cat $packagesqueryfile | grep ${packagename%.pkg*})" != "" ]]; then
|
||||
printf "$YELLOW**$RESET Package already installed:$YELLOW reinstalling\n"
|
||||
fi
|
||||
tar -xvf $1 -C $rootdir/tmp &> /dev/null
|
||||
cd $rootdir/tmp/$packagename
|
||||
mkdir $installedpackagesdir/$packagename &> /dev/null
|
||||
mv -v list $installedpackagesdir/$packagename &> /dev/null
|
||||
cp -rv ./* $rootdir &> /dev/null
|
||||
if [ -f $rootdir/tmp/$packagename/post_install ]; then
|
||||
sh -c $rootdir/tmp/$packagename/post_install
|
||||
fi
|
||||
if [[ "$(cat $packagesqueryfile | grep ${packagename%.pkg*})" == "" ]]; then
|
||||
echo ${packagename%.pkg*} >> $packagesqueryfile
|
||||
fi
|
||||
rm -rv $rootdir/tmp/$packagename &> /dev/null
|
||||
printf "$YELLOW**$GREEN Installed ${packagename%.pkg*} successful\n$RESET"
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#------------------ delete package function -----------------------------
|
||||
del() {
|
||||
printf "$YELLOW**$GREEN deleting\n$RESET"
|
||||
for i in $*; do
|
||||
if [[ "$i" == "del" ]]; then
|
||||
continue
|
||||
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
|
||||
fi
|
||||
rm -v $rootdir/$(cat $installedpackagesdir/$i.pkg/list) &> /dev/null
|
||||
rm -rv $installedpackagesdir/$i.pkg &> /dev/null
|
||||
sed -i "/$i/d" $packagesqueryfile
|
||||
printf "$YELLOW**$GREEN delete $i successful\n$RESET"
|
||||
done
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#------------------- list files in package function ---------------------
|
||||
list() {
|
||||
if [[ "$1" == "" ]]; then
|
||||
help
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$(cat $packagesqueryfile | grep $1)" == "" ]]; then
|
||||
printf "$YELLOW**$BRED error:$RESET package is not installed\n"
|
||||
exit 1
|
||||
fi
|
||||
filelist=$(cat $installedpackagesdir/$1.pkg/list)
|
||||
for i in $filelist; do
|
||||
printf "$YELLOW$1: $BWHITE$i$RESET\n"
|
||||
done
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#------------------- show installed packages function -------------------
|
||||
query() {
|
||||
packagesquery=$(cat $packagesqueryfile)
|
||||
if [[ "$packagesquery" == "" ]]; then
|
||||
printf "$YELLOW**$BWHITE No installed packages\n"
|
||||
exit 0
|
||||
fi
|
||||
printf "$packagesquery\n"
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#--------------------- show help function -------------------------------
|
||||
help() {
|
||||
printf "
|
||||
$YELLOW**$GREEN pm usage$RESET :
|
||||
$BWHITE pm add [package name] - download and install from repository
|
||||
pm unpack [/path/to/package/archive] - unpack(install) from local package archive
|
||||
pm down [package name] - download package from repository without install
|
||||
pm del [package name] - delete package
|
||||
pm list [package name] - list files in package
|
||||
pm search [package name] - search package in repository
|
||||
pm query - show installed packages
|
||||
pm help - this help message
|
||||
pm clear - clear all package archives from cached packages directory
|
||||
pm sync - synchronize repository
|
||||
|
||||
$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"
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#------------------- sync repo function ---------------------------------
|
||||
sync() {
|
||||
servers=$(cat $repofile)
|
||||
for i in $servers; do
|
||||
serverdir=$(echo $i | sed -e "/http:\//s///")
|
||||
mkdir $reposquerydir/$serverdir &> /dev/null
|
||||
wget $i/query -O $reposquerydir/$serverdir/query &> /dev/null
|
||||
done
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#----------------- search package in repo function ----------------------
|
||||
search() {
|
||||
servers=$(cat $repofile)
|
||||
if [[ ! $1 ]]; then
|
||||
for i in $servers; do
|
||||
serverdir=$(echo $i | sed -e "/http:\/\//s///")
|
||||
repoquery=$(cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
|
||||
for j in $repoquery; do
|
||||
printf "$YELLOW$serverdir: $BWHITE$j\n$RESET"
|
||||
done
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for i in $servers; do
|
||||
serverdir=$(echo $i | sed -e "/http:\/\//s///")
|
||||
repoquery=$(cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///')
|
||||
for j in $repoquery; do
|
||||
if [[ $j == $1 ]]; then
|
||||
printf "$YELLOW$serverdir: $BWHITE$j\n$RESET"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
printf "$YELLOW**$RED error:$RESET can't find package ($1)\n"
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#------------------- clear cached packages directory --------------------
|
||||
clear() {
|
||||
rm -v $cachedpkgdir/*
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
case "$1" in
|
||||
add)
|
||||
add $*
|
||||
;;
|
||||
down)
|
||||
down $2
|
||||
;;
|
||||
unpack)
|
||||
unpack $2
|
||||
;;
|
||||
del)
|
||||
del $*
|
||||
;;
|
||||
list)
|
||||
list $2
|
||||
;;
|
||||
query)
|
||||
query
|
||||
;;
|
||||
help)
|
||||
help
|
||||
;;
|
||||
sync)
|
||||
sync
|
||||
;;
|
||||
search)
|
||||
search $2
|
||||
;;
|
||||
clear)
|
||||
clear
|
||||
;;
|
||||
*)
|
||||
help
|
||||
;;
|
||||
esac
|
||||
Executable
+168
@@ -0,0 +1,168 @@
|
||||
#!/bin/sh
|
||||
|
||||
########## ##########
|
||||
########## ##########
|
||||
## ## ##
|
||||
## ##
|
||||
## ## - RC BOOT SCRIPTS MANAGER FOR SIMPLE LINUX
|
||||
## ## - AUTHOR -- TOLA MIRONCENKO
|
||||
## ##
|
||||
## ##
|
||||
## ##########
|
||||
## ##########
|
||||
|
||||
rootdir=$(pwd)
|
||||
|
||||
#----- colors -------
|
||||
. $rootdir/usr/lib/init/colors.sh
|
||||
#--------------------
|
||||
|
||||
#------------------------ add to boot function --------------
|
||||
add() {
|
||||
resultlink=$(cat $rootdir/usr/share/rc/orders | grep $1)
|
||||
if [ -f $rootdir/usr/lib/init/services/$1.service ] && [ $resultlink ]; then
|
||||
cd $rootdir/etc/rc.d
|
||||
ln -sv $rootdir/usr/lib/init/services/$1.service "$resultlink" &> /dev/null
|
||||
printf "$BLUE**$GREEN SUCCESS:$BWHITE added $1 to init.\n$RESET"
|
||||
else
|
||||
help
|
||||
fi
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
#--------------------- del from boot function ---------------
|
||||
del() {
|
||||
filetoremove=$(find $rootdir/etc/rc.d/ | grep $1 )
|
||||
if [ $filetoremove ]; then
|
||||
rm -v $filetoremove &> /dev/null
|
||||
printf "$BLUE**$GREEN SUCCESS:$BWHITE removed $1 from init.\n$RESET"
|
||||
else
|
||||
help
|
||||
fi
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
#---------------------- start daemon function ---------------
|
||||
start() {
|
||||
if [ -f $rootdir/etc/init.d/$1 ]; then
|
||||
$rootdir/etc/init.d/$1 start
|
||||
else
|
||||
help
|
||||
fi
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
#---------------- stop daemon function ----------------------
|
||||
stop() {
|
||||
if [ -f $rootdir/etc/init.d/$1 ]; then
|
||||
$rootdir/etc/init.d/$1 stop
|
||||
else
|
||||
help
|
||||
fi
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
#------------- restart daemon function ----------------------
|
||||
restart() {
|
||||
if [ -f $rootdir/etc/init.d/$1 ]; then
|
||||
$rootdir/etc/init.d/$1 restart
|
||||
else
|
||||
help
|
||||
fi
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
#------------------ list services ---------------------------
|
||||
list() {
|
||||
ls --color $rootdir/usr/lib/init/services
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
#------------------ list enabled services -------------------
|
||||
bootlist() {
|
||||
ls --color $rootdir/etc/rc.d
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
#------------------ service status --------------------------
|
||||
status() {
|
||||
if [[ "$1" == "" ]]; then
|
||||
help
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$(ls $rootdir/etc/init.d | grep $1)" == "" ]]; then
|
||||
printf "$YELLOW**$BRED error:$RESET can't find service /etc/init.d/$1\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "$YELLOW**$GREEN $1$RESET\n"
|
||||
rcdservice=$(ls $rootdir/etc/rc.d | grep $1 2> /dev/null)
|
||||
if [[ "$rcdservice" == "" ]]; then
|
||||
printf "Loaded:$YELLOW unloaded$RESET (/etc/rc.d)\n"
|
||||
else
|
||||
printf "Loaded:$GREEN loaded$RESET (/etc/rc.d/$rcdservice)\n"
|
||||
fi
|
||||
servicepid=$(ls $rootdir/var/run | grep $1)
|
||||
if [[ "$servicepid" == "" ]]; then
|
||||
printf "Active: deactive (${YELLOW}deactive$RESET)\n"
|
||||
else
|
||||
printf "Active: active (${GREEN}running$RESET); pid (/var/run/$servicepid)\n"
|
||||
fi
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
#-------------- print help function -------------------------
|
||||
help() {
|
||||
echo "
|
||||
** rc usage:
|
||||
rc add [init.d script name] - add service on boot
|
||||
rc del [init.d script name] - delete service from boot
|
||||
rc start [init.d script name] - start service
|
||||
rc stop [init.d script name] - stop service
|
||||
rc restart [init.d script name] - restart service
|
||||
rc list - list all services
|
||||
rc bootlist - list enabled services
|
||||
rc status [init.d script name] - check service status
|
||||
|
||||
examples:
|
||||
rc add httpd
|
||||
rc del httpd
|
||||
rc start httpd
|
||||
rc stop httpd
|
||||
rc restart httpd
|
||||
rc list
|
||||
rc bootlist
|
||||
"
|
||||
}
|
||||
#------------------------------------------------------------
|
||||
|
||||
command="$1"
|
||||
|
||||
case ${command} in
|
||||
add)
|
||||
add $2 $3
|
||||
;;
|
||||
del)
|
||||
del $2
|
||||
;;
|
||||
start)
|
||||
start $2
|
||||
;;
|
||||
stop)
|
||||
stop $2
|
||||
;;
|
||||
restart)
|
||||
restart $2
|
||||
;;
|
||||
list)
|
||||
list
|
||||
;;
|
||||
bootlist)
|
||||
bootlist
|
||||
;;
|
||||
status)
|
||||
status $2
|
||||
;;
|
||||
*)
|
||||
help
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user