Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): if github branch doesnt exist default to master #4170

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
22 changes: 4 additions & 18 deletions lgsm/modules/command_update_linuxgsm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
54 changes: 45 additions & 9 deletions linuxgsm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -166,26 +195,33 @@ 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}"
run="${5:-0}"
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.
Expand Down
Loading