|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -gnome-terminal "bash -c './run_linux_no_console.sh; exec bash'" |
4 |
| -gnome-terminal "bash -c './run_linux_no_console.sh; exec bash'" |
5 |
| -gnome-terminal "bash -c './run_linux_no_console.sh; exec bash'" |
6 |
| -gnome-terminal "bash -c './run_linux_no_console.sh; exec bash'" |
7 |
| -gnome-terminal "bash -c './run_linux_no_console.sh; exec bash'" |
8 |
| -gnome-terminal "bash -c './run_linux_no_console.sh; exec bash'" |
| 3 | +# Forces the script to relaunch in bash if necessary |
| 4 | +if [ -z "$BASH_VERSION" ]; then |
| 5 | + exec /bin/bash "$0" "$@" |
| 6 | +fi |
| 7 | + |
| 8 | +# Set variables |
| 9 | +SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)" |
| 10 | +LOG_DIR="${SCRIPT_DIR}/logs" |
| 11 | +JAVA_VERSION=$(java -version 2>&1 | grep -oP '(?<=version ")[^"]+') |
| 12 | +declare -A USER_ARRAY |
| 13 | + |
| 14 | +# Check if Java is installed |
| 15 | +if ! command -v java &> /dev/null; then |
| 16 | +echo "Java is not installed. You need to install Java 1.8." |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +# Check Java version |
| 21 | +if [[ "${JAVA_VERSION}" != 1.8* ]]; then |
| 22 | + echo "It is recommended to use Java 1.8 for IdleRSC!" |
| 23 | +fi |
| 24 | + |
| 25 | +# Add an entry for each account you want to launch a session for |
| 26 | +# The 'keys' in USER_ARRAY are used for creating log files per instance, while the 'values' are for passing args to that instance. |
| 27 | +# For example, 'USER_ARRAY["USERNAME"]="--auto-start --account testuser"' |
| 28 | +# would run an instance with '--auto-start --account testuser' and log output to 'IdleRSC/scripts/logs/instance_USERNAME.log' |
| 29 | + |
| 30 | +USER_ARRAY["USERNAME"]="--auto-start --account USERNAME" |
| 31 | + |
| 32 | +# Delete old log files |
| 33 | +if [ -n "${LOG_DIR}" ] && [ -d "${LOG_DIR}" ]; then |
| 34 | + if [ -z "$(find "${LOG_DIR}" -maxdepth 0 -type d -empty)" ]; then |
| 35 | + rm -r "${LOG_DIR}/instance_"* |
| 36 | + fi |
| 37 | +fi |
| 38 | + |
| 39 | +# Create new log directory if it doesn't exist |
| 40 | +if [ ! -d "${LOG_DIR}" ]; then |
| 41 | + mkdir "${LOG_DIR}" |
| 42 | +fi |
| 43 | + |
| 44 | +cd "$SCRIPT_DIR/.." || exit |
| 45 | + |
| 46 | +# Loop through the array to open an instance for each index |
| 47 | +for user in "${!USER_ARRAY[@]}"; do |
| 48 | + LOG_FILE="${LOG_DIR}/instance_${user}.log" |
| 49 | + |
| 50 | + # Log useful information to the top of the instances log file |
| 51 | + printf "User: '%s'\nJava Info:\n%s\n" "${user}" "$(java -version 2>&1)" > "${LOG_FILE}" |
| 52 | + |
| 53 | + # Launch an instance and echo the output to logs/instance_username.log. |
| 54 | + nohup java -jar ./IdleRSC.jar "${USER_ARRAY[$user]}" >> "${LOG_FILE}" 2>&1 & sleep 0.3 |
| 55 | +done |
0 commit comments