trove command

This commit is contained in:
Bob Mottram 2016-01-26 15:26:17 +00:00
parent 24ca9594a5
commit 2fbdac891b
9 changed files with 273 additions and 37 deletions

BIN
man/freedombone-trove.1.gz Normal file

Binary file not shown.

View File

@ -88,6 +88,13 @@ CONFIGURATION_FILE="${PROJECT_NAME}.cfg"
SSH_PORT=2222 SSH_PORT=2222
IRC_PORT=6697 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 # An optional password to log into IRC. This applies to all users
IRC_PASSWORD= IRC_PASSWORD=
@ -102,7 +109,7 @@ DDNS_USERNAME=
DDNS_PASSWORD= DDNS_PASSWORD=
CURRENT_DDNS_DOMAIN= 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_REPO="https://github.com/perusio/nginx_ensite"
NGINX_ENSITE_COMMIT='fa4d72ce1c0a490442c8474e9c8dc21ed52c93d0' NGINX_ENSITE_COMMIT='fa4d72ce1c0a490442c8474e9c8dc21ed52c93d0'
@ -193,7 +200,7 @@ HUBZILLA_DOMAIN_NAME=
HUBZILLA_CODE= HUBZILLA_CODE=
HUBZILLA_ONION_PORT=8085 HUBZILLA_ONION_PORT=8085
HUBZILLA_REPO="https://github.com/redmatrix/hubzilla.git" 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_ADDONS_REPO="https://github.com/redmatrix/hubzilla-addons.git"
HUBZILLA_ADMIN_PASSWORD= HUBZILLA_ADMIN_PASSWORD=
HUBZILLA_COMMIT='761afd029d97703f2f7609d546b7b5f3d257c601' HUBZILLA_COMMIT='761afd029d97703f2f7609d546b7b5f3d257c601'
@ -428,8 +435,8 @@ BABEL_PORT=6696
ENABLE_SOCIAL_KEY_MANAGEMENT="no" ENABLE_SOCIAL_KEY_MANAGEMENT="no"
TOX_PORT=33445 TOX_PORT=33445
TOX_REPO='git://github.com/irungentoo/toxcore.git' TOX_REPO="git://github.com/irungentoo/toxcore.git"
TOXID_REPO='https://github.com/bashrc/toxid' TOXID_REPO="https://github.com/bashrc/toxid"
TOX_COMMIT='73b2144edcfd1ca617e9054479b66ab0c0361a14' TOX_COMMIT='73b2144edcfd1ca617e9054479b66ab0c0361a14'
TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt
# These are some default nodes, but you can replace them with trusted nodes # 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' 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_REPO="https://github.com/HelloZeroNet/ZeroNet.git"
ZERONET_COMMIT='675bd462556c541d65e2d95f91f899146a373aad' ZERONET_COMMIT='675bd462556c541d65e2d95f91f899146a373aad'
ZERONET_BLOG_REPO='https://github.com/HelloZeroNet/ZeroBlog' ZERONET_BLOG_REPO="https://github.com/HelloZeroNet/ZeroBlog"
ZERONET_BLOG_COMMIT='bbb0d6c36465fed2e6df71f1aab45fcc9c6ad609' 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_MAIL_COMMIT='955af09d643c72b02e4983d71eca5c0c93a6c131'
ZERONET_FORUM_REPO='https://github.com/HelloZeroNet/ZeroTalk' ZERONET_FORUM_REPO="https://github.com/HelloZeroNet/ZeroTalk"
ZERONET_FORUM_COMMIT='e2d2c9cb1cfbfef91b244935efb5c14c2ad95faa' ZERONET_FORUM_COMMIT='e2d2c9cb1cfbfef91b244935efb5c14c2ad95faa'
ZERONET_URL=http://127.0.0.1:43110 ZERONET_URL=http://127.0.0.1:43110
ZERONET_PORT=15441 ZERONET_PORT=15441
@ -470,7 +477,7 @@ GPGIT_COMMIT='583dc76119f19420f8a33f606744faa7c8922738'
DH_KEYLENGTH=2048 DH_KEYLENGTH=2048
# repo for atheros AR9271 wifi driver # 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 # Whether Let's Encrypt is enabled for all sites
LETSENCRYPT_ENABLED="no" LETSENCRYPT_ENABLED="no"
@ -916,6 +923,18 @@ function read_configuration {
if [[ $CONFIGURATION_FILE != "/root/${PROJECT_NAME}.cfg" ]]; then if [[ $CONFIGURATION_FILE != "/root/${PROJECT_NAME}.cfg" ]]; then
cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg
fi 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 if grep -q "PROJECT_WEBSITE" $CONFIGURATION_FILE; then
PROJECT_WEBSITE=$(grep "PROJECT_WEBSITE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') PROJECT_WEBSITE=$(grep "PROJECT_WEBSITE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi fi
@ -4656,7 +4675,7 @@ function spam_filtering {
echo '#!/bin/bash' > /usr/bin/filterspam echo '#!/bin/bash' > /usr/bin/filterspam
echo 'for d in /home/*/ ; do' >> /usr/bin/filterspam echo 'for d in /home/*/ ; do' >> /usr/bin/filterspam
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /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 ' MAILDIR=/home/$USERNAME/Maildir/.learn-spam' >> /usr/bin/filterspam
echo ' if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterspam echo ' if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterspam
echo ' exit' >> /usr/bin/filterspam echo ' exit' >> /usr/bin/filterspam
@ -4678,7 +4697,7 @@ function spam_filtering {
echo '#!/bin/bash' > /usr/bin/filterham echo '#!/bin/bash' > /usr/bin/filterham
echo 'for d in /home/*/ ; do' >> /usr/bin/filterham echo 'for d in /home/*/ ; do' >> /usr/bin/filterham
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /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 ' MAILDIR=/home/$USERNAME/Maildir/.learn-ham' >> /usr/bin/filterham
echo ' if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterham echo ' if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterham
echo ' exit' >> /usr/bin/filterham echo ' exit' >> /usr/bin/filterham

View File

@ -35,7 +35,7 @@ export TEXTDOMAINDIR="/usr/share/locale"
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') 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 # for every user who has a mail directory
if [ -d /home/$USERNAME/Maildir ]; then if [ -d /home/$USERNAME/Maildir ]; then
MUTTRC=/home/$USERNAME/.muttrc MUTTRC=/home/$USERNAME/.muttrc

View File

@ -265,7 +265,7 @@ function backup_users {
# Backup user files # Backup user files
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USERNAME != "trove" ]]; then
# Backup any gpg keys # Backup any gpg keys
if [ -d /home/$USERNAME/.gnupg ]; then if [ -d /home/$USERNAME/.gnupg ]; then

View File

@ -178,7 +178,7 @@ function backup_configuration {
function backup_users { function backup_users {
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USERNAME != "trove" ]]; then
# personal settings # personal settings
if [ -d /home/$USERNAME/personal ]; then if [ -d /home/$USERNAME/personal ]; then
@ -604,7 +604,7 @@ do
# Social key management # Social key management
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') 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 disperse_key_shares $USERNAME $REMOTE_DOMAIN $REMOTE_SSH_PORT "$REMOTE_PASSWORD" $REMOTE_SERVER
fi fi
done done

View File

@ -261,7 +261,7 @@ function show_users {
echo '--------------------------------------------------------------------------' echo '--------------------------------------------------------------------------'
for d in /home/*/ ; do for d in /home/*/ ; do
USRNAME=$(echo "$d" | awk -F '/' '{print $3}') USRNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USRNAME != "git" ]]; then if [[ $USRNAME != "git" && $USRNAME != "trove" ]]; then
echo -n -e "$(pad_string ${USRNAME})" echo -n -e "$(pad_string ${USRNAME})"
# get the SIP extension # get the SIP extension
SIPEXT= SIPEXT=

View File

@ -116,7 +116,7 @@ function unmount_drive {
echo $"Setting permissions" echo $"Setting permissions"
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
chown -R $USERNAME:$USERNAME /home/$USERNAME chown -R $USERNAME:$USERNAME /home/$USERNAME
fi fi
done done
@ -356,7 +356,7 @@ function restore_mutt_settings {
if [ -d $USB_MOUNT/backup/mutt ]; then if [ -d $USB_MOUNT/backup/mutt ]; then
for d in $USB_MOUNT/backup/mutt/*/ ; do for d in $USB_MOUNT/backup/mutt/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
@ -388,7 +388,7 @@ function restore_gpg {
if [ -d $USB_MOUNT/backup/gnupg ]; then if [ -d $USB_MOUNT/backup/gnupg ]; then
for d in $USB_MOUNT/backup/gnupg/*/ ; do for d in $USB_MOUNT/backup/gnupg/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
@ -422,7 +422,7 @@ function restore_procmail {
if [ -d $USB_MOUNT/backup/procmail ]; then if [ -d $USB_MOUNT/backup/procmail ]; then
for d in $USB_MOUNT/backup/procmail/*/ ; do for d in $USB_MOUNT/backup/procmail/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
@ -449,7 +449,7 @@ function restore_spamassassin {
if [ -d $USB_MOUNT/backup/spamassassin ]; then if [ -d $USB_MOUNT/backup/spamassassin ]; then
for d in $USB_MOUNT/backup/spamassassin/*/ ; do for d in $USB_MOUNT/backup/spamassassin/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $USB_MOUNT/backup/spamassassin/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -525,7 +525,7 @@ function restore_user_ssh_keys {
if [ -d $USB_MOUNT/backup/ssh ]; then if [ -d $USB_MOUNT/backup/ssh ]; then
for d in $USB_MOUNT/backup/ssh/*/ ; do for d in $USB_MOUNT/backup/ssh/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
@ -552,7 +552,7 @@ function restore_user_config {
if [ -d $USB_MOUNT/backup/config ]; then if [ -d $USB_MOUNT/backup/config ]; then
for d in $USB_MOUNT/backup/config/*/ ; do for d in $USB_MOUNT/backup/config/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi
@ -622,7 +622,7 @@ function restore_personal_settings {
if [ -d $USB_MOUNT/backup/personal ]; then if [ -d $USB_MOUNT/backup/personal ]; then
for d in $USB_MOUNT/backup/personal/*/ ; do for d in $USB_MOUNT/backup/personal/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $USB_MOUNT/backup/personal/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -739,7 +739,7 @@ function restore_owncloud {
chown -R www-data:www-data /var/lib/owncloud/assets chown -R www-data:www-data /var/lib/owncloud/assets
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
occ files:scan $USERNAME occ files:scan $USERNAME
fi fi
done done
@ -853,7 +853,7 @@ function restore_blog {
fi fi
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') 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 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 mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
fi fi
@ -894,7 +894,7 @@ function restore_email {
if [ -d $USB_MOUNT/backup/mail ]; then if [ -d $USB_MOUNT/backup/mail ]; then
for d in $USB_MOUNT/backup/mail/*/ ; do for d in $USB_MOUNT/backup/mail/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
fi fi

View File

@ -260,7 +260,7 @@ function restore_mutt_settings {
fi fi
for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -291,7 +291,7 @@ function restore_gpg {
fi fi
for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -323,7 +323,7 @@ function restore_procmail {
fi fi
for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -349,7 +349,7 @@ function restore_spamassassin {
fi fi
for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -411,7 +411,7 @@ function restore_ssh_keys {
fi fi
for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -437,7 +437,7 @@ function restore_user_config {
fi fi
for d in $SERVER_DIRECTORY/backup/config/*/ ; do for d in $SERVER_DIRECTORY/backup/config/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $SERVER_DIRECTORY/backup/config/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -504,7 +504,7 @@ function restore_personal_settings {
fi fi
for d in $SERVER_DIRECTORY/backup/personal/*/ ; do for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME
@ -624,7 +624,7 @@ function restore_owncloud {
chown -R www-data:www-data /var/lib/owncloud/assets chown -R www-data:www-data /var/lib/owncloud/assets
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then if [[ $USERNAME != "git" && $USRNAME != "trove" ]]; then
occ files:scan $USERNAME occ files:scan $USERNAME
fi fi
done done
@ -733,7 +733,7 @@ function restore_blog {
fi fi
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') 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 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 mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
fi fi
@ -825,7 +825,7 @@ function restore_email {
fi fi
for d in $SERVER_DIRECTORY/backup/mail/*/ ; do for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}') 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 $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME ${PROJECT_NAME}-adduser $USERNAME

217
src/freedombone-trove Executable file
View File

@ -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 <bob@robotics.uk.to>
#
# 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 <http://www.gnu.org/licenses/>.
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