Skip to content

Commit

Permalink
Add support for certificates in setup command
Browse files Browse the repository at this point in the history
  • Loading branch information
dhelonious committed Feb 15, 2025
1 parent d9f6959 commit 01ca003
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/actions/test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ runs:
sleep 10
sudo snap set mastodon-server domain="${{ steps.env.outputs.DOMAIN }}"
sudo snap set mastodon-server email="${{ steps.env.outputs.EMAIL }}"
sudo mastodon-server.setup -u ${{ steps.env.outputs.USERNAME }}
sudo mastodon-server.setup -u ${{ steps.env.outputs.USERNAME }} -c no
sleep 10
- name: install snap
shell: bash
Expand All @@ -87,7 +87,7 @@ runs:
echo "Test setup" | yellow
sudo snap set mastodon-server domain="${{ steps.env.outputs.DOMAIN }}"
sudo snap set mastodon-server email="${{ steps.env.outputs.EMAIL }}"
if sudo mastodon-server.setup -u ${{ steps.env.outputs.USERNAME }}; then
if sudo mastodon-server.setup -u ${{ steps.env.outputs.USERNAME }} -c no; then
echo "Mastodon setup completed successfully" | green
else
echo "Mastodon setup failed" | red
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ If you're not running Ubuntu, start by [installing the snap daemon](https://snap

sudo mastodon-server.setup

sudo mastodon-server.get-certificate

🥳 Congratulations! You now have your very own Mastodon instance! 🎉

> Note that an administrator account with a randomly generated password is created during setup. Some usernames such as `admin` and `administrator` are reserved by Mastodon. See the [FAQ](docs/faq.md) for a full list.
Expand Down Expand Up @@ -76,7 +74,7 @@ An initial setup command is required to initialize the database and configuratio
## SSL

SSL certificates can be obtained via ACME from either [Let's Encrypt](https://letsencrypt.org/), [ZeroSSL](https://zerossl.com/) or [BuyPass](https://buypass.com):
SSL certificates can be obtained via ACME from either [Let's Encrypt](https://letsencrypt.org/), [ZeroSSL](https://zerossl.com/) or [BuyPass](https://buypass.com). This is done either during `mastodon-server.setup` or by using:

mastodon-server.get-certificate

Expand Down
2 changes: 1 addition & 1 deletion src/acme/bin/get-certificate
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ while getopts "d:m:s:h" OPTION; do
fi
;;
h)
echo "Usage: $SNAP_NAME.get-certificate [-d DOMAIN] [-m EMAIL]"
echo "Usage: $SNAP_NAME.get-certificate [-d DOMAIN] [-m EMAIL] [-s SERVER]"
exit 0
;;
esac
Expand Down
35 changes: 33 additions & 2 deletions src/mastodon/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
. "$SNAP/postgres.env"
. "$SNAP/redis.env"
. "$SNAP/nginx.env"
. "$SNAP/acme.env"

check_root

Expand All @@ -12,7 +13,7 @@ if mastodon_config_exists; then
exit 0
fi

while getopts "d:u:m:h" OPTION; do
while getopts "d:u:m:c:s:h" OPTION; do
case "$OPTION" in
d)
if is_domain "$OPTARG"; then
Expand All @@ -37,8 +38,26 @@ while getopts "d:u:m:h" OPTION; do
echo "Invalid email '$OPTARG'"
fi
;;
c)
case "$OPTARG" in
true|yes)
GET_CERTIFICATE=true
;;
false|no)
GET_CERTIFICATE=false
;;
esac
;;
s)
if is_acme_server "$OPTARG"; then
snapctl set acme.server="$OPTARG"
export ACME_SERVER="$OPTARG"
else
echo "Invalid ACME server '$OPTARG'"
fi
;;
h)
echo "Usage: $SNAP_NAME.setup [-d DOMAIN] [-u USERNAME] [-m EMAIL]"
echo "Usage: $SNAP_NAME.setup [-d DOMAIN] [-u USERNAME] [-m EMAIL] [-c GET_CERTIFICATE] [-s SERVER]"
exit 0
;;
esac
Expand Down Expand Up @@ -68,6 +87,18 @@ fi
echo Create admin account
$SNAP/bin/tootctl.wrapper accounts create "$USERNAME" --email "$EMAIL" --role Owner --confirmed --approve

if [ -z "$GET_CERTIFICATE" ]; then
if confirm "Get a certificate now?"; then
GET_CERTIFICATE=true
fi
fi
if [ "$GET_CERTIFICATE" == true ]; then
if ! [ -z "$SERVER" ]; then
SERVER_FLAG="-s $SERVER"
fi
$SNAP/bin/get-certificate -d $DOMAIN -m $EMAIL $SERVER_FLAG
fi

$SNAP/bin/recompile_if_required

echo Restart services
Expand Down

0 comments on commit 01ca003

Please sign in to comment.