forked from superseriousbusiness/gotosocial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] add script to test import / export cycle of a gotosocial in…
…stance (superseriousbusiness#2693) * add script to test import / export cycle of a gotosocial instance * use suffix for setting mktemp file suffix
- Loading branch information
1 parent
9bf448b
commit 90dcc00
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
HOST='localhost:8080' | ||
ADDR='127.0.0.1' | ||
PORT='8080' | ||
DB=$(mktemp) | ||
STORAGE=$(mktemp -d) | ||
EXPORT="$(mktemp --suffix '.json')" | ||
|
||
_kill() { | ||
pid=$(pidof gotosocial) \ | ||
|| return # i.e. not running | ||
kill -$1 $pid | ||
} | ||
|
||
gotosocial() { | ||
env \ | ||
GTS_HOST=$HOST \ | ||
GTS_PROTOCOL='http' \ | ||
GTS_BIND_ADDRESS=$ADDR \ | ||
GTS_PORT=$PORT \ | ||
GTS_DB_TYPE='sqlite' \ | ||
GTS_DB_ADDRESS=$DB \ | ||
GTS_STORAGE_BACKEND='local' \ | ||
GTS_STORAGE_LOCAL_BASE_PATH=$STORAGE \ | ||
GTS_WEB_ASSET_BASE_DIR='./web/assets' \ | ||
GTS_WEB_TEMPLATE_BASE_DIR='./web/template' \ | ||
go run ./cmd/gotosocial ${@} | ||
} | ||
|
||
# Cleanup instance, database file, export file, storage on exit | ||
trap "_kill 9; rm -f $DB; rm -f $EXPORT; rm -rf $STORAGE" exit | ||
|
||
# Iterate list of usernames | ||
for username in scoobert \ | ||
shaggy \ | ||
daphne \ | ||
velma \ | ||
fred \ | ||
scrappy; do # hahaha | ||
|
||
# Create account for each username | ||
gotosocial admin account create \ | ||
--username ${username} \ | ||
--password 'sh1t_tiEr_Password Zomg123!' \ | ||
--email ${username}@example.com | ||
|
||
# Confirm each of the accounts | ||
gotosocial admin account confirm \ | ||
--username ${username} | ||
done | ||
|
||
# Ensure server runs once | ||
gotosocial server start & | ||
|
||
# Kill server | ||
sleep 5 | ||
_kill 15 | ||
sleep 5 | ||
|
||
# Export current gts database to file | ||
gotosocial admin export --path "$EXPORT" \ | ||
|| echo 'failed exporting to file' | ||
|
||
# Clear database | ||
rm -f $DB | ||
touch $DB | ||
|
||
# Import current gts database from file | ||
gotosocial admin import --path "$EXPORT" \ | ||
|| echo 'failed importing from file' | ||
|
||
# Ensure server can restart | ||
{ gotosocial server start \ | ||
|| echo 'post-import failure' | ||
} & | ||
|
||
# Kill server | ||
sleep 5 | ||
_kill 15 | ||
sleep 5 | ||
|
||
exit 0 |