diff --git a/src/freedombone-addcert b/src/freedombone-addcert index 3d211723..3bb1e5b1 100755 --- a/src/freedombone-addcert +++ b/src/freedombone-addcert @@ -33,7 +33,7 @@ PROJECT_NAME='freedombone' export TEXTDOMAIN=${PROJECT_NAME}-addcert export TEXTDOMAINDIR="/usr/share/locale" -CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg +CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt HOSTNAME= @@ -50,6 +50,30 @@ INSTALL_DIR=/root/build LETSENCRYPT_SERVER='https://acme-v01.api.letsencrypt.org/directory' LETSENCRYPT_REPO="https://github.com/letsencrypt/letsencrypt" MY_EMAIL_ADDRESS= +FRIENDS_TROVE_SERVER= +FRIENDS_TROVE_PASSWORD= + +if [ -f $CONFIGURATION_FILE ]; then + if grep -q "LETSENCRYPT_REPO" $CONFIGURATION_FILE; then + LETSENCRYPT_REPO=$(grep "LETSENCRYPT_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "LETSENCRYPT_SERVER" $CONFIGURATION_FILE; then + LETSENCRYPT_SERVER=$(grep "LETSENCRYPT_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + + # use a trove? + if ! grep -q "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE; then + FRIENDS_TROVE_SERVER=$(grep "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + FRIENDS_TROVE_SSH_PORT=2222 + 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 + LETSENCRYPT_REPO="ssh://trove@${FRIENDS_TROVE_SERVER}:${FRIENDS_TROVE_SSH_PORT}/home/trove/letsencrypt" + fi +fi function show_help { echo '' @@ -157,14 +181,32 @@ fi CERTFILE=$HOSTNAME +function git_clone { + repo_url="$1" + destination_dir="$2" + if [[ "$repo_url" == "ssh:"* ]]; then + if [ "${FRIENDS_TROVE_SERVER}" ]; then + if [ ${#FRIENDS_TROVE_SERVER} -gt 2 ]; then + if [ "$FRIENDS_TROVE_PASSWORD" ]; then + if [ ${#FRIENDS_TROVE_PASSWORD} -gt 2 ]; then + sshpass -p "$FRIENDS_TROVE_PASSWORD" git clone "$repo_url" "$destination_dir" + return + fi + fi + fi + fi + fi + git clone "$repo_url" "$destination_dir" +} + function add_cert_letsencrypt { CERTFILE=$LETSENCRYPT_HOSTNAME # obtain the email address for the admin user if [ ! $MY_EMAIL_ADDRESS ]; then - if [ -f $CONFIG_FILE ]; then - if grep -q "MY_EMAIL_ADDRESS=" $CONFIG_FILE; then - MY_EMAIL_ADDRESS=$(cat $CONFIG_FILE | grep "MY_EMAIL_ADDRESS=" | awk -F '=' '{print $2}') + if [ -f $CONFIGURATION_FILE ]; then + if grep -q "MY_EMAIL_ADDRESS=" $CONFIGURATION_FILE; then + MY_EMAIL_ADDRESS=$(cat $CONFIGURATION_FILE | grep "MY_EMAIL_ADDRESS=" | awk -F '=' '{print $2}') fi fi fi @@ -184,7 +226,7 @@ function add_cert_letsencrypt { # obtain the repo if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then - git clone $LETSENCRYPT_REPO ${INSTALL_DIR}/letsencrypt + git_clone $LETSENCRYPT_REPO ${INSTALL_DIR}/letsencrypt if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then exit 76283 fi