new: mtsc-common, mp-build and mp-pool
This commit is contained in:
9
mtsc-common/Makefile
Normal file
9
mtsc-common/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
PREFIX = /usr
|
||||
|
||||
install:
|
||||
install -m755 "common.sh" $(DESTDIR)/$(PREFIX)/lib/mtsc-common.sh
|
||||
|
||||
uninstall:
|
||||
rm $(DESTDIR)/$(PREFIX)/lib/mtsc-common.sh
|
||||
|
||||
.PHONY: install uninstall
|
3
mtsc-common/README.md
Normal file
3
mtsc-common/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# mtsc-common | MatterLinux common script functions
|
||||
A (bash) shell script that contains common functions used in MatterLinux
|
||||
build scripts and tools.
|
206
mtsc-common/common.sh
Executable file
206
mtsc-common/common.sh
Executable file
@ -0,0 +1,206 @@
|
||||
#!/bin/bash
|
||||
|
||||
# mtsc-common | MatterLinux common script functions
|
||||
# MatterLinux 2023-2024 (https://matterlinux.xyz)
|
||||
|
||||
# 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 3 of the License, or
|
||||
# (at your option) 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
$(return 0 2>/dev/null)
|
||||
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "This script contains common functions for MatterLinux tools/scripts"
|
||||
echo "You are not supposed to directly run it, now exiting to prevent any errors"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
############################
|
||||
## logging functions/vars ##
|
||||
############################
|
||||
BOLD="\e[1m"
|
||||
RESET="\e[0m"
|
||||
YELLOW="\e[33m"
|
||||
GREEN="\e[32m"
|
||||
BLUE="\e[34m"
|
||||
GRAY="\e[37m"
|
||||
RED="\e[31m"
|
||||
|
||||
NORMAL_PREFIX=">>>"
|
||||
INDENT_PREFIX=" |"
|
||||
|
||||
LOG_PREFIX="$NORMAL_PREFIX"
|
||||
|
||||
echo_color() {
|
||||
echo -e "${1}"
|
||||
}
|
||||
|
||||
success() {
|
||||
if [ "$LOG_PREFIX" == "$NORMAL_PREFIX" ]; then
|
||||
echo_color "${BOLD}${GREEN}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
|
||||
else
|
||||
echo_color "${BOLD}${GREEN}${LOG_PREFIX}${RESET} $1"
|
||||
fi
|
||||
}
|
||||
|
||||
info() {
|
||||
if [ "$LOG_PREFIX" == "$NORMAL_PREFIX" ]; then
|
||||
echo_color "${BOLD}${BLUE}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
|
||||
else
|
||||
echo_color "${BOLD}${BLUE}${LOG_PREFIX}${RESET} $1"
|
||||
fi
|
||||
}
|
||||
|
||||
warn() {
|
||||
if [ "$LOG_PREFIX" == "$NORMAL_PREFIX" ]; then
|
||||
echo_color "${BOLD}${YELLOW}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
|
||||
else
|
||||
echo_color "${BOLD}${YELLOW}${LOG_PREFIX}${RESET} $1"
|
||||
fi
|
||||
}
|
||||
|
||||
error() {
|
||||
if [ "$LOG_PREFIX" == "$NORMAL_PREFIX" ]; then
|
||||
echo_color "${BOLD}${RED}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
|
||||
else
|
||||
echo_color "${BOLD}${RED}${LOG_PREFIX}${RESET} $1"
|
||||
fi
|
||||
}
|
||||
|
||||
print() {
|
||||
echo_color "${BOLD}${GRAY}$1${RESET}"
|
||||
}
|
||||
|
||||
set_indent() {
|
||||
LOG_PREFIX="$INDENT_PREFIX"
|
||||
}
|
||||
|
||||
unset_indent() {
|
||||
LOG_PREFIX="$NORMAL_PREFIX"
|
||||
}
|
||||
|
||||
####################
|
||||
## util functions ##
|
||||
####################
|
||||
check_ret() {
|
||||
if [ $? -ne 0 ]; then
|
||||
if [ ! -z "$1" ]; then
|
||||
error "$1"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# integer-to-yes-or-no
|
||||
itoyn() {
|
||||
if [ $1 -eq 0 ]; then
|
||||
echo "${RED}no${RESET}"
|
||||
else
|
||||
echo "${GREEN}yes${RESET}"
|
||||
fi
|
||||
}
|
||||
|
||||
# checks if all the required package vars/functions are set
|
||||
check_pool_vars() {
|
||||
if [ ! -n "$NAME" ]; then
|
||||
error "Failed to load the pool script"
|
||||
set_indent
|
||||
|
||||
error "Required pool variable is not set: \"\$NAME\""
|
||||
unset_indent
|
||||
|
||||
return 1
|
||||
elif [ ! -n "$MAINTAINER" ]; then
|
||||
error "Failed to load the pool script"
|
||||
set_indent
|
||||
|
||||
error "Required pool variable is not set: \"\$MAINTAINER\""
|
||||
unset_indent
|
||||
|
||||
return 1
|
||||
elif [ ! -n "$PUBKEY" ]; then
|
||||
error "Failed to load the pool script"
|
||||
set_indent
|
||||
|
||||
error "Required pool variable is not set: \"\$PUBKEY\""
|
||||
unset_indent
|
||||
|
||||
return 1
|
||||
elif [ ! -n "$SRCDIR" ]; then
|
||||
error "Failed to load the pool script"
|
||||
set_indent
|
||||
|
||||
error "Required pool variable is not set: \"\$SRCDIR\""
|
||||
unset_indent
|
||||
|
||||
return 1
|
||||
fi
|
||||
|
||||
case "${NAME}" in
|
||||
*" "*)
|
||||
error "Pool name contains an invalid character: \" \""
|
||||
unset_indent
|
||||
return 1 ;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# checks if all the required package vars/functions are set
|
||||
check_pkg_vars() {
|
||||
if [ ! -n "$NAME" ]; then
|
||||
error "Failed to load the package script"
|
||||
set_indent
|
||||
|
||||
error "Required package variable is not set: \"\$NAME\""
|
||||
unset_indent
|
||||
|
||||
return 1
|
||||
elif [ ! -n "$VERSION" ]; then
|
||||
error "Failed to load the package script"
|
||||
set_indent
|
||||
|
||||
error "Required package variable is not set: \"\$VERSION\""
|
||||
unset_indent
|
||||
|
||||
return 1
|
||||
elif [ ! -n "$DESC" ]; then
|
||||
error "Failed to load the package script"
|
||||
set_indent
|
||||
|
||||
error "Required package variable is not set: \"\$DESC\""
|
||||
unset_indent
|
||||
|
||||
return 1
|
||||
elif ! type PACKAGE &>/dev/null; then
|
||||
error "Failed to load the package script"
|
||||
set_indent
|
||||
|
||||
error "Required \"PACKAGE()\" function is not defined"
|
||||
unset_indent
|
||||
|
||||
return 1
|
||||
fi
|
||||
|
||||
case "${NAME}" in
|
||||
*_*)
|
||||
error "Package name contains an invalid character: \"_\""
|
||||
unset_indent
|
||||
return 1 ;;
|
||||
*" "*)
|
||||
error "Package name contains an invalid character: \" \""
|
||||
unset_indent
|
||||
return 1 ;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
Reference in New Issue
Block a user