Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a7b04e7 authored by thilo's avatar thilo
Browse files

- added generic bootstrap

- modified commons to support input validation
parent efae5c53
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
#!/usr/bin/env bash

function getRandomString {
        LENGTH=$1
        cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $LENGTH | head -n 1
@@ -11,11 +12,22 @@ function replaceTokensWithRandomStrings {
        RANDOMPART=$(getRandomString $REPLACEMENT_LENGTH)
        echo "$INPUT" | sed "s/$TOBEREPLACED/$RANDOMPART/g"
}

function doReplacementIfNecessary {
    VALUE="$1"
    echo "$VALUE" | grep -q "@@@generate@@@" && replaceTokensWithRandomStrings "$VALUE" || echo "$VALUE"
}

function getValidationPattern {
    INPUT="$1"
    echo "$INPUT" | sed 's/^.*||||//g' | sed 's/;;;;.*$//g'
}

function getInputDirectionMessage {
    INPUT="$1"
    echo "$INPUT" | sed 's/^.*;;;;//g'
}

function generateEnvFile {
    QUESTFILE="$1"
    ANSWERFILE="$2"
@@ -23,15 +35,25 @@ function generateEnvFile {
    while read KEY VALUE; do
        PREVVALUE="$VALUE"
        VALUE=$(doReplacementIfNecessary "$VALUE")
        if [ "$PREVVALUE" = "$VALUE" ]
        if [[ "$PREVVALUE" = "$VALUE" ]]
        then
            if [[ "$#" -ne 1 ]]
            then
                DEFVAL=$(echo "$PREVVALUE" | grep -q ";default$" && echo "$PREVVALUE" | sed 's/;default$//g' || echo 0)
                if [[ "$DEFVAL" = "0" ]]
                then
                    PATTERN=$(getValidationPattern "$VALUE")
                    INPUT_DIRECTION=$(getInputDirectionMessage "$VALUE")
                    echo "$VALUE"
                    if [[ "$PATTERN$INPUT_DIRECTION" = "" ]]
                    then
                        read INPUT < /dev/tty
                    else
                        while [[ $(echo "$INPUT" | grep -q "$PATTERN" && echo ok || echo nok) = "nok" ]]; do
                            echo "$INPUT_DIRECTION"
                            read INPUT < /dev/tty
                         :; done
                    fi
                    echo "$KEY=$INPUT" >> "$ENVFILE"
                else
                    echo "$KEY=$DEFVAL" >> "$ENVFILE"
@@ -43,5 +65,5 @@ function generateEnvFile {
         else
            echo "$KEY=$VALUE" >> "$ENVFILE"
         fi
    :;done <<< "$(grep -v \# $QUESTFILE | sed '/^$/d'| sed 's/=/        /g')"
    :;done <<< "$(grep -v \# ${QUESTFILE} | sed '/^$/d'| sed 's/=/        /g')"
}
 No newline at end of file

bootstrap-generic.sh

0 → 100644
+34 −0
Original line number Diff line number Diff line
#!/bin/bash

if [[ $# -lt 1 ]]
then
    echo "Usage $0 <repo-url> [branch name]"
    exit 1
fi
REPO=$1
BRANCH="$2"
if [[ "$BRANCH" != "" ]]
then
    BRANCH="--branch $BRANCH"
fi
################################################################################
apt-get update && apt install -y --asume-yes true git salt-minion
################################################################################


# Clone repo
echo "Cloning repo .."
git -C /mnt clone ${REPO} ${BRANCH} repo-base
ln -s /mnt/repo-base /mnt/docker


# Init salt-minion (masterless)
cp /mnt/repo-base/deployment/salt/init-config/masterless.conf /etc/salt/minion.d/

# Run repo init (might run a few minutes)
echo "System update and packages installation .."
salt-call state.apply docker-compose


# init repo
cd /mnt/docker && bash init-repo.sh