Created
April 7, 2022 19:43
-
-
Save flleeppyy/7f3b66056994348b2d1c671057744be5 to your computer and use it in GitHub Desktop.
JMusicBot configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nohup java -Dnogui=true -jar JMusicBot-0.3.8.jar & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Updater: Get the latest release of jagrosh/MusicBot from github | |
# NOTE: name format is JMusicBot-x.x.x.jar" | |
# First check if node is installed | |
if ! [ -x "$(command -v node)" ]; then | |
echo 'Error: node is not installed.' >&2 | |
exit 1 | |
fi | |
echo "Fetching latest release of jagrosh/MusicBot..." | |
# Get the latest release of jagrosh/MusicBot from github | |
latest=$(curl -s https://api.github.com/repos/jagrosh/MusicBot/releases/latest | jq -r '.tag_name') | |
release_asset_url=$(curl -s https://api.github.com/repos/jagrosh/MusicBot/releases/latest | jq -r '.assets[0].browser_download_url') | |
# Run a check if the version is already installed | |
if [ -f "JMusicBot-$latest.jar" ]; then | |
echo "Latest version JMusicBot-$latest.jar is already installed" | |
exit 0 | |
fi | |
# Kill all java process that contain "JMusicBot" in their command, using node | |
echo "Killing 'JMusicBot'" | |
echo ' | |
const child_process = require("child_process"); | |
(async () => { | |
const commandArgs = "ps -A -o pid,args| grep java"; | |
const results = await child_process.execSync(commandArgs).toString("utf-8"); | |
const lines = results.split("\\n").map(line => line.trim()); | |
const javaProcesses = lines.filter(line => line.includes("java")).map(line => { | |
const pid = line.split(" ")[0]; | |
const args = line.split(" ").slice(1).join(" "); | |
return { pid, args }; | |
}); | |
const JMusicBotProcesses = javaProcesses.filter(process => process.args.includes("JMusicBot")); | |
JMusicBotProcesses.forEach(jProcess => { | |
console.log(`Killing process ${jProcess.pid}`); | |
child_process.execSync(`kill -9 ${jProcess.pid}`); | |
}); | |
})();' | node -; | |
# Check if there was an error | |
if [ $? -ne 0 ]; then | |
echo "Error: Could not kill all java processes" | |
exit 1 | |
fi | |
# Remove previous versions | |
echo "Removing previous versions" | |
rm -f JMusicBot-*.jar | |
# Download the jar file | |
echo "Downloading JMusicBot-$latest.jar" | |
curl -L -o JMusicBot-$latest.jar $release_asset_url | |
# Replace the version name in the start.sh script | |
echo "Replacing version name in start.sh" | |
sed -i "s/JMusicBot-.*.jar/JMusicBot-$latest.jar/g" start.sh | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment