Skip to content

Instantly share code, notes, and snippets.

@Tschrock
Created July 30, 2014 20:23
Show Gist options
  • Save Tschrock/de1c53773eb4920aec0f to your computer and use it in GitHub Desktop.
Save Tschrock/de1c53773eb4920aec0f to your computer and use it in GitHub Desktop.
Some stuff for developing Pocketmine plugins
#!/bin/bash
#
# This needs to be set to the Plugin's server directory!!
#
PP_ServerDirectory="/home/tyler/pocketmine/1.4plugdev"
# Just some options for cleaning up before we package.
# - We don't need any options for hidden files as those aren't included anyway.
# - Everything not listed will be temp removed before packaging
# Note: This only looks 1 deep into the plugin's folder
PP_Clean_Keep=("resources" "src" "plugin.yml" "plugin.yaml")
PP_Clean_Remove=("config.yml")
# The Cleaning function
clean_dir () {
cd "$PP_ServerDirectory/plugins/$PP_PluginName"
PP_Clean_Files=("$PP_ServerDirectory/plugins/$PP_PluginName"/*)
local i
for i in "${PP_Clean_Files[@]}"
do
if containsElement $(basename $i) "${PP_Clean_Keep[@]}"; then
echo Keeping $(basename $i)
else if containsElement $(basename $i) "${PP_Clean_Remove[@]}"; then
PP_file=$(basename "$i")
echo Removing "$PP_file"
rm -r "$PP_file"
else
PP_file=$(basename "$i")
[[ -e ./.tmp-PP_Clean ]] || mkdir ./.tmp-PP_Clean
echo Temp Removing "$PP_file"
mv "$PP_file" ./.tmp-PP_Clean/"$PP_file"
fi;fi
done
}
clean_dir_unremove () {
if [[ -e "$PP_ServerDirectory/plugins/$PP_PluginName/.tmp-PP_Clean" ]]; then
cd "$PP_ServerDirectory/plugins/$PP_PluginName"
PP_Clean_Files=("$PP_ServerDirectory/plugins/$PP_PluginName/.tmp-PP_Clean"/*)
local i
for i in "${PP_Clean_Files[@]}"
do
PP_file=$(basename "$i")
mv ./.tmp-PP_Clean/"$PP_file" "$PP_file"
done
rm -r "$PP_ServerDirectory/plugins/$PP_PluginName/.tmp-PP_Clean"
fi
}
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
PP_PluginName="$1"
# Check Plugin name one last time
if [[ ("$PP_PluginName" != "") && (-e "$PP_ServerDirectory/plugins/$PP_PluginName") ]]; then
echo "Preparing to package $PP_PluginName"
cd $PP_ServerDirectory
# Get a tmp file
PP_InPipe="$(mktemp)"
# Make the file into a named pipe for injecting commands into the server
rm $PP_InPipe
mkfifo $PP_InPipe
# Start the server with our named pipe and watch the output
( cat $PP_InPipe | ./start.sh &) | while read LOGLINE
do
# Check if the server's started
if [[ "${LOGLINE}" == *"[INFO] Done"* ]]; then
# Clean up some files before we package it
echo "Cleaning up plugin files"
clean_dir
# Inject /makeplugin and /stop using our pipe
echo -e "makeplugin $PP_PluginName\nstop" > $PP_InPipe
fi
if [[ "${LOGLINE}" == *"[INFO] Phar plugin"* ]]; then
echo "${LOGLINE}"
fi
done
#Done! Now we just need to do some Cleanup
clean_dir_unremove
rm $PP_InPipe
else
echo "'"$PP_PluginName"'" "could not be found"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment