Improve debugger and host OS detection

This commit is contained in:
2022-02-13 18:09:21 -05:00
parent 35ce40c0ef
commit 9cd401ace5

View File

@@ -36,7 +36,7 @@ printHelp() {
--install, -i repo|local --install, -i repo|local
repo: Install MC from repository, updates are handled by the system package manager repo: Install MC from repository, updates are handled by the system package manager
local: Build and install MC package locally local: Build and install MC package locally
--build[=suse|fedora|centos] --build[=suse|fedora|centos|rhel]
Build RPM from source DEB but do not install Build RPM from source DEB but do not install
Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=') Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=')
--compat --compat
@@ -55,7 +55,7 @@ printHelp() {
Starts services at boot (system) or at user login (user) (Default: boot) Starts services at boot (system) or at user login (user) (Default: boot)
--container, -c CONTAINER (TODO: Under construction) --container, -c CONTAINER (TODO: Under construction)
See CONTAINERS section below for a list of possible services to install See CONTAINERS section below for a list of possible services to install
--createrepo[=suse|fedora|centos] --createrepo[=suse|fedora|centos|rhel]
Build rpm, copy to webroot, and run createrepo. Use in conjunction with --build=TARGET for crossbuilding repos Build rpm, copy to webroot, and run createrepo. Use in conjunction with --build=TARGET for crossbuilding repos
Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=') Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=')
--createrepo-webroot PATH --createrepo-webroot PATH
@@ -303,7 +303,7 @@ installPackage() {
install_flags+=(--allow-downgrades) install_flags+=(--allow-downgrades)
;; ;;
--nogpgcheck) --nogpgcheck)
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then if [[ "$ID" =~ ^(fedora|centos|rhel)$ ]]; then
install_flags+=(--nogpgcheck) install_flags+=(--nogpgcheck)
elif [[ "$ID" == "suse" ]]; then elif [[ "$ID" == "suse" ]]; then
install_flags+=(--allow-unsigned-rpm) install_flags+=(--allow-unsigned-rpm)
@@ -369,7 +369,7 @@ addRepo() {
fi fi
echo "Adding JRiver repository to package manager" echo "Adding JRiver repository to package manager"
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then if [[ "$ID" =~ ^(fedora|centos|rhel)$ ]]; then
declare sources_dir="/etc/yum.repos.d/" declare sources_dir="/etc/yum.repos.d/"
sudo bash -c "cat <<- EOF > $sources_dir/jriver.repo sudo bash -c "cat <<- EOF > $sources_dir/jriver.repo
[jriver] [jriver]
@@ -531,7 +531,7 @@ buildRPM() {
# Translate package names # Translate package names
case "$TARGET" in case "$TARGET" in
fedora|centos) fedora|centos|rhel)
requires=("${requires[@]/libc6/glibc}") requires=("${requires[@]/libc6/glibc}")
requires=("${requires[@]/libasound2/alsa-lib}") requires=("${requires[@]/libasound2/alsa-lib}")
requires=("${requires[@]/libuuid1/libuuid}") requires=("${requires[@]/libuuid1/libuuid}")
@@ -801,7 +801,7 @@ openFirewall() {
fi fi
# Open the ports # Open the ports
if [[ "$ID" =~ ^(fedora|centos|suse)$ ]]; then if [[ "$ID" =~ ^(fedora|centos|rhel|suse)$ ]]; then
installPackage firewalld installPackage firewalld
if ! firewall_cmd --get-services | grep -q "$1"; then if ! firewall_cmd --get-services | grep -q "$1"; then
firewall_cmd --permanent --new-service="$1" &>/dev/null firewall_cmd --permanent --new-service="$1" &>/dev/null
@@ -1308,6 +1308,71 @@ service_jriver-createrepo() {
# brc del-pkg .build-deps # brc del-pkg .build-deps
# } # }
#######################################
# Perform OS detection and use compatability modes if necessary
#######################################
getOS() {
debug "Running: ${FUNCNAME[0]}"
declare -g ID MGR
if [[ -e "/etc/os-release" ]]; then
source "/etc/os-release"
else
err "/etc/os-release not found"
err "Your OS is unsupported"
printHelp && exit 1
fi
debug "Detected host platform: $ID $VERSION_ID"
# normalize ID
case "$ID" in
fedora|arch|debian|centos)
;;
rhel)
ID="centos"
;;
linuxmint|neon|*ubuntu*)
ID="ubuntu"
;;
*suse*)
ID="suse"
;;
*)
echo "Autodetecting distro, this may be unreliable and --compat may also be required"
if hash dnf &>/dev/null; then
ID="fedora"
MGR="dnf"
elif hash yum &>/dev/null; then
ID="centos"
MGR="yum"
COMPAT_SWITCH=1
elif hash apt &>/dev/null; then
ID="ubuntu"
elif hash pacman &>/dev/null; then
ID="arch"
else
err "OS detection failed!"
exit 1
fi
esac
# Set package manager for RPM distros
case "$ID" in
centos|fedora|rhel)
if hash dnf &>/dev/null; then
MGR="dnf"
elif hash yum &>/dev/null; then
MGR="yum"
fi
;;
esac
debug "Using host platform: $ID $VERSION_ID"
}
uninstall() { uninstall() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
@@ -1396,55 +1461,10 @@ tests() {
main() { main() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare -g ID MGR getOS
if [[ -e "/etc/os-release" ]]; then
source "/etc/os-release"
else
err "/etc/os-release not found"
err "Your OS is unsupported"
printHelp && exit 1
fi
debug "Host platform: $ID $VERSION_ID"
case "$ID" in
centos|fedora)
if hash dnf &>/dev/null; then
MGR="dnf"
elif hash yum &>/dev/null; then
MGR="yum"
fi
;;
debian|ubuntu|arch)
return 0
;;
linuxmint|neon)
ID="ubuntu"
;;
*suse*)
ID="suse"
;;
*)
echo "Autodetecting distro, this may be unreliable and --compat may also be required"
if hash dnf &>/dev/null; then
ID="fedora"
MGR="dnf"
elif hash yum &>/dev/null; then
ID="centos"
MGR="yum"
elif hash apt &>/dev/null; then
ID="ubuntu"
elif hash pacman &>/dev/null; then
ID="arch"
fi
;;
esac
debug "Host compatability platform: $ID $VERSION_ID"
# Distro-specific commands # Distro-specific commands
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then if [[ "$ID" =~ ^(fedora|centos|rhel)$ ]]; then
pkg_install(){ sudo "$MGR" install -y "$@"; } pkg_install(){ sudo "$MGR" install -y "$@"; }
pkg_remove(){ sudo "$MGR" remove -y "$@"; } pkg_remove(){ sudo "$MGR" remove -y "$@"; }
pkg_update(){ sudo "$MGR" makecache; } pkg_update(){ sudo "$MGR" makecache; }
@@ -1475,7 +1495,7 @@ main() {
getVersion getVersion
# Set target package name # Set target package name
if [[ "$ID" =~ ^(fedora|centos|suse)$ ]]; then if [[ "$ID" =~ ^(fedora|centos|rhel|suse)$ ]]; then
MCPKG="MediaCenter" MCPKG="MediaCenter"
[[ "$VERSION_SOURCE" == "user input" ]] && MCPKG="$MCPKG-$MCVERSION" [[ "$VERSION_SOURCE" == "user input" ]] && MCPKG="$MCPKG-$MCVERSION"
elif [[ "$ID" =~ ^(debian|ubuntu)$ ]]; then elif [[ "$ID" =~ ^(debian|ubuntu)$ ]]; then
@@ -1496,9 +1516,11 @@ main() {
echo "Adding universe repository" echo "Adding universe repository"
sudo add-apt-repository universe sudo add-apt-repository universe
fi fi
elif [[ "$ID" == "centos" ]]; then elif [[ "$ID" =~ ^(centos|rhel)$ ]]; then
echo "Adding EPEL repository" echo "Adding EPEL repository"
installPackage epel-release installPackage epel-release
elif [[ "$ID" =~ ^(rhel)$ ]] && ! hash dpkg &>/dev/null; then
installPackage epel-release
fi fi
if (( REPO_INSTALL_SWITCH )); then if (( REPO_INSTALL_SWITCH )); then
@@ -1516,7 +1538,7 @@ main() {
if (( BUILD_SWITCH )); then if (( BUILD_SWITCH )); then
installPackage "wget" installPackage "wget"
acquireDeb acquireDeb
if [[ "$TARGET" =~ (centos|fedora|suse) ]]; then if [[ "$TARGET" =~ (centos|fedora|rhel|suse) ]]; then
installPackage "dpkg" "rpm-build" installPackage "dpkg" "rpm-build"
buildRPM buildRPM
fi fi
@@ -1524,7 +1546,7 @@ main() {
if (( LOCAL_INSTALL_SWITCH )); then if (( LOCAL_INSTALL_SWITCH )); then
if ([[ "$TARGET" =~ (debian|ubuntu) ]] && installMCDEB) || if ([[ "$TARGET" =~ (debian|ubuntu) ]] && installMCDEB) ||
([[ "$TARGET" =~ (fedora|centos|suse) ]] && ([[ "$TARGET" =~ (fedora|centos|rhel|suse) ]] &&
installPackage --skip-check-installed --nogpgcheck "$MCRPM") || installPackage --skip-check-installed --nogpgcheck "$MCRPM") ||
([[ "$TARGET" == "arch" ]] && installMCArch); then ([[ "$TARGET" == "arch" ]] && installMCArch); then
echo "JRiver Media Center installed successfully from local package" echo "JRiver Media Center installed successfully from local package"
@@ -1565,5 +1587,7 @@ main() {
# done # done
} }
# Quickly turn debugging on (catch for real with getopt in parseInput())
[[ " $* " =~ ( --debug | -d ) ]] && echo "First Debugging on!" && DEBUG=1
main "$@" main "$@"