diff --git a/installJRMC b/installJRMC index 3083713..0884f15 100755 --- a/installJRMC +++ b/installJRMC @@ -36,7 +36,7 @@ printHelp() { --install, -i repo|local repo: Install MC from repository, updates are handled by the system package manager 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 Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=') --compat @@ -55,7 +55,7 @@ printHelp() { Starts services at boot (system) or at user login (user) (Default: boot) --container, -c CONTAINER (TODO: Under construction) 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 Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=') --createrepo-webroot PATH @@ -303,7 +303,7 @@ installPackage() { install_flags+=(--allow-downgrades) ;; --nogpgcheck) - if [[ "$ID" =~ ^(fedora|centos)$ ]]; then + if [[ "$ID" =~ ^(fedora|centos|rhel)$ ]]; then install_flags+=(--nogpgcheck) elif [[ "$ID" == "suse" ]]; then install_flags+=(--allow-unsigned-rpm) @@ -369,7 +369,7 @@ addRepo() { fi 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/" sudo bash -c "cat <<- EOF > $sources_dir/jriver.repo [jriver] @@ -531,7 +531,7 @@ buildRPM() { # Translate package names case "$TARGET" in - fedora|centos) + fedora|centos|rhel) requires=("${requires[@]/libc6/glibc}") requires=("${requires[@]/libasound2/alsa-lib}") requires=("${requires[@]/libuuid1/libuuid}") @@ -801,7 +801,7 @@ openFirewall() { fi # Open the ports - if [[ "$ID" =~ ^(fedora|centos|suse)$ ]]; then + if [[ "$ID" =~ ^(fedora|centos|rhel|suse)$ ]]; then installPackage firewalld if ! firewall_cmd --get-services | grep -q "$1"; then firewall_cmd --permanent --new-service="$1" &>/dev/null @@ -1308,6 +1308,71 @@ service_jriver-createrepo() { # 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() { debug "Running: ${FUNCNAME[0]}" @@ -1396,55 +1461,10 @@ tests() { main() { 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 "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" + getOS # Distro-specific commands - if [[ "$ID" =~ ^(fedora|centos)$ ]]; then + if [[ "$ID" =~ ^(fedora|centos|rhel)$ ]]; then pkg_install(){ sudo "$MGR" install -y "$@"; } pkg_remove(){ sudo "$MGR" remove -y "$@"; } pkg_update(){ sudo "$MGR" makecache; } @@ -1475,7 +1495,7 @@ main() { getVersion # Set target package name - if [[ "$ID" =~ ^(fedora|centos|suse)$ ]]; then + if [[ "$ID" =~ ^(fedora|centos|rhel|suse)$ ]]; then MCPKG="MediaCenter" [[ "$VERSION_SOURCE" == "user input" ]] && MCPKG="$MCPKG-$MCVERSION" elif [[ "$ID" =~ ^(debian|ubuntu)$ ]]; then @@ -1496,9 +1516,11 @@ main() { echo "Adding universe repository" sudo add-apt-repository universe fi - elif [[ "$ID" == "centos" ]]; then + elif [[ "$ID" =~ ^(centos|rhel)$ ]]; then echo "Adding EPEL repository" installPackage epel-release + elif [[ "$ID" =~ ^(rhel)$ ]] && ! hash dpkg &>/dev/null; then + installPackage epel-release fi if (( REPO_INSTALL_SWITCH )); then @@ -1516,7 +1538,7 @@ main() { if (( BUILD_SWITCH )); then installPackage "wget" acquireDeb - if [[ "$TARGET" =~ (centos|fedora|suse) ]]; then + if [[ "$TARGET" =~ (centos|fedora|rhel|suse) ]]; then installPackage "dpkg" "rpm-build" buildRPM fi @@ -1524,7 +1546,7 @@ main() { if (( LOCAL_INSTALL_SWITCH )); then if ([[ "$TARGET" =~ (debian|ubuntu) ]] && installMCDEB) || - ([[ "$TARGET" =~ (fedora|centos|suse) ]] && + ([[ "$TARGET" =~ (fedora|centos|rhel|suse) ]] && installPackage --skip-check-installed --nogpgcheck "$MCRPM") || ([[ "$TARGET" == "arch" ]] && installMCArch); then echo "JRiver Media Center installed successfully from local package" @@ -1565,5 +1587,7 @@ main() { # done } +# Quickly turn debugging on (catch for real with getopt in parseInput()) +[[ " $* " =~ ( --debug | -d ) ]] && echo "First Debugging on!" && DEBUG=1 main "$@"