diff --git a/lgsm/modules/command_update_linuxgsm.sh b/lgsm/modules/command_update_linuxgsm.sh index 3c4e6d0809..1c20a5b483 100644 --- a/lgsm/modules/command_update_linuxgsm.sh +++ b/lgsm/modules/command_update_linuxgsm.sh @@ -16,24 +16,10 @@ info_distro.sh fn_print_dots "" fn_script_log_info "Updating LinuxGSM" +fn_repo_selector fn_print_dots "Selecting repo" -fn_script_log_info "Selecting repo" -# Select remotereponame -curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1> /dev/null -if [ $? != "0" ]; then - curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1> /dev/null - if [ $? != "0" ]; then - fn_print_fail_nl "Selecting repo: Unable to to access GitHub or Bitbucket repositories" - fn_script_log_fatal "Selecting repo: Unable to to access GitHub or Bitbucket repositories" - core_exit.sh - else - remotereponame="Bitbucket" - fn_print_ok_nl "Selecting repo: ${remotereponame}" - fi -else - remotereponame="GitHub" - fn_print_ok_nl "Selecting repo: ${remotereponame}" -fi +fn_print_ok_nl "Selecting repo: ${remotereponame}" +fn_script_log_pass "Selecting repo: ${remotereponame}" # Check linuxsm.sh echo -en "checking ${remotereponame} linuxgsm.sh...\c" @@ -99,7 +85,7 @@ if [ "${script_diff}" != "" ]; then sed -i "s+gamename=\"core\"+gamename=\"${gamename}\"+g" "${rootdir}/${selfname}" sed -i "s+githubuser=\"GameServerManagers\"+githubuser=\"${githubuser}\"+g" "${rootdir}/${selfname}" sed -i "s+githubrepo=\"LinuxGSM\"+githubrepo=\"${githubrepo}\"+g" "${rootdir}/${selfname}" - sed -i "s+githubbranch=\"master\"+githubbranch=\"${githubbranch}\"+g" "${rootdir}/${selfname}" + sed -i "s+githubbranch=\"master\"+githubbranch=\"${githubbranch}\"+g;q" "${rootdir}/${selfname}" if [ $? != "0" ]; then fn_print_fail_eol_nl diff --git a/linuxgsm.sh b/linuxgsm.sh index 331a618221..ae9ba4b474 100755 --- a/linuxgsm.sh +++ b/linuxgsm.sh @@ -58,7 +58,36 @@ if [ ! "$(command -v curl 2> /dev/null)" ]; then exit 1 fi -# Core module that is required first. +fn_repo_selector() { + # Check if GitHub is accessible if not fail over to Bitbucket. + repocheck=$(curl -s -o /dev/null -w "%{http_code}" "https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/master/linuxgsm.sh" 2> /dev/null) + if [ "${repocheck}" != "200" ]; then + echo -e "Selecting repo: GitHub is not accessable. Selecting Bitbucket" + repocheck=$(curl -s -o /dev/null -w "%{http_code}" "https://bitbucket.org/GameServerManagers/LinuxGSM/raw/master/linuxgsm.sh" 2> /dev/null) + if [ "${repocheck}" != "200" ]; then + echo -e "Selecting repo: Unable to to access GitHub or Bitbucket repositories" + exit 1 + else + remotereponame="Bitbucket" + fi + else + remotereponame="GitHub" + fi + + # Check that git branch exists. + if [ "${remotereponame}" == "GitHub" ]; then + branchexistscheck=$(curl -s -o /dev/null -w "%{http_code}" "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 2> /dev/null) + else + branchexistscheck=$(curl -s -o /dev/null -w "%{http_code}" "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 2> /dev/null) + fi + + if [ "${branchexistscheck}" != "200" ]; then + echo -e "Warning! ${githubbranch} branch does not exist. Defaulting to master branch." + githubbranch="master" + fi +} + +# Fetches the core module required before passed off to core_dl.sh. core_modules.sh() { modulefile="${FUNCNAME[0]}" fn_bootstrap_fetch_file_github "lgsm/modules" "core_modules.sh" "${modulesdir}" "chmodx" "run" "noforcedl" "nomd5" @@ -166,18 +195,25 @@ fn_bootstrap_fetch_file() { } fn_bootstrap_fetch_file_github() { + fn_repo_selector github_file_url_dir="${1}" github_file_url_name="${2}" + # By default modules will be downloaded from the version release to prevent potential version mixing. Only update-lgsm will allow an update. - if [ "${githubbranch}" == "master" ] && [ "${githubuser}" == "GameServerManagers" ] && [ "${commandname}" != "UPDATE-LGSM" ]; then - remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}" - remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}" - else - remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" - remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" + if [ "${remotereponame}" == "GitHub" ]; then + if [ "${githubbranch}" == "master" ] && [ "${githubuser}" == "GameServerManagers" ] && [ "${commandname}" != "UPDATE-LGSM" ]; then + remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}" + else + remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" + fi + elif [ "${remotereponame}" == "BitBucket" ]; then + if [ "${githubbranch}" == "master" ] && [ "${githubuser}" == "GameServerManagers" ] && [ "${commandname}" != "UPDATE-LGSM" ]; then + remote_fileurl="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}" + else + remote_fileurl="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" + fi fi remote_fileurl_name="GitHub" - remote_fileurl_backup_name="Bitbucket" local_filedir="${3}" local_filename="${github_file_url_name}" chmodx="${4:-0}" @@ -185,7 +221,7 @@ fn_bootstrap_fetch_file_github() { forcedl="${6:-0}" md5="${7:-0}" # Passes vars to the file download module. - fn_bootstrap_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}" + fn_bootstrap_fetch_file "${remote_fileurl}" "" "${remote_fileurl_name}" "" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}" } # Installer menu.