This commit is contained in:
Bedir Tuğra Karaabalı 2025-02-28 00:31:54 +03:00
commit ec160f7ed9
6 changed files with 196 additions and 0 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# ServerFinder
scale to your MC (paper, spigot) servers on debian based systems.

29
finder.sh Normal file
View File

@ -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
}

15
main.sh Normal file
View File

@ -0,0 +1,15 @@
#! usr/bin/bash
source finder.sh
source starter.sh
function main() {
result=$(find_server_files)
starter_main $result
}
main

4
server_start_options.txt Normal file
View File

@ -0,0 +1,4 @@
min_ram=4G
max_ram=4G
#disk_priority=2
#cpu_priority=4

17
start_options.sh Normal file
View File

@ -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
}

129
starter.sh Normal file
View File

@ -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
}