mirror of
https://github.com/runcitadel/core.git
synced 2024-11-11 16:30:38 +00:00
New backup server (#43)
This commit is contained in:
parent
86c17c365e
commit
ce71560ef0
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# SPDX-FileCopyrightText: 2020 Umbrel. https://getumbrel.com
|
# SPDX-FileCopyrightText: 2020 Umbrel. https://getumbrel.com
|
||||||
|
# SPDX-FileCopyrightText: 2022 Citadel and contributors. https://runcitadel.space
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
@ -98,39 +99,19 @@ tar \
|
||||||
# --verbose \
|
# --verbose \
|
||||||
# --gzip
|
# --gzip
|
||||||
|
|
||||||
# Check if a file exists on Firebase by checking if
|
|
||||||
# "https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F<THE_FILE_NAME>?alt=media"
|
|
||||||
# returns a 200 response code.
|
|
||||||
#
|
|
||||||
check_if_exists() {
|
|
||||||
curl -s -o /dev/null -w "%{http_code}" \
|
|
||||||
-X GET \
|
|
||||||
"https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F${1}?alt=media"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Upload a file to Firebase Cloud Storage by uloading its name + a random ID.
|
|
||||||
# Before uploading, we need to check if a file with the same name already exists, and if it does, change the random ID.
|
|
||||||
# For example, if we want to upload a file named "<THE_FILE_NAME>" with the content AA, we'd use this command to upload:
|
|
||||||
# curl -X POST "https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F<THE_FILE_NAME>?alt=media" -d "AA" -H "Content-Type: text/plain"
|
|
||||||
# To check if a file exists, we can check if this endpoint returns an error 404:
|
|
||||||
# curl "https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F<THE_FILE_NAME>?alt=media"
|
|
||||||
# To download a file, we can the same endpoint
|
|
||||||
upload_file() {
|
upload_file() {
|
||||||
local file_to_send="${1}"
|
local file_to_send="${1}"
|
||||||
local file_name="${2}"
|
local backup_id="${2}"
|
||||||
# A random ID to avoid collisions
|
local upload_data=$(jq --null-input \
|
||||||
local random_id="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 60 ; echo '')"
|
--arg name "$backup_id" \
|
||||||
# Check if the file already exists
|
--arg data "$(base64 $file_to_send)" \
|
||||||
# While a file with the same name exists, we'll try to upload it with a different ID
|
'{"name": $name, "data": $data}')
|
||||||
while [[ $(check_if_exists "${file_name}-${random_id}") == "200" ]]; do
|
|
||||||
random_id="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 60 ; echo '')"
|
|
||||||
done
|
|
||||||
# Upload the file
|
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
"https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F${file_name}-${random_id}?alt=media" \
|
"https://account.runcitadel.space/api/upload" \
|
||||||
-d @"${file_to_send}" \
|
-d "${upload_data}" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/json" \
|
||||||
> /dev/null
|
--socks5 "localhost:${TOR_PROXY_PORT}" \
|
||||||
|
> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $BITCOIN_NETWORK == "testnet" ]]; then
|
if [[ $BITCOIN_NETWORK == "testnet" ]]; then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user