From 59e04ecfe276eb081f6d9ae13d4a8430ce72765c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 10 Oct 2016 10:28:37 +0100 Subject: [PATCH] Consolidate repo mirrors function --- src/freedombone-addcert | 45 +-------- src/freedombone-controlpanel | 39 -------- src/freedombone-upgrade | 45 +-------- src/freedombone-utils-repos | 175 ++++++++++++++++++----------------- 4 files changed, 98 insertions(+), 206 deletions(-) diff --git a/src/freedombone-addcert b/src/freedombone-addcert index 23bcc194..bb15f15e 100755 --- a/src/freedombone-addcert +++ b/src/freedombone-addcert @@ -36,7 +36,11 @@ export TEXTDOMAINDIR="/usr/share/locale" CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt -source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-git +UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-* +for f in $UTILS_FILES +do + source $f +done # Don't pin certs by default PIN_CERTS= @@ -60,45 +64,6 @@ FRIENDS_MIRRORS_PASSWORD= FRIENDS_MIRRORS_SSH_PORT= MY_MIRRORS_PASSWORD= -function read_repo_servers { - if [ -f $CONFIGURATION_FILE ]; then - if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then - MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - fi - - if [ ! $FRIENDS_MIRRORS_SERVER ]; then - return - fi - if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then - return - fi - - 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')) - - for line in "${REPOS[@]}" - do - repo_name=$(echo "$line" | awk -F '=' '{print $1}') - mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') - friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}" - ${repo_name}="${friends_repo_url}" - done -} - function show_help { echo '' echo $"${PROJECT_NAME}-addcert -h [hostname] -c [country code] -a [area] -l [location]" diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel index 8fe9811f..5c5853c0 100755 --- a/src/freedombone-controlpanel +++ b/src/freedombone-controlpanel @@ -154,45 +154,6 @@ function check_for_updates { any_key } -function read_repo_servers { - if [ -f $CONFIGURATION_FILE ]; then - if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then - MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - fi - - if [ ! $FRIENDS_MIRRORS_SERVER ]; then - return - fi - if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then - return - fi - - 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')) - - for line in "${REPOS[@]}" - do - repo_name=$(echo "$line" | awk -F '=' '{print $1}') - mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') - friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}" - ${repo_name}="${friends_repo_url}" - done -} - function set_main_repo { data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 diff --git a/src/freedombone-upgrade b/src/freedombone-upgrade index f09ff767..4ddcf4ea 100755 --- a/src/freedombone-upgrade +++ b/src/freedombone-upgrade @@ -42,46 +42,11 @@ FRIENDS_MIRRORS_SSH_PORT=2222 FRIENDS_MIRRORS_PASSWORD= MY_MIRRORS_PASSWORD= -source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-git - -function read_repo_servers { - if [ -f $CONFIGURATION_FILE ]; then - if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then - MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - fi - - if [ ! $FRIENDS_MIRRORS_SERVER ]; then - return - fi - if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then - return - fi - - 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')) - - for line in "${REPOS[@]}" - do - repo_name=$(echo "$line" | awk -F '=' '{print $1}') - mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') - friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}" - ${repo_name}="${friends_repo_url}" - done -} +UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-* +for f in $UTILS_FILES +do + source $f +done if [ -f $CONFIGURATION_FILE ]; then # read the location of the main project repo diff --git a/src/freedombone-utils-repos b/src/freedombone-utils-repos index 40aa6e25..4002cc8c 100755 --- a/src/freedombone-utils-repos +++ b/src/freedombone-utils-repos @@ -39,111 +39,112 @@ FRIENDS_MIRRORS_SERVER= FRIENDS_MIRRORS_SSH_PORT=2222 function create_repo_sources { - if grep -Fxq "create_repo_sources" $COMPLETION_FILE; then - return - fi - rm -rf /var/lib/apt/lists/* - apt-get clean + if grep -Fxq "create_repo_sources" $COMPLETION_FILE; then + return + fi + rm -rf /var/lib/apt/lists/* + apt-get clean - echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION} main" > /etc/apt/sources.list - echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION} main" >> /etc/apt/sources.list - echo '' >> /etc/apt/sources.list - echo "deb http://security.debian.org/ ${DEBIAN_VERSION}/updates main" >> /etc/apt/sources.list - echo "deb-src http://security.debian.org/ ${DEBIAN_VERSION}/updates main" >> /etc/apt/sources.list - echo '' >> /etc/apt/sources.list - echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-updates main" >> /etc/apt/sources.list - echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-updates main" >> /etc/apt/sources.list - echo '' >> /etc/apt/sources.list - echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> /etc/apt/sources.list - echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> /etc/apt/sources.list + echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION} main" > /etc/apt/sources.list + echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION} main" >> /etc/apt/sources.list + echo '' >> /etc/apt/sources.list + echo "deb http://security.debian.org/ ${DEBIAN_VERSION}/updates main" >> /etc/apt/sources.list + echo "deb-src http://security.debian.org/ ${DEBIAN_VERSION}/updates main" >> /etc/apt/sources.list + echo '' >> /etc/apt/sources.list + echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-updates main" >> /etc/apt/sources.list + echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-updates main" >> /etc/apt/sources.list + echo '' >> /etc/apt/sources.list + echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> /etc/apt/sources.list + echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> /etc/apt/sources.list - apt-get update - apt-get -y install apt-transport-https + apt-get update + apt-get -y install apt-transport-https - echo 'create_repo_sources' >> $COMPLETION_FILE + echo 'create_repo_sources' >> $COMPLETION_FILE } function read_repo_servers { - if [ -f $CONFIGURATION_FILE ]; then - if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then - MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then - FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi - fi + read_config_param FRIENDS_MIRRORS_SERVER + read_config_param FRIENDS_MIRRORS_SSH_PORT + read_config_param MY_MIRRORS_PASSWORD + read_config_param FRIENDS_MIRRORS_PASSWORD - if [ ! $FRIENDS_MIRRORS_SERVER ]; then - return - fi - if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then - return - fi + if [ ! $FRIENDS_MIRRORS_SERVER ]; then + return + fi + if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then + return + fi - MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME} - if [ ! -f $MAIN_COMMAND ]; then - MAIN_COMMAND=/usr/bin/${PROJECT_NAME} - fi + APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-* + for f in $APP_FILES + do + REPOS=($(cat ${f} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g')) + for line in "${REPOS[@]}" + do + repo_name=$(echo "$line" | awk -F '=' '{print $1}') + mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') + friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}" + export ${repo_name}="${friends_repo_url}" + done + done - REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g')) - - for line in "${REPOS[@]}" - do - repo_name=$(echo "$line" | awk -F '=' '{print $1}') - mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') - friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}" - ${repo_name}="${friends_repo_url}" - done + APP_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-* + for f in $APP_FILES + do + REPOS=($(cat ${f} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g')) + for line in "${REPOS[@]}" + do + repo_name=$(echo "$line" | awk -F '=' '{print $1}') + mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') + friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}" + export ${repo_name}="${friends_repo_url}" + done + done } # A command to create a git repository for a project function create_git_project { - if grep -Fxq "create_git_project" $COMPLETION_FILE; then - return - fi - apt-get -y install git + if grep -Fxq "create_git_project" $COMPLETION_FILE; then + return + fi + apt-get -y install git - echo '#!/bin/bash' > /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'GIT_PROJECT_NAME=$1' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'if [ ! $GIT_PROJECT_NAME ]; then' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo ' echo "Please specify a project name, without any spaces"' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo ' exit 1' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'fi' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'if [ ! -d /home/$USER/projects/$GIT_PROJECT_NAME ]; then' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo ' mkdir -p /home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'fi' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'cd /home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'git init --bare' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo -n 'echo "Your project has been created, ' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'use the following command to clone the repository"' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo -n " git clone ssh://$MY_USERNAME@$DEFAULT_DOMAIN_NAME:$SSH_PORT" >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo '/home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'exit 0' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND - chmod +x /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo '#!/bin/bash' > /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'GIT_PROJECT_NAME=$1' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'if [ ! $GIT_PROJECT_NAME ]; then' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo ' echo "Please specify a project name, without any spaces"' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo ' exit 1' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'fi' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'if [ ! -d /home/$USER/projects/$GIT_PROJECT_NAME ]; then' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo ' mkdir -p /home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'fi' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'cd /home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'git init --bare' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo -n 'echo "Your project has been created, ' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'use the following command to clone the repository"' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo -n " git clone ssh://$MY_USERNAME@$DEFAULT_DOMAIN_NAME:$SSH_PORT" >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo '/home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + echo 'exit 0' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND + chmod +x /usr/bin/$CREATE_GIT_PROJECT_COMMAND - echo 'create_git_project' >> $COMPLETION_FILE + echo 'create_git_project' >> $COMPLETION_FILE } function create_mirrors { - if [ -d /home/trove ]; then - userdel -r trove - fi - if grep -Fxq "create_mirrors" $COMPLETION_FILE; then - return - fi - ${PROJECT_NAME}-mirrors - echo 'create_mirrors' >> $COMPLETION_FILE + if [ -d /home/trove ]; then + userdel -r trove + fi + if grep -Fxq "create_mirrors" $COMPLETION_FILE; then + return + fi + ${PROJECT_NAME}-mirrors + echo 'create_mirrors' >> $COMPLETION_FILE } # NOTE: deliberately no exit 0