Expand eval usage

This commit is contained in:
2022-01-07 18:55:58 -05:00
parent c746dd3fc9
commit 21064eb7d0

View File

@@ -389,7 +389,7 @@ getLatestVersion() {
return 0 return 0
fi fi
# Scrape from Interact # Scrape from Interact
installPackage --silent wget installPackage wget
if MCVERSION=$(wget -qO- "$BOARDURL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then if MCVERSION=$(wget -qO- "$BOARDURL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then
version_source="webscrape" version_source="webscrape"
fi fi
@@ -414,7 +414,7 @@ installPackage() {
debug "Running: ${FUNCNAME[0]}" "$@" debug "Running: ${FUNCNAME[0]}" "$@"
declare -a pkg_array install_flags declare -a pkg_array install_flags
declare pkg nocheck silent _return declare pkg nocheck silent _return pkg_install_cmd
if _input=$(getopt -o +s -l nocheck,nogpgcheck,nobest,silent -- "$@"); then if _input=$(getopt -o +s -l nocheck,nogpgcheck,nobest,silent -- "$@"); then
eval set -- "$_input" eval set -- "$_input"
@@ -474,15 +474,12 @@ installPackage() {
# Install packages from package array # Install packages from package array
if [[ ${#pkg_array[@]} -ge 1 ]]; then if [[ ${#pkg_array[@]} -ge 1 ]]; then
debug "pkg_install ${install_flags[*]} ${pkg_array[*]}" pkg_install_cmd="pkg_install ${install_flags[*]} ${pkg_array[*]}"
if $DEBUG; then debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
pkg_install "${install_flags[@]}" "${pkg_array[@]}" if ! eval "$pkg_install_cmd" && [[ ! -v silent ]]; then
else err "Failed to install ${pkg_array[*]}. Attempting to continue..."
pkg_install "${install_flags[@]}" "${pkg_array[@]}" &>/dev/null
fi fi
_return=$?
[[ $_return -ne 0 && ! -v silent ]] && err "Failed to install ${pkg_array[*]}. Attempting to continue..."
return $_return
fi fi
} }
@@ -502,7 +499,7 @@ addRepo() {
EOF' EOF'
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
# MVERSION depends on $BASE unless --MCVERSION is passed # MVERSION depends on $BASE unless --MCVERSION is passed
installPackage --silent wget installPackage wget
wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | ifSudo apt-key add - &>/dev/null wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | ifSudo apt-key add - &>/dev/null
ifSudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list" &>/dev/null ifSudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list" &>/dev/null
elif [[ "$ID" =~ ^opensuse.* ]]; then elif [[ "$ID" =~ ^opensuse.* ]]; then
@@ -530,19 +527,15 @@ installMCFromRepo() {
addRepo addRepo
# Update package list # Update package list
debug "Updating package list" debug "$pkg_update_cmd" || pkg_update_cmd+=" &>/dev/null"
if ! pkg_update &>/dev/null; then if ! eval "$pkg_update_cmd"; then
err "Package update failed!" err "Package update failed!"
exit 1 exit 1
fi fi
if $DEBUG; then pkg_install_cmd="installPackage --nocheck --nogpgcheck $MCPKG"
installPackage --nocheck --nogpgcheck "$MCPKG" debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
else eval "$pkg_install_cmd"
installPackage --nocheck --nogpgcheck "$MCPKG" &>/dev/null
fi
return $?
} }
@@ -753,9 +746,8 @@ buildRPM() {
# Run rpmbuild # Run rpmbuild
echo "Building version $MCVERSION, please wait..." echo "Building version $MCVERSION, please wait..."
rpmbuild_cmd="rpmbuild --define=\"%_topdir $OUTPUTDIR\" --define=\"%_libdir /usr/lib\" -bb $OUTPUTDIR/SPECS/mediacenter.spec" rpmbuild_cmd="rpmbuild --define=\"%_topdir $OUTPUTDIR\" --define=\"%_libdir /usr/lib\" -bb $OUTPUTDIR/SPECS/mediacenter.spec"
$DEBUG || rpmbuild_cmd+=" &>/dev/null" debug "$rpmbuild_cmd" || rpmbuild_cmd+=" &>/dev/null"
if eval "$rpmbuild_cmd" && [[ -f "$MCRPM" ]] ; then if eval "$rpmbuild_cmd" && [[ -f "$MCRPM" ]] ; then
echo "Build successful. The RPM file is located at: $MCRPM" echo "Build successful. The RPM file is located at: $MCRPM"
else else
@@ -774,19 +766,20 @@ buildRPM() {
runCreaterepo() { runCreaterepo() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare -a createrepo_cmd declare cr_cmd cr_cp_cmd cr_mkdir_cmd cr_chown_cmd
installPackage createrepo_c installPackage createrepo_c
# 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
debug "ifSudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT" cr_mkdir_cmd="ifSudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT"
if ! ifSudo -u "$CREATEREPO_USER" mkdir -p "$CREATEREPO_WEBROOT" &>/dev/null; then debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
debug "ifSudo mkdir -p $CREATEREPO_WEBROOT" if ! eval "$cr_mkdir_cmd"; then
if ifSudo mkdir -p "$CREATEREPO_WEBROOT" && \ cr_mkdir_cmd="ifSudo mkdir -p $CREATEREPO_WEBROOT"
ifSudo chown -R "$CREATEREPO_USER":"$CREATEREPO_USER" "$CREATEREPO_WEBROOT"; then debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
: cr_chown_cmd="ifSudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
else debug "$cr_chown_cmd" || cr_chown_cmd+=" &>/dev/null"
if ! ( eval "$cr_mkdir_cmd" && eval "$cr_chown_cmd" ); then
err "Could not create the createrepo-webroot path!" err "Could not create the createrepo-webroot path!"
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
@@ -795,13 +788,13 @@ runCreaterepo() {
fi fi
# Copy built rpms to webroot # Copy built rpms to webroot
debug "ifSudo -u $CREATEREPO_USER cp -n -f $MCRPM $CREATEREPO_WEBROOT" cr_cp_cmd="ifSudo -u $CREATEREPO_USER cp -n -f $MCRPM $CREATEREPO_WEBROOT"
if ! ifSudo -u "$CREATEREPO_USER" cp -n -f "$MCRPM" "$CREATEREPO_WEBROOT" &>/dev/null; then cr_chown_cmd="ifSudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
debug "cp_cmd $MCRPM $CREATEREPO_WEBROOT" debug "$cr_cp_cmd && $cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null" cr_chown_cmd+=" &>/dev/null"
if cp_cmd "$MCRPM" "$CREATEREPO_WEBROOT" && \ if ! (eval "$cr_cp_cmd" && eval "$cr_chown_cmd"); then
ifSudo chown -R "$CREATEREPO_USER":"$CREATEREPO_USER" "$CREATEREPO_WEBROOT"; then cr_cp_cmd="cp_cmd $MCRPM $CREATEREPO_WEBROOT"
: debug "$cr_cp_cmd" || cr_cp_cmd+=" &>/dev/null"
else if ! eval "$cr_cp_cmd"; then
err "Could not copy $MCRPM to $CREATEREPO_WEBROOT" err "Could not copy $MCRPM to $CREATEREPO_WEBROOT"
err "Make sure that the createrepo-webroot path is writeable by createrepo-user: $CREATEREPO_USER" err "Make sure that the createrepo-webroot path is writeable by createrepo-user: $CREATEREPO_USER"
return 1 return 1
@@ -809,10 +802,10 @@ runCreaterepo() {
fi fi
# Run createrepo # Run createrepo
createrepo_cmd=("sudo" "-u" "$CREATEREPO_USER" "createrepo" "-q") cr_cmd="sudo -u $CREATEREPO_USER createrepo -q"
[[ -d "$CREATEREPO_WEBROOT/repodata" ]] && createrepo_cmd+=("--update") [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=" --update"
debug "${createrepo_cmd[*]} $CREATEREPO_WEBROOT" debug "$cr_cmd $CREATEREPO_WEBROOT" || cr_cmd+=" &>/dev/null"
if "${createrepo_cmd[@]}" "$CREATEREPO_WEBROOT"; then if eval "$cr_cmd $CREATEREPO_WEBROOT"; then
echo "Successfully updated repo" echo "Successfully updated repo"
return 0 return 0
else else
@@ -1407,34 +1400,24 @@ uninstall() {
firewall_cmd --reload &>/dev/null firewall_cmd --reload &>/dev/null
fi fi
elif [[ -x $(command -v ufw) ]]; then elif [[ -x $(command -v ufw) ]]; then
if [[ -v debug ]]; then firewall_cmd="firewall_cmd delete allow jriver"
firewall_cmd delete allow jriver debug "$firewall_cmd" || firewall_cmd+=" &>/dev/null"
else eval "$firewall_cmd"
firewall_cmd delete allow jriver &>/dev/null
fi
[[ -f "/etc/ufw/applications.d/jriver" ]] \ [[ -f "/etc/ufw/applications.d/jriver" ]] \
&& rm_cmd /etc/ufw/applications.d/jriver && rm_cmd /etc/ufw/applications.d/jriver
fi fi
debug "Uninstalling Media Center packages" debug "Uninstalling Media Center package"
if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then mc_pkg_rm_cmd="pkg_remove $MCPKG"
MCPKG="MediaCenter" debug "$mc_pkg_rm_cmd" || mc_pkg_rm_cmd+=" &>/dev/null"
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then if eval "$mc_pkg_rm_cmd"; then
MCPKG="mediacenter$MVERSION" echo "JRiver Media Center has been completely uninstalled."
fi echo "To remove your library files, run: rm -rf $HOME/.jriver"
echo "To remove your rpmbuild output files, run: rm -rf $OUTPUTDIR"
if $DEBUG; then exit 0
debug "pkg_remove $MCPKG"
pkg_remove "$MCPKG"
else else
pkg_remove "$MCPKG" &>/dev/null exit $?
fi fi
echo "JRiver Media Center has been completely uninstalled."
echo "To remove your library files, run: rm -rf $HOME/.jriver"
echo "To remove your rpmbuild output files, run: rm -rf $OUTPUTDIR"
exit 0
} }
@@ -1478,7 +1461,7 @@ main() {
# Build RPM from source deb package # Build RPM from source deb package
if [[ -v BUILD_SWITCH ]]; then if [[ -v BUILD_SWITCH ]]; then
installPackage --silent "wget" "dpkg" "rpm-build" installPackage "wget" "dpkg" "rpm-build"
acquireDeb acquireDeb
buildRPM buildRPM
fi fi