From 6054dc146413cd23c260eaf4c933efe9bb9ee1ab Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Tue, 3 Oct 2023 12:08:41 +0100 Subject: [PATCH] better standardise random --- lgsm/modules/fix_samp.sh | 4 ++-- lgsm/modules/info_messages.sh | 9 --------- lgsm/modules/install_config.sh | 8 ++++---- lgsm/modules/update_mcb.sh | 4 ++-- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/lgsm/modules/fix_samp.sh b/lgsm/modules/fix_samp.sh index 461d92aee7..24882f9150 100644 --- a/lgsm/modules/fix_samp.sh +++ b/lgsm/modules/fix_samp.sh @@ -16,8 +16,8 @@ if [ -f "${servercfgfullpath}" ]; then fixname="change default rcon password" fn_fix_msg_start fn_script_log_info "changing rcon/admin password." - random=$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c 8 | xargs) - rconpass="admin${random}" + randomstring=$(tr -dc 'A-Za-z0-9_' < /dev/urandom 2> /dev/null | head -c 8 | xargs) + rconpass="admin${randomstring}" sed -i "s/rcon_password changeme/rcon_password ${rconpass}/g" "${servercfgfullpath}" fn_fix_msg_end fi diff --git a/lgsm/modules/info_messages.sh b/lgsm/modules/info_messages.sh index 2d706d7ba1..d205c08a8f 100644 --- a/lgsm/modules/info_messages.sh +++ b/lgsm/modules/info_messages.sh @@ -7,15 +7,6 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -# Separator is different for details. -fn_messages_separator() { - if [ "${commandname}" == "DETAILS" ]; then - printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' = - else - echo -e "${bold}=================================${default}" - fi -} - # Removes the passwords form all but details. fn_info_message_password_strip() { if [ "${commandname}" != "DETAILS" ]; then diff --git a/lgsm/modules/install_config.sh b/lgsm/modules/install_config.sh index 3ae4a20c4f..1e3c243abe 100644 --- a/lgsm/modules/install_config.sh +++ b/lgsm/modules/install_config.sh @@ -78,9 +78,9 @@ fn_default_config_local() { # PASSWORD to random password fn_set_config_vars() { if [ -f "${servercfgfullpath}" ]; then - random=$(tr -dc 'A-Za-z0-9_' < /dev/urandom 2>/dev/null | head -c 8 | xargs) + randomstring=$(tr -dc 'A-Za-z0-9_' < /dev/urandom 2> /dev/null | head -c 8 | xargs) servername="LinuxGSM" - rconpass="admin${random}" + rconpass="admin${randomstring}" echo -e "changing hostname." fn_script_log_info "changing hostname." fn_sleep_time @@ -121,8 +121,8 @@ fn_set_dst_config_vars() { fn_sleep_time echo -e "randomizing cluster key." fn_script_log_info "randomizing cluster key." - randomkey=$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c 8 | xargs) - sed -i "s/CLUSTERKEY/${randomkey}/g" "${clustercfgfullpath}" + randomstring=$(tr -dc 'A-Za-z0-9_' < /dev/urandom 2> /dev/null | head -c 8 | xargs) + sed -i "s/CLUSTERKEY/${randomstring}/g" "${clustercfgfullpath}" fn_sleep_time else echo -e "${clustercfg} is already configured." diff --git a/lgsm/modules/update_mcb.sh b/lgsm/modules/update_mcb.sh index 6d13728567..eb8adfd12c 100644 --- a/lgsm/modules/update_mcb.sh +++ b/lgsm/modules/update_mcb.sh @@ -50,10 +50,10 @@ fn_update_localbuild() { fn_update_remotebuild() { # Random number for userAgent - randnum=$((1 + RANDOM % 5000)) + randomint=$(tr -dc 0-9 < /dev/urandom 2> /dev/null | head -c 4 | xargs) # Get remote build info. if [ "${mcversion}" == "latest" ]; then - remotebuildversion=$(curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -Ls -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.${randnum}.212 Safari/537.36" "https://www.minecraft.net/en-us/download/server/bedrock/" | grep -o 'https://minecraft.azureedge.net/bin-linux/[^"]*' | sed 's/.*\///' | grep -Eo "[.0-9]+[0-9]") + remotebuildversion=$(curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -Ls -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.${randomint}.212 Safari/537.36" "https://www.minecraft.net/en-us/download/server/bedrock/" | grep -o 'https://minecraft.azureedge.net/bin-linux/[^"]*' | sed 's/.*\///' | grep -Eo "[.0-9]+[0-9]") else remotebuildversion="${mcversion}" fi