diff -r e7279b13a071 -r 44a8a36ca380 vcs-backup.sh --- a/vcs-backup.sh Mon Apr 22 11:24:43 2019 +0200 +++ b/vcs-backup.sh Mon Apr 22 12:00:35 2019 +0200 @@ -34,7 +34,7 @@ # This is an asynchronous message-driven shell script that runs distributed across two machines and four user accounts. You have been warned :-) -# Server-side configuration: +# Server-side configuration: / loadServerConfigFile() VCS_BACKUP_DATA_DIR="/mnt/data"; VCS_BACKUP_CURRENT_DIR="$VCS_BACKUP_DATA_DIR/current"; VCS_BACKUP_PUBLIC_DIR="$VCS_BACKUP_DATA_DIR/public"; @@ -46,6 +46,10 @@ VCS_BACKUP_USER="vcs-backup"; VCS_BACKUP_MANAGER="vcs-backup-manager"; +# Client-side configuration: / see loadClientConfigFile() +VCS_BACKUP_SERVER="$VCS_BACKUP_MANAGER@localhost"; +VCS_BACKUP_SSH_COMMAND=(ssh "$VCS_BACKUP_SERVER"); + # Installation – check and do it by hand: # There should be already mounted Btrfs at $VCS_BACKUP_DATA_DIR installInstructions() { @@ -73,6 +77,8 @@ # Environment: all # $1 = path to the config file loadConfigFile() { if [ -f "$1" ]; then . "$1"; fi } +loadClientConfigFile() { loadConfigFile ~/.config/vcs-backup/client.cfg; } +loadServerConfigFile() { loadConfigFile "/etc/vcs-backup/server.cfg"; } # Environment: server # $1 = URL @@ -98,7 +104,6 @@ # $4 = "clone" (optional), if present, will also clone the backup locally vcs_backup_public_clientSubmitBackupRequest() { if isValidTypeAndURL "$1" "$2"; then - loadConfigFile ~/.config/vcs-backup/client.cfg ${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverSubmitBackupRequest "$1" "$2" "$3" "$4" if [[ "$4" == "clone" ]]; then if [[ "$1" == "hg" ]]; then hg clone "ssh://${VCS_BACKUP_SERVER}/$VCS_BACKUP_CURRENT_DIR/$1/$(urlToRelativeDirectoryPath $2)"; @@ -115,7 +120,6 @@ # has same parameters as clientSubmitBackupRequest (see above) vcs_backup_public_serverSubmitBackupRequest() { if isValidTypeAndURL "$1" "$2"; then - loadConfigFile "/etc/vcs-backup/server.cfg"; relativePath=$1/$(urlToRelativeDirectoryPath "$2"); absolutePath="$VCS_BACKUP_CONFIG_DIR/$relativePath"; # TODO: stop if directory already exists / only add public link? @@ -200,7 +204,6 @@ # prints list of repositories in recfile format # usage example: vcs-backup.sh clientListRepositories | relpipe-in-recfile | relpipe-out-tabular vcs_backup_public_clientListRepositories() { - loadConfigFile ~/.config/vcs-backup/client.cfg; ${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverListRepositories; } @@ -323,6 +326,8 @@ # --- Single entry-point: -------------------------------------------------------------------------- +loadClientConfigFile; +loadServerConfigFile; PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"; PUBLIC_FUNCTION_PREFIX="vcs_backup_public_"; if type -t "$PUBLIC_FUNCTION_PREFIX$1" > /dev/null; then