Prevent injections

This commit is contained in:
2022-01-07 23:35:30 -05:00
parent fa96735448
commit 382b462922

View File

@@ -183,7 +183,7 @@ init() {
} }
# Helpers # Helpers
debug() { [[ -v DEBUG && $# -gt 0 ]] && echo "Debug: $*"; } debug() { (( DEBUG )) && [[ $# -gt 0 ]] && echo "Debug: $*"; }
err() { echo "Error: $*" >&2; } err() { echo "Error: $*" >&2; }
askOk() { askOk() {
declare response declare response
@@ -243,11 +243,11 @@ parseInput() {
err "RPM install method not available on $ID" err "RPM install method not available on $ID"
printHelp && exit 1 printHelp && exit 1
fi fi
BUILD_SWITCH=true BUILD_SWITCH=1
fi fi
;; ;;
--build) --build)
BUILD_SWITCH=true BUILD_SWITCH=1
;; ;;
--target) --target)
shift && TARGET="$1" shift && TARGET="$1"
@@ -271,8 +271,8 @@ parseInput() {
shift && SERVICES+=("$1") shift && SERVICES+=("$1")
;; ;;
--createrepo) --createrepo)
BUILD_SWITCH=true BUILD_SWITCH=1
CREATEREPO_SWITCH=true CREATEREPO_SWITCH=1
;; ;;
--createrepo-webroot) --createrepo-webroot)
shift && CREATEREPO_WEBROOT="$1" shift && CREATEREPO_WEBROOT="$1"
@@ -287,7 +287,7 @@ parseInput() {
shift && USER_DISPLAY="$1" shift && USER_DISPLAY="$1"
;; ;;
--compat) --compat)
COMPAT_SWITCH=true COMPAT_SWITCH=1
;; ;;
--container|-c) --container|-c)
shift && CONTAINERS+=("$1") shift && CONTAINERS+=("$1")
@@ -299,13 +299,13 @@ parseInput() {
--debug|-d) --debug|-d)
echo "Debugging on" echo "Debugging on"
echo "installJRMC version: $SCRIPTVERSION" echo "installJRMC version: $SCRIPTVERSION"
DEBUG=true DEBUG=1
;; ;;
--help|-h) --help|-h)
printHelp && exit $? printHelp && exit $?
;; ;;
--uninstall|-u) --uninstall|-u)
UNINSTALL_SWITCH=true UNINSTALL_SWITCH=1
;; ;;
--tests) --tests)
echo "Running tests, all other options are skipped" echo "Running tests, all other options are skipped"
@@ -422,7 +422,7 @@ installPackage() {
while true; do while true; do
case "$1" in case "$1" in
--nocheck) --nocheck)
nocheck=true nocheck=1
;; ;;
--nogpgcheck) --nogpgcheck)
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
@@ -437,7 +437,7 @@ installPackage() {
fi fi
;; ;;
--silent|-s) --silent|-s)
silent=true silent=1
;; ;;
--) --)
shift shift
@@ -466,8 +466,7 @@ installPackage() {
pkg=${PKG_ALIASES[$pkg]} pkg=${PKG_ALIASES[$pkg]}
fi fi
# Check if already installed # Check if already installed
if [[ -v nocheck ]] \ if (( nocheck )) || ([[ ! -x $(command -v $pkg) ]] \
|| ([[ ! -x $(command -v $pkg) ]] \
&& ! pkg_query "$pkg" &>/dev/null); then && ! pkg_query "$pkg" &>/dev/null); then
pkg_array+=("$pkg") pkg_array+=("$pkg")
fi fi
@@ -477,7 +476,7 @@ installPackage() {
if [[ ${#pkg_array[@]} -ge 1 ]]; then if [[ ${#pkg_array[@]} -ge 1 ]]; then
pkg_install_cmd="pkg_install ${install_flags[*]} ${pkg_array[*]}" pkg_install_cmd="pkg_install ${install_flags[*]} ${pkg_array[*]}"
debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null" debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
if ! eval "$pkg_install_cmd" && [[ ! -v silent ]]; then if ! eval "$pkg_install_cmd" && (( silent )); then
err "Failed to install ${pkg_array[*]}. Attempting to continue..." err "Failed to install ${pkg_array[*]}. Attempting to continue..."
fi fi
@@ -693,7 +692,7 @@ buildRPM() {
requires="${requires%?}" requires="${requires%?}"
recommends="${recommends%?}" recommends="${recommends%?}"
if [[ -v COMPAT_SWITCH ]]; then if (( COMPAT_SWITCH )); then
# Strip minimum versions # Strip minimum versions
requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}') requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}')
fi fi
@@ -771,9 +770,9 @@ runCreaterepo() {
# If the webroot does not exist, create it # If the webroot does not exist, create it
if [[ ! -d "$CREATEREPO_WEBROOT" ]]; then if [[ ! -d "$CREATEREPO_WEBROOT" ]]; then
cr_mkdir_cmd="sudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT" #cr_mkdir_cmd="sudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT"
debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null" #debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
if ! eval "$cr_mkdir_cmd"; then #if ! eval "$cr_mkdir_cmd"; then
cr_mkdir_cmd="mkdir_cmd $CREATEREPO_WEBROOT" cr_mkdir_cmd="mkdir_cmd $CREATEREPO_WEBROOT"
debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null" debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
cr_chown_cmd="chown_cmd $CREATEREPO_USER $CREATEREPO_WEBROOT" cr_chown_cmd="chown_cmd $CREATEREPO_USER $CREATEREPO_WEBROOT"
@@ -783,14 +782,14 @@ runCreaterepo() {
err "Make sure that the createrepo-webroot is writeable by createrepo-user: $CREATEREPO_USER" err "Make sure that the createrepo-webroot is writeable by createrepo-user: $CREATEREPO_USER"
return 1 return 1
fi fi
fi #fi
fi fi
# Copy built rpms to webroot # Copy built rpms to webroot
cr_cp_cmd="sudo -u $CREATEREPO_USER cp -n -f $MCRPM $CREATEREPO_WEBROOT" #cr_cp_cmd="sudo -u $CREATEREPO_USER cp -n -f $MCRPM $CREATEREPO_WEBROOT"
cr_chown_cmd="sudo -u $CREATEREPO_USER chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT" #cr_chown_cmd="sudo -u $CREATEREPO_USER chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
debug "$cr_cp_cmd && $cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null" cr_chown_cmd+=" &>/dev/null" #debug "$cr_cp_cmd && $cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null" cr_chown_cmd+=" &>/dev/null"
if ! ( exec "$cr_cp_cmd" && exec "$cr_chown_cmd" ); then #if ! ( exec "$cr_cp_cmd" && exec "$cr_chown_cmd" ); then
cr_cp_cmd="cp_cmd $MCRPM $CREATEREPO_WEBROOT" cr_cp_cmd="cp_cmd $MCRPM $CREATEREPO_WEBROOT"
cr_chown_cmd="chown_cmd $CREATEREPO_USER $CREATEREPO_WEBROOT" cr_chown_cmd="chown_cmd $CREATEREPO_USER $CREATEREPO_WEBROOT"
debug "$cr_cp_cmd" || cr_cp_cmd+=" &>/dev/null" debug "$cr_cp_cmd" || cr_cp_cmd+=" &>/dev/null"
@@ -800,7 +799,7 @@ runCreaterepo() {
#err "Is the createrepo-webroot $CREATEREPO_WEBROOT writeable by createrepo-user: $CREATEREPO_USER?" #err "Is the createrepo-webroot $CREATEREPO_WEBROOT writeable by createrepo-user: $CREATEREPO_USER?"
return 1 return 1
fi fi
fi #fi
# Run createrepo # Run createrepo
cr_cmd="sudo -u $CREATEREPO_USER createrepo -q" cr_cmd="sudo -u $CREATEREPO_USER createrepo -q"
@@ -1438,7 +1437,7 @@ main() {
init "$@" init "$@"
# Uninstall and exit # Uninstall and exit
if [[ -v UNINSTALL_SWITCH ]]; then if (( UNINSTALL_SWITCH )); then
uninstall uninstall
exit $? exit $?
fi fi
@@ -1465,14 +1464,14 @@ main() {
fi fi
# Build RPM from source deb package # Build RPM from source deb package
if [[ -v BUILD_SWITCH ]]; then if (( BUILD_SWITCH )); then
installPackage "wget" "dpkg" "rpm-build" installPackage "wget" "dpkg" "rpm-build"
acquireDeb acquireDeb
buildRPM buildRPM
fi fi
# Run createrepo # Run createrepo
if [[ -v CREATEREPO_SWITCH ]]; then if (( CREATEREPO_SWITCH )); then
runCreaterepo runCreaterepo
exit $? exit $?
fi fi