- Initial release: help, list & install commands implemented.
This commit is contained in:
203
sbin/mpm
Executable file
203
sbin/mpm
Executable file
@@ -0,0 +1,203 @@
|
||||
#!/bin/bash
|
||||
#-------------------------------------------------------------------------------#
|
||||
#
|
||||
# MPM (Meta Package Manager)
|
||||
# Copyright (C) 2024 Arnaud G. GIBERT
|
||||
# mailto:arnaud@rx3.net
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
command="$1"
|
||||
arg="$2"
|
||||
|
||||
|
||||
|
||||
if [[ -f /etc/mpm.conf ]]
|
||||
then
|
||||
. /etc/mpm.conf
|
||||
else
|
||||
MPM_REPO="https://www.rx3.net/mpm-repository"
|
||||
fi
|
||||
|
||||
VERSION=1.0.0
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MPM Help
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mpm_help()
|
||||
{
|
||||
echo "MPM Version: [${VERSION}]"
|
||||
echo "Repository URL: [${MPM_REPO}]"
|
||||
echo "usage: mpm [--help | -h] | [--list | -l] | [--install | -i <mpm_name>]"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MPM Meta Package List
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mpm_mpkg_list()
|
||||
{
|
||||
echo "$(curl -L 2>/dev/null "${MPM_REPO}" | grep -e '\.mpm</a>' | sed -e 's/.*href="//' -e 's/\.mpm".*//')"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MPM Meta Package Tag Read
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mpm_mpkg_tag_read()
|
||||
{
|
||||
mpkg="$1"
|
||||
tag="$2"
|
||||
|
||||
echo "$(curl -L 2>/dev/null "${MPM_REPO}/${mpkg}.mpm" | grep -e "${tag}: " | sed -e "s/^${tag}: //")"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MPM Meta Package Description
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mpm_mpkg_desc()
|
||||
{
|
||||
mpkg="$1"
|
||||
|
||||
mpm_mpkg_tag_read "${mpkg}" "PKG_DESC"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MPM Meta Package List
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mpm_mpkg_pkglist()
|
||||
{
|
||||
mpkg="$1"
|
||||
|
||||
mpm_mpkg_tag_read "${mpkg}" "PKG_LIST"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MPM List
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mpm_list()
|
||||
{
|
||||
echo " MPM Name + MPM Description + Package List "
|
||||
echo "--------------------+---------------------------------+------------------------------------------------"
|
||||
|
||||
mpm_mpkg_list | while read mpkg
|
||||
do
|
||||
desc="$(mpm_mpkg_desc $mpkg)"
|
||||
pkglist="$(mpm_mpkg_pkglist $mpkg)"
|
||||
|
||||
printf "%20s: %-32s [%s]\n" "${mpkg}" "${desc}" "${pkglist}"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MPM Install
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mpm_install
|
||||
{
|
||||
mpkg=$1
|
||||
|
||||
if [[ "${mpkg}" == "" ]]
|
||||
then
|
||||
echo "missing required mpkg name"
|
||||
mpm_help
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
mpm_mpkg_list | grep -e "^${mpkg}$" -e "^${mpkg} " -e " ${mpkg}$" -e " ${mpkg} " 2>&1 >/dev/null
|
||||
|
||||
if [[ "$?" == 1 ]]
|
||||
then
|
||||
echo "mpkg [${mpkg}] not found!"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
pkglist="$(mpm_mpkg_pkglist $mpkg)"
|
||||
|
||||
if [[ "${pkglist}" == "" ]]
|
||||
then
|
||||
echo "package list is empty!"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "installing MPM: [$mpkg]:[${pkglist}]"
|
||||
|
||||
urpmi --force ${pkglist}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MPM Main
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
case "${command}"
|
||||
in
|
||||
"--help" | "-h")
|
||||
mpm_help
|
||||
;;
|
||||
|
||||
"--list" | "-l")
|
||||
mpm_list
|
||||
;;
|
||||
|
||||
"--install" | "-i")
|
||||
mpm_install $arg
|
||||
;;
|
||||
|
||||
*)
|
||||
if [[ "${command}" == "" ]]
|
||||
then
|
||||
echo "missing mandatory command!"
|
||||
else
|
||||
|
||||
echo "unknown command [${command}]!"
|
||||
fi
|
||||
|
||||
echo
|
||||
mpm_help
|
||||
|
||||
exit 1
|
||||
;;
|
||||
|
||||
|
||||
esac
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user