Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/repo refresh option #251

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ MAIL_SMTP_HOST=
MAIL_SMTP_PORT=
MAIL_SMTP_LOGIN=
MAIL_SMTP_PWD=
MAIL_REJECT_SELFSIGNED_TLS=
MAIL_REJECT_SELFSIGNED_TLS=

# Misc
AUTO_REFRESH=false # Set to "true" if you want to refresh the UI Metadata after any borg serve finished
14 changes: 14 additions & 0 deletions docker/docker-bw-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,26 @@ check_env() {
fi
}

check_auto_refresh() {
if [ -z "$AUTO_REFRESH" ]; then
AUTO_REFRESH="false"
export AUTO_REFRESH
fi

if [ "$AUTO_REFRESH" = "true" ]; then
sed -ri "/command=\".*${repositoryName}.*\",restrict/ {/\;\/bin\/bash \/home\/borgwarehouse\/app\/helpers\/shells\/cronjob\.sh\",restrict/! s/\",restrict/;\/bin\/bash \/home\/borgwarehouse\/app\/helpers\/shells\/cronjob\.sh\",restrict/}" "$AUTHORIZED_KEYS_FILE"
else
sed -ri "/command=\".*${repositoryName}.*\",restrict/ s/;\/bin\/bash \/home\/borgwarehouse\/app\/helpers\/shells\/cronjob.sh//g" "$AUTHORIZED_KEYS_FILE"
fi
}

check_env
init_ssh_server
check_ssh_directory
create_authorized_keys_file
check_repos_directory
get_SSH_fingerprints
check_auto_refresh

print_green "Successful initialization. BorgWarehouse is ready !"
exec supervisord -c /home/borgwarehouse/app/supervisord.conf
9 changes: 8 additions & 1 deletion helpers/shells/createRepo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ else
appendOnlyMode=""
fi

# Refresh Mode
if [ "$AUTO_REFRESH" == "true" ]; then
autoRefresh=";/bin/bash /home/borgwarehouse/app/helpers/shells/cronjob.sh"
else
autoRefresh=""
fi

## Add ssh public key in authorized_keys with borg restriction for only 1 repository and storage quota
restricted_authkeys="command=\"cd ${pool};borg serve${appendOnlyMode} --restrict-to-path ${pool}/${repositoryName} --storage-quota $2G\",restrict $1"
restricted_authkeys="command=\"cd ${pool};borg serve${appendOnlyMode} --restrict-to-path ${pool}/${repositoryName} --storage-quota $2G${autoRefresh}\",restrict $1"
echo "$restricted_authkeys" | tee -a "${authorized_keys}" >/dev/null

## Return the repositoryName
Expand Down
9 changes: 9 additions & 0 deletions helpers/shells/cronjob.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash bash

# This shell can be called to execute all cronjobs to refresh the instance
# This may be enabled as a setting to refresh the storage used after any borg serve command finishes

source /home/borgwarehouse/app/.env

curl --request POST --url "${NEXTAUTH_URL}/api/cronjob/checkStatus" --header "Authorization: Bearer ${CRONJOB_KEY}"
curl --request POST --url "${NEXTAUTH_URL}/api/cronjob/getStorageUsed" --header "Authorization: Bearer ${CRONJOB_KEY}"