rc script, pm - package manger and update init scripts

This commit is contained in:
wt committed 2024-07-08 18:40:50 +07:00
1 parent 7c88b136ef
commit 31717c44b6
40 files changed
+569 -231

No files matched your search

-16
View File
@@ -1,16 +0,0 @@
#!/bin/sh
if [ -f /etc/init.d/$1 ] && [ "$2" -gt 0 ]; then
cd /etc/rc.d
ln -sv ../init.d/$1 "$2$1"
echo "added $1 to init."
else
echo "
** add-rc.d usage:
add-rc.d [init.d script name] [order number]
examples:
add-rc.d httpd 40
add-rc.d ftpd 40
add-rc.d telnetd 50
"
fi
+284
View File
@@ -0,0 +1,284 @@
#!/bin/sh
########## #### ####
########## #### ####
## ## ## ## ## ##
## ## ## ## ## ##
########## ## ## ## - PACKAGE MANAGER FOR SIMPLE LINUX
########## ## ## ## - AUTHOR -- TOLA MIRONCENKO
## ## ##
## ## ##
## ## ##
## ## ##
#----- colors -------
Green='\033[0;32m'
Color_off='\033[0m'
Red='\033[0;31m'
Bred='\033[1;31m'
Yellow='\033[1;33m'
White='\033[0;37m'
Bwhite='\033[1;37m'
#--------------------
#---------------- 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:$Color_off 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**$Color_off Downloading $Yellow$serverdir: $Bwhite$j\n$Color_off"
wget $i/$1.pkg.gz -P $cachedpkgdir
if [[ "$?" == "0" ]]; then
printf "$Yellow**$Green successful downloaded $1\n$Color_off"
return
else
printf "$Yellow**$Red error:$Color_off can't download package\n"
exit 1
fi
else
printf "$Yellow**$Green successful downloaded $1\n$Color_off"
return
fi
# exit 0
fi
done
done
printf "$Yellow**$Red error:$Color_off 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$Color_off"
if [[ "$(cat $packagesqueryfile | grep ${packagename%.pkg*})" != "" ]]; then
printf "$Yellow**$Color_off 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 [[ "$(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$Color_off"
}
#------------------------------------------------------------------------
#------------------ delete package function -----------------------------
del() {
printf "$Yellow**$Green deleting\n$Color_off"
for i in $*; do
if [[ "$i" == "del" ]]; then
continue
fi
printf "$Yellow**$Green deleting $i\n$Color_off"
if [ ! -f $installedpackagesdir/$i.pkg/list ]; then
printf "$Yellow**$Bred error:$Color_off 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$Color_off"
done
}
#------------------------------------------------------------------------
#------------------- list files in package function ---------------------
list() {
if [[ "$1" == "" ]]; then
help
exit 0
fi
if [[ "$(cat $packagesqueryfile | grep $1)" == "" ]]; then
printf "$Yellow**$Bred error:$Color_off package is not installed\n"
exit 1
fi
filelist=$(cat $installedpackagesdir/$1.pkg/list)
for i in $filelist; do
printf "$Yellow$1: $Bwhite$i$Color_off\n"
done
}
#------------------------------------------------------------------------
#------------------- show installed packages function -------------------
query() {
packagesquery=$(cat $packagesqueryfile)
if [[ "$packagesquery" == "" ]]; then
printf "$Yellow**$Bwhite No installed packages\n"
exit 0
fi
printf "$Bwhite$packagesquery$Color_off\n"
}
#------------------------------------------------------------------------
#--------------------- show help function -------------------------------
help() {
printf "
$Yellow**$Green pm usage$Color_off :
$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$Color_off :
$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$Color_off"
}
#------------------------------------------------------------------------
#------------------- 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$Color_off"
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$Color_off"
exit 0
fi
done
done
printf "$Yellow**$Red error:$Color_off 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
+124
View File
@@ -0,0 +1,124 @@
#!/bin/sh
########## ##########
########## ##########
## ## ##
## ##
## ## - RC BOOT SCRIPTS MANAGER FOR SIMPLE LINUX
## ## - AUTHOR -- TOLA MIRONCENKO
## ##
## ##
## ##########
## ##########
#------------------------ add to boot function --------------
add() {
resultlink=$(cat /usr/share/rc/ordernumbers | grep $1)
if [ -f /etc/init.d/$1 ] && [ $resultlink ]; then
cd /etc/rc.d
ln -sv ../init.d/$1 "$resultlink" &> /dev/null
echo "added $1 to init."
else
help
fi
}
#------------------------------------------------------------
#--------------------- del from boot function ---------------
del() {
filetoremove=$(find /etc/rc.d/ | grep $1 )
if [ $filetoremove ]; then
rm -v $filetoremove &> /dev/null
echo "removed $1 from init."
else
help
fi
}
#------------------------------------------------------------
#---------------------- start daemon function ---------------
start() {
if [ -f /etc/init.d/$1 ]; then
/etc/init.d/$1 start
else
help
fi
}
#------------------------------------------------------------
#---------------- stop daemon function ----------------------
stop() {
if [ -f /etc/init.d/$1 ]; then
/etc/init.d/$1 stop
else
help
fi
}
#------------------------------------------------------------
#------------- restart daemon function ----------------------
restart() {
if [ -f /etc/init.d/$1 ]; then
/etc/init.d/$1 restart
else
help
fi
}
#------------------------------------------------------------
#-------------- print help function -------------------------
help() {
echo "
** rc usage:
rc add [init.d script name]
rc del [init.d script name]
rc start [init.d script name]
rc stop [init.d script name]
rc restart [init.d script name]
examples:
rc add httpd
rc add ftpd
rc add telnetd
rc del httpd
rc del ftpd
rc del telnetd
rc start httpd
rc start ftpd
rc start telnetd
rc stop httpd
rc stop ftpd
rc stop telnetd
rc restart httpd
rc restart ftpd
rc restart telnetd
"
}
#------------------------------------------------------------
command="$1"
case ${command} in
add)
add $2 $3
;;
del)
del $2
;;
start)
start $2
;;
stop)
stop $2
;;
restart)
restart $2
;;
*)
help
;;
esac
-15
View File
@@ -1,15 +0,0 @@
#!/bin/sh
if [ -f /etc/rc.d/$1 ]; then
rm -v /etc/rc.d/$1
echo "removed $1 from init."
else
echo "
** rm-rc.d usage:
rm-rc.d [rc.d link name]
examples:
rm-rc.d 40httpd
rm-rc.d 40ftpd
rm-rc.d 50telnetd
"
fi
View File
Whitespace-only changes.
@@ -0,0 +1,2 @@
fet.sh.pkg.gz
pfetch.pkg.gz
+14
View File
@@ -0,0 +1,14 @@
15hostname
20klogd
30syslogd
40swap
50networking
55sysctl
60dnsmasq
65dnsd
70telnet
75ssh
80iptables
85openrouterinit
90ftp
95nginx