diff --git a/pleroma b/pleroma index 62e13c6..e5781a2 100755 --- a/pleroma +++ b/pleroma @@ -1,69 +1,22 @@ #!/bin/bash +######################################################### +# Options # +######################################################### + set -e set -o pipefail -print_help() { - echo " -Pleroma Maintenance Script - -Usage: - $0 [action] - -Actions: - build Rebuild the pleroma container. - - config [file = config.yml] Print the generated pleroma config to stdout. - - dump Dump the generated docker-compose.yml to stdout. - - debug [bin] [args...] Launches a new pleroma container but uses \$bin instead of phx.server as entrypoint. - **Warning**: This is intended for debugging pleroma with tools like :debugger and :observer. - It thus forwards your X-Server into docker and temporarily fiddles with your xhost - access controls. If this is a security concern for you, please export NO_X_FORWARDING=1 - before launching a debugger session. - - enter Spawn a shell inside the container for debugging/maintenance. - This command does not link to the postgres container. - If you need that use #debug instead. - - logs Show the current container logs. - - mix [task] [args...] Run a mix task without entering the container. - - mod [file] Creates the file in custom.d and downloads the content from pleroma.social. - The download respects your \$PLEROMA_VERSION from .env. - - passthrough / p [...] Pass any custom command to docker-compose. - - restart Executes #stop and #start respectively. - - start / up Start pleroma and sibling services. - - stop / down Stop pleroma and sibling services. - - status / ps Show the current container status. - -Environment: - DEBUG can be used to modify the loglevel. - DEBUG=1 prints all commands before they are executed. - DEBUG=2 prints all bash statements before they are executed (a lot). - - SHOPT can be used to modify shell options. - Pass a list of options to this variable like SHOPT='-x -e'. - -e is always on unless you set it to +e. - - For setting long options with -o use a colon (:) instead of a space - to seperate the option from -o. For example: SHOPT='-x -e -o:pipefail'. - -Contributing: - You can report bugs or contribute to this project at: - https://glitch.sh/sn0w/pleroma-docker -" -} +######################################################### +# Globals # +######################################################### flags="" +######################################################### +# Helpers # +######################################################### + render_template() { m4 $flags docker-compose.m4 | awk 'NF' } @@ -92,31 +45,71 @@ load_env() { done < .env } -action__build() { docker_compose build --build-arg __BUST_CACHE="$(date +%s)" server; } -action__config() { docker run --rm -t -i -v $(pwd):/mnt ruby:alpine sh -c "cd /mnt && ruby config_parser/parser.rb ${1:-config.yml}"; } -action__dump() { cat <(render_template); } -action__enter() { docker_compose exec server ash -c 'cd /pleroma && ash'; } -action__logs() { docker_compose logs -f; } -action__mix() { docker_compose exec server ash -c "cd /pleroma && mix $*"; } -action__passthrough() { docker_compose $*; } -action__p() { action__passthrough $*; } +######################################################### +# Subcommands # +######################################################### + +action__build() { + docker_compose build --build-arg __BUST_CACHE="$(date +%s)" server +} + +action__config() { + docker run --rm -t -i -v $(pwd):/mnt ruby:alpine sh -c "cd /mnt && ruby config_parser/parser.rb ${1:-config.yml}" +} + +action__dump() { + cat <(render_template) +} + +action__enter() { + docker_compose exec server ash -c 'cd /pleroma && ash' +} -action__restart() { action__stop; action__start; } +action__logs() { + docker_compose logs -f $* +} -action__start() { docker_compose up --remove-orphans -d; } -action__up() { action__start; } +action__mix() { + docker_compose exec server ash -c "cd /pleroma && mix $*" +} -action__stop() { docker_compose down; } -action__down() { action__stop; } +action__passthrough() { + docker_compose $* +} -action__status() { docker_compose ps; } -action__ps() { action__status; } +action__p() { + action__passthrough $* +} + +action__restart() { + action__stop + action__start +} + +action__start() { + docker_compose up --remove-orphans -d +} + +action__up() { + action__start +} + +action__stop() { + docker_compose down +} + +action__down() { + action__stop +} + +action__status() { + docker_compose ps +} + +action__ps() { + action__status +} -### -# This function rips out the mix caches from the container -# in order to speed up rebuilds during debugging/modding sessions. -# To persist the changes, the user still needs to rebuild the container. -### action__debug() { debug_mounts="-v $(pwd)/custom.d:/custom.d -v $(pwd)/debug.d/build:/home/pleroma/pleroma/_build -v $(pwd)/debug.d/deps:/home/pleroma/pleroma/deps" @@ -148,6 +141,73 @@ action__mod() { wget -O ./custom.d/$1 https://git.pleroma.social/pleroma/pleroma/raw/$PLEROMA_VERSION/$1 } +######################################################### +# Help # +######################################################### + +print_help() { + echo " +Pleroma Maintenance Script + +Usage: + $0 [action] + +Actions: + build Rebuild the pleroma container. + + config [file = config.yml] Print the generated pleroma config to stdout. + + dump Dump the generated docker-compose.yml to stdout. + + debug [bin] [args...] Launches a new pleroma container but uses \$bin instead of phx.server as entrypoint. + **Warning**: This is intended for debugging pleroma with tools like :debugger and :observer. + It thus forwards your X-Server into docker and temporarily fiddles with your xhost + access controls. If this is a security concern for you, please export NO_X_FORWARDING=1 + before launching a debugger session. + + enter Spawn a shell inside the container for debugging/maintenance. + This command does not link to the postgres container. + If you need that use #debug instead. + + logs Show the current container logs. + + mix [task] [args...] Run a mix task without entering the container. + + mod [file] Creates the file in custom.d and downloads the content from pleroma.social. + The download respects your \$PLEROMA_VERSION from .env. + + passthrough / p [...] Pass any custom command to docker-compose. + + restart Executes #stop and #start respectively. + + start / up Start pleroma and sibling services. + + stop / down Stop pleroma and sibling services. + + status / ps Show the current container status. + +Environment: + DEBUG can be used to modify the loglevel. + DEBUG=1 prints all commands before they are executed. + DEBUG=2 prints all bash statements before they are executed (a lot). + + SHOPT can be used to modify shell options. + Pass a list of options to this variable like SHOPT='-x -e'. + -e is always on unless you set it to +e. + + For setting long options with -o use a colon (:) instead of a space + to seperate the option from -o. For example: SHOPT='-x -e -o:pipefail'. + +Contributing: + You can report bugs or contribute to this project at: + https://glitch.sh/sn0w/pleroma-docker +" +} + +######################################################### +# Main # +######################################################### + # Check if there is any command at all if [[ -z "$1" ]]; then print_help @@ -177,8 +237,7 @@ fi # Parse .env load_env -# Guess function name of current command -# and then check for it's existance. +# Guess function name of current command and call it if present func="action__${1}" if type -t $func 2>&1 1>/dev/null; then