commit ec160f7ed9f091bcc6e76853910c5f672a2601a4 Author: bdrtr Date: Fri Feb 28 00:31:54 2025 +0300 preload diff --git a/README.md b/README.md new file mode 100644 index 0000000..51194c8 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# ServerFinder +scale to your MC (paper, spigot) servers on debian based systems. diff --git a/finder.sh b/finder.sh new file mode 100644 index 0000000..04b596d --- /dev/null +++ b/finder.sh @@ -0,0 +1,29 @@ +#!/usr/bin/bash + +function find_server_files() { + + running_jar=$(ps aux | grep '[j]ava' | grep 'paper\|spigot' | awk '{print $(NF-1)}') + if [[ $running_jar ]]; then + gum log --structured --level info "running jar file is found" + continue + else + gum log --structured --level info "running jar file is not found" + gum confirm "Do you want to manual search for the jar file?" || server_jar="" + + fi + + + server_jar=$(find ~/ -type f \( -name "paper*.jar" -o -name "spigot*.jar" \)) + + if [[ ${server_jar[@]} -eq 0 ]]; then + gum log --structured --level info "jar file not found" + server_jar=$(gum file $HOME) + + else + gum log --structured --level info "jar file found" + gum choose --header "prefer" ${server_jar[@]} + fi + + echo $server_jar +} + diff --git a/main.sh b/main.sh new file mode 100644 index 0000000..5783f80 --- /dev/null +++ b/main.sh @@ -0,0 +1,15 @@ +#! usr/bin/bash + +source finder.sh +source starter.sh + +function main() { + + result=$(find_server_files) + starter_main $result + + +} + + +main \ No newline at end of file diff --git a/server_start_options.txt b/server_start_options.txt new file mode 100644 index 0000000..e3c6ed9 --- /dev/null +++ b/server_start_options.txt @@ -0,0 +1,4 @@ +min_ram=4G +max_ram=4G +#disk_priority=2 +#cpu_priority=4 diff --git a/start_options.sh b/start_options.sh new file mode 100644 index 0000000..5ed650d --- /dev/null +++ b/start_options.sh @@ -0,0 +1,17 @@ +#! bin/bash + +declare -A options + +function run { + + while IFS='=' read -r key value; do + [[ -z "$key" || "$key" =~ ^# ]] && continue + options["$key"]=$value + done < server_start_options.txt + + for key in "${!options[@]}"; do + echo "$key=${options[$key]}" + done + + cd $2 && java -Xms${options['min_ram']} -Xmx${options['max_ram']} -jar $1 nogui +} \ No newline at end of file diff --git a/starter.sh b/starter.sh new file mode 100644 index 0000000..4b3e580 --- /dev/null +++ b/starter.sh @@ -0,0 +1,129 @@ +#! usr/bin/bash + +source start_options.sh + +function change_the_properties() { + gum log --structured --level info "we find the $1 file" + gum write --width 40 --value "$(awk -F "=" '{printf "%s --> %s\n", $1, $2}' "$current_path/$1")" > $current_path/temp.txt + awk -F "-->" '{printf "%s=%s\n", $1, $2}' $current_path/temp.txt > $current_path/$1 + gum log --structured --level info "$1 file is updated" +} + +function change_the_properties_other () { + + gum log --structured --level info "we find the $1 file" + writed_file=$(<"$current_path/$1") + write=$(gum write --width 40 --value "$writed_file") + echo $write > $current_path/$1 + gum log --structured --level info "$1 file is updated" + +} + + +function just_base_of_path () { + + __current_path=$(echo $1 | awk -F "/" '{OFS="/"; $NF=""; print $0}') #this path is used to read the files in the directory + echo $__current_path +} + +function just_name_of_path () { + + __current_path=$(echo $1 | awk -F "/" '{print $NF}') #this path is used to read the files in the directory + echo $__current_path +} + +function server_options() { + local select=$(gum choose --header "Options" server.properties permissions.yml commands.yml whitelist.json bukkit.yml banned-ips.json banned-players.json choose-your-file) + + case $select in + + "server.properties") + change_the_properties "server.properties" + ;; + "permissions.yml") + change_the_properties_other "permissions.yml" + ;; + "commands.yml") + change_the_properties_other "commands.yml" + ;; + "whitelist.json") + change_the_properties_other "whitelist.json" + ;; + "bukkit.yml") + change_the_properties_other "bukkit.yml" + ;; + "banned-ips.json") + change_the_properties_other "banned-ips.json" + ;; + "banned-players.json") + change_the_properties_other "banned-players.json" + ;; + "choose-your-file") + change_the_properties_other $(just_name_of_path $(gum file $current_path)) + ;; + *) + ;; + esac + + starter_main $_current_path +} + +function server_start () { + + echo "eula=true" > $current_path/eula.txt + + select=$(gum choose --header "Options" "quick-start" "custom-start") + + case $select in + + "quick-start") + run $_current_path $current_path + ;; + "custom-start") + gum log --structured --level info "Customizing the server" + ;; + *) + ;; + esac +} + + +function starter_main() { + + _current_path=$1 #this path provied by the main.sh + current_path=$(just_base_of_path $_current_path) #this path is used to read the files in the directory + + select=$(gum choose --header "Options" start-server stop-server restart-server status-server find-server options-server) + + + case $select in + + "start-server") + server_start + ;; + "stop-server") + gum log --structured --level info "Stopping server" + ;; + "restart-server") + gum log --structured --level info "Restarting server" + ;; + "status-server") + gum log --structured --level info "Checking server status" + ;; + "find-server") + gum log --structured --level info "Finding server" + ;; + "options-server") + server_options + ;; + + + + *) + ;; + esac + +} + + +