0

How would I force my server to download a specific file every time the server is started up? For example; I have a plugin coded, and I want to make it so it will automatically reinstall that plugin to the server every time it is started up, but I want it to check if the server has the plugin already.

So, for example the plugin would be called Test.jar I want to check to see if the server contains the file "Test.jar", if it does, do nothing, else install the plugin.

Also, if that above is possible, how would I check to see if it is the correct file, rather than just a random filed named "Test.jar" to get around that check?

If it helps, I use the Pterodactyl panel, so maybe a script can be added to the Startup Command?

I also have all the information necessary to hook a discord bot up to the panel, which I've started doing, but I can't find a good API for javascript.

I tried using websockets, but I can not seem to find any documentation to assist me on this, I also tried asking for support on the Pterodactyl support discord, and searching on the API documentation, but I can't figure it out.

  • 2
    While your goal is understandable, your question lacks all the details that might permit someone to answer it. How do you start your server? How do you install the plugin? Where are the plugin files located once it's installed? etc.... – Fravadona Nov 20 '22 at 01:18
  • "server" as in "the machine" or as in "server process"? – derpirscher Nov 20 '22 at 10:50

1 Answers1

0

For the main part of your question, the native solution is using Cron daemon named crond by configuring /etc/crontab.

By this, you may schedule desired commands/scripts to be run regularly or once per reboot.

So, to keep /etc/crontab configuration simple and clear, I'd suggest creating a proper bash script (make it executable) and then configuring it in crontab to be run on server boot.

Example: Add the following line to your /etc/crontab file:

Note: This assumes you have root privileges otherwise read more about cron command to schedule it for the user.

@reboot root /script.sh

Since you didn't detail the reproducing steps related to all parts of the goals you're trying to reach (as @Fravadona also stated in the comments) please feel free to use the following script as a hint/example and develop it to cover your needs.

#!/bin/bash

## USER DEFINED VARIABLES
# Jar file path
# Relevant path can be passed to this script as the first argument
# Default is: '/Test.jar'
_jarFilePath="${1:- /Test.jar}"

# Jar file sha256sum hash 
# Intended to provide this value manually for now, hash of file can be identified by running 'sha256sum' command passing the file path to this command:
# sha256sum <PATH_TO_FILE>
# but may be automated by a relevant logic.
_jarFileHash="<PUT_FILE_HASH_HERE>"

## SCRIPT BODY

# Check if the Jar file is available and has the currect Hash then do nothing (exit)
# otherwise continue running some commands to download/install it.

if [ -f "${_jarFilePath}" ] && [ "$(sha256sum ${_jarFilePath} | awk '{print $1}')" == "${_jarFileHash}" ] ;then
  exit 0
fi

# Put the commands that works for you to install the file after this line.
# Example: wget -O ${_jarFilePath}  <URL_TO_DOWNLOAD_FILE_FROM>
Vab
  • 412
  • 1
  • 11