From 2fbdac891b79259043f774cc16c1ec1df3c7dee6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 26 Jan 2016 15:26:17 +0000 Subject: [PATCH] trove command --- man/freedombone-trove.1.gz | Bin 0 -> 728 bytes src/freedombone | 41 +++++-- src/freedombone-archive-mail | 2 +- src/freedombone-backup-local | 2 +- src/freedombone-backup-remote | 4 +- src/freedombone-controlpanel | 2 +- src/freedombone-restore-local | 22 ++-- src/freedombone-restore-remote | 20 +-- src/freedombone-trove | 217 +++++++++++++++++++++++++++++++++ 9 files changed, 273 insertions(+), 37 deletions(-) create mode 100644 man/freedombone-trove.1.gz create mode 100755 src/freedombone-trove diff --git a/man/freedombone-trove.1.gz b/man/freedombone-trove.1.gz new file mode 100644 index 0000000000000000000000000000000000000000..db00e97233584e79aa55cbdfe1d263d0debc3fba GIT binary patch literal 728 zcmV;}0w?_+iwFROi>Foq1FchEZ__XkfA^<2<%JiT!jKSD2xv!X3+q}nDbpAea*|79 zmiQvuSyzb<&&7$lO@lY0Je|*Xzkd$nIphX0qbebd183+K;Uxqoui=Z-aPs2i>i`1& zKi_x3)}nc4VJUSZ%Rq=QnnQ3tUQPq?bl8sp%*i^~DF+5?val~yT7WAMYD2#;b&z3= zI#C)-domfHRd7`uo|Xq1 z_i%MU`&-j>zxUHLI^8VR@nUrzh`3Pp3B;x*4H9%yC1`+hz&nRV%krL}a>P(<2p5HP zpmL^479X9#9u0ycNDHZV_#DW06PR=UH4 z+OdaJc>ui0DZK-B=vJk?C^;N!t>RWzJrWkXoyZ*a8WOq-Vd2`#n2e3c>R7XS`W`oBmvn zqv&F_`4qs=5V_$47-5?4#6xcVHZO*RE^jQ^!>7^ej^xFPe}ig40B z2|=|}r2h|v{+00~>jN{{&iGMp*mvU?|BeIa+SP?~wH*zIoZ+HLLJt0rDHJAsXvk1m z+Z;!YxAA)8mVO{E;t(7|*!DKl&NiUkBn%sWNax*W^=zE;m`t;^2s+i0cZFJ^uU0^cufEn-OUE&WD K@3Z7k1pol8n`i0( literal 0 HcmV?d00001 diff --git a/src/freedombone b/src/freedombone index d9abbe80..1c8a65dc 100755 --- a/src/freedombone +++ b/src/freedombone @@ -88,6 +88,13 @@ CONFIGURATION_FILE="${PROJECT_NAME}.cfg" SSH_PORT=2222 IRC_PORT=6697 +# password used for accessing your repo trove +MY_TROVE_PASSWORD= +# friend's repo trove +FRIENDS_TROVE_PASSWORD= +FRIENDS_TROVE_SERVER= +FRIENDS_TROVE_SSH_PORT= + # An optional password to log into IRC. This applies to all users IRC_PASSWORD= @@ -102,7 +109,7 @@ DDNS_USERNAME= DDNS_PASSWORD= CURRENT_DDNS_DOMAIN= -EXIM_ONION_REPO='https://github.com/petterreinholdtsen/exim4-smtorp' +EXIM_ONION_REPO="https://github.com/petterreinholdtsen/exim4-smtorp" NGINX_ENSITE_REPO="https://github.com/perusio/nginx_ensite" NGINX_ENSITE_COMMIT='fa4d72ce1c0a490442c8474e9c8dc21ed52c93d0' @@ -193,7 +200,7 @@ HUBZILLA_DOMAIN_NAME= HUBZILLA_CODE= HUBZILLA_ONION_PORT=8085 HUBZILLA_REPO="https://github.com/redmatrix/hubzilla.git" -HUBZILLA_THEMES_REPO='https://github.com/DeadSuperHero/redmatrix-themes' +HUBZILLA_THEMES_REPO="https://github.com/DeadSuperHero/redmatrix-themes" HUBZILLA_ADDONS_REPO="https://github.com/redmatrix/hubzilla-addons.git" HUBZILLA_ADMIN_PASSWORD= HUBZILLA_COMMIT='761afd029d97703f2f7609d546b7b5f3d257c601' @@ -428,8 +435,8 @@ BABEL_PORT=6696 ENABLE_SOCIAL_KEY_MANAGEMENT="no" TOX_PORT=33445 -TOX_REPO='git://github.com/irungentoo/toxcore.git' -TOXID_REPO='https://github.com/bashrc/toxid' +TOX_REPO="git://github.com/irungentoo/toxcore.git" +TOXID_REPO="https://github.com/bashrc/toxid" TOX_COMMIT='73b2144edcfd1ca617e9054479b66ab0c0361a14' TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt # These are some default nodes, but you can replace them with trusted nodes @@ -443,13 +450,13 @@ TOXIC_REPO="https://github.com/Tox/toxic" TOXIC_COMMIT='88270827a96b2082e254677f35585ed24581a42c' #ZERONET_REPO='https://github.com/HelloZeroNet/ZeroNet.git' -ZERONET_REPO='https://github.com/HelloZeroNet/ZeroNet.git' +ZERONET_REPO="https://github.com/HelloZeroNet/ZeroNet.git" ZERONET_COMMIT='675bd462556c541d65e2d95f91f899146a373aad' -ZERONET_BLOG_REPO='https://github.com/HelloZeroNet/ZeroBlog' +ZERONET_BLOG_REPO="https://github.com/HelloZeroNet/ZeroBlog" ZERONET_BLOG_COMMIT='bbb0d6c36465fed2e6df71f1aab45fcc9c6ad609' -ZERONET_MAIL_REPO='https://github.com/HelloZeroNet/ZeroMail' +ZERONET_MAIL_REPO="https://github.com/HelloZeroNet/ZeroMail" ZERONET_MAIL_COMMIT='955af09d643c72b02e4983d71eca5c0c93a6c131' -ZERONET_FORUM_REPO='https://github.com/HelloZeroNet/ZeroTalk' +ZERONET_FORUM_REPO="https://github.com/HelloZeroNet/ZeroTalk" ZERONET_FORUM_COMMIT='e2d2c9cb1cfbfef91b244935efb5c14c2ad95faa' ZERONET_URL=http://127.0.0.1:43110 ZERONET_PORT=15441 @@ -470,7 +477,7 @@ GPGIT_COMMIT='583dc76119f19420f8a33f606744faa7c8922738' DH_KEYLENGTH=2048 # repo for atheros AR9271 wifi driver -ATHEROS_WIFI_REPO='https://github.com/qca/open-ath9k-htc-firmware.git' +ATHEROS_WIFI_REPO="https://github.com/qca/open-ath9k-htc-firmware.git" # Whether Let's Encrypt is enabled for all sites LETSENCRYPT_ENABLED="no" @@ -916,6 +923,18 @@ function read_configuration { if [[ $CONFIGURATION_FILE != "/root/${PROJECT_NAME}.cfg" ]]; then cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg fi + if grep -q "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE; then + FRIENDS_TROVE_SERVER=$(grep "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE; then + FRIENDS_TROVE_SSH_PORT=$(grep "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "MY_TROVE_PASSWORD" $CONFIGURATION_FILE; then + MY_TROVE_PASSWORD=$(grep "MY_TROVE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE; then + FRIENDS_TROVE_PASSWORD=$(grep "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi if grep -q "PROJECT_WEBSITE" $CONFIGURATION_FILE; then PROJECT_WEBSITE=$(grep "PROJECT_WEBSITE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') fi @@ -4656,7 +4675,7 @@ function spam_filtering { echo '#!/bin/bash' > /usr/bin/filterspam echo 'for d in /home/*/ ; do' >> /usr/bin/filterspam echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/filterspam - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/filterspam + echo ' if [[ $USERNAME != "git" && $USERNAME != "trove" ]]; then' >> /usr/bin/filterspam echo ' MAILDIR=/home/$USERNAME/Maildir/.learn-spam' >> /usr/bin/filterspam echo ' if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterspam echo ' exit' >> /usr/bin/filterspam @@ -4678,7 +4697,7 @@ function spam_filtering { echo '#!/bin/bash' > /usr/bin/filterham echo 'for d in /home/*/ ; do' >> /usr/bin/filterham echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/filterham - echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/filterham + echo ' if [[ $USERNAME != "git" && $USERNAME != "trove" ]]; then' >> /usr/bin/filterham echo ' MAILDIR=/home/$USERNAME/Maildir/.learn-ham' >> /usr/bin/filterham echo ' if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterham echo ' exit' >> /usr/bin/filterham diff --git a/src/freedombone-archive-mail b/src/freedombone-archive-mail index df71e336..3b3d5b97 100755 --- a/src/freedombone-archive-mail +++ b/src/freedombone-archive-mail @@ -35,7 +35,7 @@ export TEXTDOMAINDIR="/usr/share/locale" for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USERNAME != "trove" ]]; then # for every user who has a mail directory if [ -d /home/$USERNAME/Maildir ]; then MUTTRC=/home/$USERNAME/.muttrc diff --git a/src/freedombone-backup-local b/src/freedombone-backup-local index 832fcae5..21ff7cfb 100755 --- a/src/freedombone-backup-local +++ b/src/freedombone-backup-local @@ -265,7 +265,7 @@ function backup_users { # Backup user files for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USERNAME != "trove" ]]; then # Backup any gpg keys if [ -d /home/$USERNAME/.gnupg ]; then diff --git a/src/freedombone-backup-remote b/src/freedombone-backup-remote index 1ab7b027..343d72ca 100755 --- a/src/freedombone-backup-remote +++ b/src/freedombone-backup-remote @@ -178,7 +178,7 @@ function backup_configuration { function backup_users { for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USERNAME != "trove" ]]; then # personal settings if [ -d /home/$USERNAME/personal ]; then @@ -604,7 +604,7 @@ do # Social key management for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USERNAME != "trove" ]]; then disperse_key_shares $USERNAME $REMOTE_DOMAIN $REMOTE_SSH_PORT "$REMOTE_PASSWORD" $REMOTE_SERVER fi done diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel index 81e5a74f..e0426ef9 100755 --- a/src/freedombone-controlpanel +++ b/src/freedombone-controlpanel @@ -261,7 +261,7 @@ function show_users { echo '--------------------------------------------------------------------------' for d in /home/*/ ; do USRNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USRNAME != "git" ]]; then + if [[ $USRNAME != "git" && $USRNAME != "trove" ]]; then echo -n -e "$(pad_string ${USRNAME})" # get the SIP extension SIPEXT= diff --git a/src/freedombone-restore-local b/src/freedombone-restore-local index 4948fa54..ae75dda7 100755 --- a/src/freedombone-restore-local +++ b/src/freedombone-restore-local @@ -116,7 +116,7 @@ function unmount_drive { echo $"Setting permissions" for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then chown -R $USERNAME:$USERNAME /home/$USERNAME fi done @@ -356,7 +356,7 @@ function restore_mutt_settings { if [ -d $USB_MOUNT/backup/mutt ]; then for d in $USB_MOUNT/backup/mutt/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME fi @@ -388,7 +388,7 @@ function restore_gpg { if [ -d $USB_MOUNT/backup/gnupg ]; then for d in $USB_MOUNT/backup/gnupg/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME fi @@ -422,7 +422,7 @@ function restore_procmail { if [ -d $USB_MOUNT/backup/procmail ]; then for d in $USB_MOUNT/backup/procmail/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME fi @@ -449,7 +449,7 @@ function restore_spamassassin { if [ -d $USB_MOUNT/backup/spamassassin ]; then for d in $USB_MOUNT/backup/spamassassin/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $USB_MOUNT/backup/spamassassin/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -525,7 +525,7 @@ function restore_user_ssh_keys { if [ -d $USB_MOUNT/backup/ssh ]; then for d in $USB_MOUNT/backup/ssh/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME fi @@ -552,7 +552,7 @@ function restore_user_config { if [ -d $USB_MOUNT/backup/config ]; then for d in $USB_MOUNT/backup/config/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME fi @@ -622,7 +622,7 @@ function restore_personal_settings { if [ -d $USB_MOUNT/backup/personal ]; then for d in $USB_MOUNT/backup/personal/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $USB_MOUNT/backup/personal/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -739,7 +739,7 @@ function restore_owncloud { chown -R www-data:www-data /var/lib/owncloud/assets for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then occ files:scan $USERNAME fi done @@ -853,7 +853,7 @@ function restore_blog { fi for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post fi @@ -894,7 +894,7 @@ function restore_email { if [ -d $USB_MOUNT/backup/mail ]; then for d in $USB_MOUNT/backup/mail/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME fi diff --git a/src/freedombone-restore-remote b/src/freedombone-restore-remote index addc8f9c..5b7036cf 100755 --- a/src/freedombone-restore-remote +++ b/src/freedombone-restore-remote @@ -260,7 +260,7 @@ function restore_mutt_settings { fi for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -291,7 +291,7 @@ function restore_gpg { fi for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -323,7 +323,7 @@ function restore_procmail { fi for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -349,7 +349,7 @@ function restore_spamassassin { fi for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -411,7 +411,7 @@ function restore_ssh_keys { fi for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -437,7 +437,7 @@ function restore_user_config { fi for d in $SERVER_DIRECTORY/backup/config/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $SERVER_DIRECTORY/backup/config/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -504,7 +504,7 @@ function restore_personal_settings { fi for d in $SERVER_DIRECTORY/backup/personal/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME @@ -624,7 +624,7 @@ function restore_owncloud { chown -R www-data:www-data /var/lib/owncloud/assets for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then occ files:scan $USERNAME fi done @@ -733,7 +733,7 @@ function restore_blog { fi for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post fi @@ -825,7 +825,7 @@ function restore_email { fi for d in $SERVER_DIRECTORY/backup/mail/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" ]]; then + if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then if [ -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then ${PROJECT_NAME}-adduser $USERNAME diff --git a/src/freedombone-trove b/src/freedombone-trove new file mode 100755 index 00000000..01b85b9d --- /dev/null +++ b/src/freedombone-trove @@ -0,0 +1,217 @@ +#!/bin/bash +# +# .---. . . +# | | | +# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. +# | | (.-' (.-' ( | ( )| | | | )( )| | (.-' +# ' ' --' --' -' - -' ' ' -' -' -' ' - --' +# +# Freedom in the Cloud +# +# Host git repos which the project depends on +# +# License +# ======= +# +# Copyright (C) 2015-2016 Bob Mottram +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +PROJECT_NAME='freedombone' + +export TEXTDOMAIN=${PROJECT_NAME}-trove +export TEXTDOMAINDIR="/usr/share/locale" + +# Minimum number of characters in a password +MINIMUM_PASSWORD_LENGTH=10 + +CONFIGURATION_FILE="/root/${PROJECT_NAME}.cfg" + +# if this is blank then just use the default repos +FRIENDS_TROVE_SERVER= +REPOS= +TROVE_BASE=/home/trove/trove +MY_TROVE_PASSWORD= +FRIENDS_TROVE_PASSWORD= +NEW_TROVE='no' +FRIENDS_TROVE_SSH_PORT=2222 + +MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME} +if [ ! -f $MAIN_COMMAND ]; then + MAIN_COMMAND=/usr/bin/${PROJECT_NAME} +fi + +REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g')) + +# obtain the trove password if it exists +if [ -f $CONFIGURATION_FILE ]; then + if ! grep -q "MY_TROVE_PASSWORD" $CONFIGURATION_FILE; then + MY_TROVE_PASSWORD=$(grep "MY_TROVE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if ! grep -q "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE; then + FRIENDS_TROVE_SERVER=$(grep "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if ! grep -q "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE; then + FRIENDS_TROVE_PASSWORD=$(grep "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if ! grep -q "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE; then + FRIENDS_TROVE_SSH_PORT=$(grep "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi +fi + +function show_help { + echo '' + echo $"${PROJECT_NAME}-trove --sync [domain/url] -p [password]" + echo '' + echo $'Creates or syncs with a set of git repositories' + echo '' + echo $' --help Show help' + echo $' -n|--new [yes|no] Start a new trove' + echo $" -p|--password [yes|no] Friend's trove user password" + echo $" -m|--mypassword [yes|no] Local trove user password" + echo $" --port [number] Friend's server ssh port number" + echo $" -s|--sync [domain] Friend's server domain to sync with" + echo '' + exit 0 +} + +function create_trove_user { + if [ -d /home/trove ]; then + return + fi + + create_password='no' + if [ ! "$MY_TROVE_PASSWORD" ]; then + create_password='yes' + fi + if [ ${#MY_TROVE_PASSWORD} -lt ${MINIMUM_PASSWORD_LENGTH} ]; then + echo $'Password is too short. Creating new one.' + create_password='yes' + fi + + if [[ $create_password == 'yes' ]]; then + MY_TROVE_PASSWORD="$(openssl rand -base64 20 | cut -c1-18)" + fi + + useradd -m -p "$MY_TROVE_PASSWORD" -s /bin/bash trove + + # remove any existing user files + rm -rf /home/trove/* + + # store the trove password + if [ -f $CONFIGURATION_FILE ]; then + if ! grep -q "MY_TROVE_PASSWORD" $CONFIGURATION_FILE; then + echo "MY_TROVE_PASSWORD=$MY_TROVE_PASSWORD" >> $CONFIGURATION_FILE + else + sed -i "s|MY_TROVE_PASSWORD=.*|MY_TROVE_PASSWORD=${MY_TROVE_PASSWORD}|g" $CONFIGURATION_FILE + fi + fi +} + +function update_repos_from_friend { + if [ ! $FRIENDS_TROVE_SERVER ] then + return + fi + + new_repos=() + for line in "${REPOS[@]}" + do + repo_name=$(echo "$line" | awk -F '=' '{print $1}') + trove_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') + #repo_url=$(echo "$line" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') + friends_repo_url="ssh://trove@${FRIENDS_TROVE_SERVER}:${FRIENDS_TROVE_SSH_PORT}/home/trove/${trove_name}" + new_line="${repo_name}=\"${friends_repo_url}\"" + new_repos+=($new_line) + done + REPOS=("${new_repos[@]}") +} + +function sync_trove_repos { + for line in "${REPOS[@]}" + do + repo_name=$(echo "$line" | awk -F '=' '{print $1}') + repo_url=$(echo "$line" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') + trove_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') + if [[ $NEW_TROVE == 'yes' ]]; then + if [ -d /home/trove/${trove_name} ]; then + rm -rf /home/trove/${trove_name} + fi + fi + if [ ! -d /home/trove/${trove_name} ]; then + git clone --mirror ${repo_url} /home/trove/${trove_name} + if [ ! -d /home/trove/${trove_name} ]; then + echo $"WARNING: failed to mirror repo ${repo_url}" + fi + else + cd /home/trove/${trove_name} + git fetch -p origin + fi + done +} + +while [[ $# > 1 ]] +do +key="$1" + +case $key in + --help) + show_help + ;; + -s|--sync) + shift + # use repos on another server + FRIENDS_TROVE_SERVER="$1" + ;; + -m|--mypass|--mypassword) + shift + MY_TROVE_PASSWORD="$1" + if [ -f $CONFIGURATION_FILE ]; then + if ! grep -q "MY_TROVE_PASSWORD" $CONFIGURATION_FILE; then + echo "MY_TROVE_PASSWORD=$MY_TROVE_PASSWORD" >> $CONFIGURATION_FILE + else + sed -i "s|MY_TROVE_PASSWORD=.*|MY_TROVE_PASSWORD=${MY_TROVE_PASSWORD}|g" $CONFIGURATION_FILE + fi + fi + ;; + -p|--pass|--password) + shift + FRIENDS_TROVE_PASSWORD="$1" + if [ -f $CONFIGURATION_FILE ]; then + if ! grep -q "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE; then + echo "FRIENDS_TROVE_PASSWORD=$FRIENDS_TROVE_PASSWORD" >> $CONFIGURATION_FILE + else + sed -i "s|FRIENDS_TROVE_PASSWORD=.*|FRIENDS_TROVE_PASSWORD=${FRIENDS_TROVE_PASSWORD}|g" $CONFIGURATION_FILE + fi + fi + ;; + -n|--new) + shift + NEW_TROVE="$1" + ;; + --port) + shift + FRIENDS_TROVE_SSH_PORT=${1} + ;; + *) + # unknown option + ;; +esac +shift +done + +create_trove_user +update_repos_from_friend +sync_trove_repos + +exit 0