Move git functions to separate script

This commit is contained in:
Bob Mottram 2016-06-30 14:59:43 +01:00
parent 634773fcf6
commit 6f5f81d45c
No known key found for this signature in database
GPG Key ID: BA68F26108DC9F87
4 changed files with 240 additions and 384 deletions

View File

@ -37,6 +37,11 @@ export TEXTDOMAINDIR="/usr/share/locale"
DEFAULT_LANGUAGE=$(echo $LANG) DEFAULT_LANGUAGE=$(echo $LANG)
source /usr/local/bin/${PROJECT_NAME}-utils-git
if [ -f /usr/bin/${PROJECT_NAME}-utils-git ]; then
source /usr/bin/${PROJECT_NAME}-utils-git
fi
# username created by default within a debian image # username created by default within a debian image
GENERIC_IMAGE_USERNAME='fbone' GENERIC_IMAGE_USERNAME='fbone'
@ -618,61 +623,6 @@ function show_help {
exit 0 exit 0
} }
function git_clone {
repo_url="$1"
destination_dir="$2"
if [[ "$repo_url" == "ssh:"* ]]; then
if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
echo "sshpass -p \"$FRIENDS_MIRRORS_PASSWORD\" git clone $repo_url $destination_dir"
sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git clone "$repo_url" "$destination_dir"
return
fi
fi
fi
fi
fi
echo "git clone $repo_url $destination_dir"
git clone "$repo_url" "$destination_dir"
}
function git_pull {
if [ ! $1 ]; then
echo $'git_pull no repo specified'
fi
git stash
git remote set-url origin $1
git checkout master
if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git pull
if [ $2 ]; then
git checkout $2 -b $2
fi
return
fi
fi
fi
fi
git pull
if [ $2 ]; then
# delete any existing branch
git branch -D $2
# check out the new branch
git checkout $2 -b $2
if [ ! "$?" = "0" ]; then
echo $"Unable to checkout $1 $2"
exit 72357
fi
fi
}
function remove_database { function remove_database {
app_name="$1" app_name="$1"
if [ ! -d $INSTALL_DIR ]; then if [ ! -d $INSTALL_DIR ]; then

View File

@ -36,6 +36,11 @@ export TEXTDOMAINDIR="/usr/share/locale"
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
source /usr/local/bin/${PROJECT_NAME}-utils-git
if [ -f /usr/bin/${PROJECT_NAME}-utils-git ]; then
source /usr/bin/${PROJECT_NAME}-utils-git
fi
HOSTNAME= HOSTNAME=
LETSENCRYPT_HOSTNAME= LETSENCRYPT_HOSTNAME=
COUNTRY_CODE="US" COUNTRY_CODE="US"
@ -56,112 +61,66 @@ FRIENDS_MIRRORS_SSH_PORT=
MY_MIRRORS_PASSWORD= MY_MIRRORS_PASSWORD=
function read_repo_servers { function read_repo_servers {
if [ -f $CONFIGURATION_FILE ]; then if [ -f $CONFIGURATION_FILE ]; then
if grep -q "FRIENDS_MIRRORS_SERVER" $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}') FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi fi
if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then 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}') FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi fi
if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi fi
if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi fi
fi fi
if [ ! $FRIENDS_MIRRORS_SERVER ]; then if [ ! $FRIENDS_MIRRORS_SERVER ]; then
return return
fi fi
if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then
return return
fi fi
MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME} MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME}
if [ ! -f $MAIN_COMMAND ]; then if [ ! -f $MAIN_COMMAND ]; then
MAIN_COMMAND=/usr/bin/${PROJECT_NAME} MAIN_COMMAND=/usr/bin/${PROJECT_NAME}
fi fi
REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g')) REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g'))
for line in "${REPOS[@]}" for line in "${REPOS[@]}"
do do
repo_name=$(echo "$line" | awk -F '=' '{print $1}') repo_name=$(echo "$line" | awk -F '=' '{print $1}')
mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') 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}" friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}"
${repo_name}="${friends_repo_url}" ${repo_name}="${friends_repo_url}"
done done
}
function git_clone {
repo_url="$1"
destination_dir="$2"
if [[ "$repo_url" == "ssh:"* ]]; then
if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git clone "$repo_url" "$destination_dir"
return
fi
fi
fi
fi
fi
git clone "$repo_url" "$destination_dir"
}
function git_pull {
if [ ! $1 ]; then
echo $'git_pull no repo specified'
fi
git stash
git remote set-url origin $1
git checkout master
if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git pull
if [ $2 ]; then
git checkout $2 -b $2
fi
return
fi
fi
fi
fi
git pull
if [ $2 ]; then
git checkout $2 -b $2
fi
} }
function show_help { function show_help {
echo '' echo ''
echo $"${PROJECT_NAME}-addcert -h [hostname] -c [country code] -a [area] -l [location]" echo $"${PROJECT_NAME}-addcert -h [hostname] -c [country code] -a [area] -l [location]"
echo $' -o [organisation] -u [unit] --ca "" --nodh ""' echo $' -o [organisation] -u [unit] --ca "" --nodh ""'
echo '' echo ''
echo $'Creates a self-signed certificate for the given hostname' echo $'Creates a self-signed certificate for the given hostname'
echo '' echo ''
echo $' --help Show help' echo $' --help Show help'
echo $' -h --hostname [name] Hostname' echo $' -h --hostname [name] Hostname'
echo $' -e --letsencrypt [hostname] Hostname to use with Lets Encrypt' echo $' -e --letsencrypt [hostname] Hostname to use with Lets Encrypt'
echo $' -s --server [url] Lets Encrypt server URL' echo $' -s --server [url] Lets Encrypt server URL'
echo $' -c --country [code] Optional country code (eg. US, GB, etc)' echo $' -c --country [code] Optional country code (eg. US, GB, etc)'
echo $' -a --area [description] Optional area description' echo $' -a --area [description] Optional area description'
echo $' -l --location [locn] Optional location name' echo $' -l --location [locn] Optional location name'
echo $' -o --organisation [name] Optional organisation name' echo $' -o --organisation [name] Optional organisation name'
echo $' -u --unit [name] Optional unit name' echo $' -u --unit [name] Optional unit name'
echo $' --email [address] Email address for letsencrypt' echo $' --email [address] Email address for letsencrypt'
echo $' --dhkey [bits] DH key length in bits' echo $' --dhkey [bits] DH key length in bits'
echo $' --nodh "" Do not calculate DH params' echo $' --nodh "" Do not calculate DH params'
echo $' --ca "" Certificate authority cert' echo $' --ca "" Certificate authority cert'
echo '' echo ''
exit 0 exit 0
} }
while [[ $# > 1 ]] while [[ $# > 1 ]]
@ -169,217 +128,217 @@ do
key="$1" key="$1"
case $key in case $key in
--help) --help)
show_help show_help
;; ;;
-h|--hostname) -h|--hostname)
shift shift
HOSTNAME="$1" HOSTNAME="$1"
;; ;;
-e|--letsencrypt) -e|--letsencrypt)
shift shift
LETSENCRYPT_HOSTNAME="$1" LETSENCRYPT_HOSTNAME="$1"
;; ;;
--email) --email)
shift shift
MY_EMAIL_ADDRESS="$1" MY_EMAIL_ADDRESS="$1"
;; ;;
-s|--server) -s|--server)
shift shift
LETSENCRYPT_SERVER="$1" LETSENCRYPT_SERVER="$1"
;; ;;
-c|--country) -c|--country)
shift shift
COUNTRY_CODE="$1" COUNTRY_CODE="$1"
;; ;;
-a|--area) -a|--area)
shift shift
AREA="$1" AREA="$1"
;; ;;
-l|--location) -l|--location)
shift shift
LOCATION="$1" LOCATION="$1"
;; ;;
-o|--organisation) -o|--organisation)
shift shift
ORGANISATION="$1" ORGANISATION="$1"
;; ;;
-u|--unit) -u|--unit)
shift shift
UNIT="$1" UNIT="$1"
;; ;;
--ca) --ca)
shift shift
EXTENSIONS="-extensions v3_ca" EXTENSIONS="-extensions v3_ca"
ORGANISATION="Freedombone-CA" ORGANISATION="Freedombone-CA"
;; ;;
--nodh) --nodh)
shift shift
NODH="true" NODH="true"
;; ;;
--dhkey) --dhkey)
shift shift
DH_KEYLENGTH=${1} DH_KEYLENGTH=${1}
;; ;;
*) *)
# unknown option # unknown option
;; ;;
esac esac
shift shift
done done
if [ ! $HOSTNAME ]; then if [ ! $HOSTNAME ]; then
if [ ! $LETSENCRYPT_HOSTNAME ]; then if [ ! $LETSENCRYPT_HOSTNAME ]; then
echo $'No hostname specified' echo $'No hostname specified'
exit 5748 exit 5748
fi fi
fi fi
if ! which openssl > /dev/null ;then if ! which openssl > /dev/null ;then
echo $"$0: openssl is not installed, exiting" 1>&2 echo $"$0: openssl is not installed, exiting" 1>&2
exit 5689 exit 5689
fi fi
if [ ! -d /etc/ssl/mycerts ]; then if [ ! -d /etc/ssl/mycerts ]; then
mkdir /etc/ssl/mycerts mkdir /etc/ssl/mycerts
fi fi
CERTFILE=$HOSTNAME CERTFILE=$HOSTNAME
function add_cert_letsencrypt { function add_cert_letsencrypt {
CERTFILE=$LETSENCRYPT_HOSTNAME CERTFILE=$LETSENCRYPT_HOSTNAME
# obtain the email address for the admin user # obtain the email address for the admin user
if [ ! $MY_EMAIL_ADDRESS ]; then if [ ! $MY_EMAIL_ADDRESS ]; then
if [ -f $CONFIGURATION_FILE ]; then if [ -f $CONFIGURATION_FILE ]; then
if grep -q "MY_EMAIL_ADDRESS=" $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}') MY_EMAIL_ADDRESS=$(cat $CONFIGURATION_FILE | grep "MY_EMAIL_ADDRESS=" | awk -F '=' '{print $2}')
fi fi
fi fi
fi fi
if [ ! $MY_EMAIL_ADDRESS ]; then if [ ! $MY_EMAIL_ADDRESS ]; then
if [ -f $COMPLETION_FILE ]; then if [ -f $COMPLETION_FILE ]; then
if grep -q "Admin user:" $COMPLETION_FILE; then if grep -q "Admin user:" $COMPLETION_FILE; then
ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME
fi fi
fi fi
fi fi
if [ ! -d $INSTALL_DIR ]; then if [ ! -d $INSTALL_DIR ]; then
mkdir -p $INSTALL_DIR mkdir -p $INSTALL_DIR
fi fi
cd $INSTALL_DIR cd $INSTALL_DIR
# obtain the repo # obtain the repo
if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then 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 if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then
exit 76283 exit 76283
fi fi
else else
cd ${INSTALL_DIR}/letsencrypt cd ${INSTALL_DIR}/letsencrypt
git_pull $LETSENCRYPT_REPO git_pull $LETSENCRYPT_REPO
fi fi
# stop the web server # stop the web server
systemctl stop nginx systemctl stop nginx
cd ${INSTALL_DIR}/letsencrypt cd ${INSTALL_DIR}/letsencrypt
./letsencrypt-auto certonly --server $LETSENCRYPT_SERVER --standalone -d $LETSENCRYPT_HOSTNAME --renew-by-default --agree-tos --email $MY_EMAIL_ADDRESS ./letsencrypt-auto certonly --server $LETSENCRYPT_SERVER --standalone -d $LETSENCRYPT_HOSTNAME --renew-by-default --agree-tos --email $MY_EMAIL_ADDRESS
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $"Failed to install letsencrypt for domain $LETSENCRYPT_HOSTNAME" echo $"Failed to install letsencrypt for domain $LETSENCRYPT_HOSTNAME"
systemctl start nginx systemctl start nginx
exit 63216 exit 63216
fi fi
# replace some legacy filenames # replace some legacy filenames
if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt ]; then if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt ]; then
mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
fi fi
if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt ]; then if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt ]; then
mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
fi fi
sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME
sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME
# link the private key # link the private key
if [ -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key ]; then if [ -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key ]; then
if [ ! -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old ]; then if [ ! -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old ]; then
mv /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old mv /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old
else else
rm -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key rm -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
fi fi
fi fi
ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/privkey.pem /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/privkey.pem /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
# link the public key # link the public key
if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem ]; then if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem ]; then
if [ ! -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old ]; then if [ ! -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old ]; then
mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old
else else
rm -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem rm -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
fi fi
fi fi
ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
cp /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/mycerts/${LETSENCRYPT_HOSTNAME}.pem cp /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/mycerts/${LETSENCRYPT_HOSTNAME}.pem
systemctl start nginx systemctl start nginx
${PROJECT_NAME}-pin-cert $LETSENCRYPT_HOSTNAME ${PROJECT_NAME}-pin-cert $LETSENCRYPT_HOSTNAME
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $"Certificate for $LETSENCRYPT_HOSTNAME could not be pinned" echo $"Certificate for $LETSENCRYPT_HOSTNAME could not be pinned"
exit 62878 exit 62878
fi fi
} }
function add_cert_selfsigned { function add_cert_selfsigned {
if [[ $ORGANISATION == "Freedombone-CA" ]]; then if [[ $ORGANISATION == "Freedombone-CA" ]]; then
CERTFILE="ca-$HOSTNAME" CERTFILE="ca-$HOSTNAME"
fi fi
openssl req -x509 ${EXTENSIONS} -nodes -days 3650 -sha256 \ openssl req -x509 ${EXTENSIONS} -nodes -days 3650 -sha256 \
-subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \ -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
-newkey rsa:4096 -keyout /etc/ssl/private/${CERTFILE}.key \ -newkey rsa:4096 -keyout /etc/ssl/private/${CERTFILE}.key \
-out /etc/ssl/certs/${CERTFILE}.crt -out /etc/ssl/certs/${CERTFILE}.crt
chmod 400 /etc/ssl/private/${CERTFILE}.key chmod 400 /etc/ssl/private/${CERTFILE}.key
chmod 640 /etc/ssl/certs/${CERTFILE}.crt chmod 640 /etc/ssl/certs/${CERTFILE}.crt
cp /etc/ssl/certs/${CERTFILE}.crt /etc/ssl/mycerts cp /etc/ssl/certs/${CERTFILE}.crt /etc/ssl/mycerts
${PROJECT_NAME}-pin-cert $CERTFILE ${PROJECT_NAME}-pin-cert $CERTFILE
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $"Certificate for $CERTFILE could not be pinned" echo $"Certificate for $CERTFILE could not be pinned"
exit 62879 exit 62879
fi fi
} }
function generate_dh_params { function generate_dh_params {
if [ ! $NODH ]; then if [ ! $NODH ]; then
if [ ! -f /etc/ssl/certs/${CERTFILE}.dhparam ]; then if [ ! -f /etc/ssl/certs/${CERTFILE}.dhparam ]; then
${PROJECT_NAME}-dhparam -h ${CERTFILE} --fast yes ${PROJECT_NAME}-dhparam -h ${CERTFILE} --fast yes
fi fi
fi fi
} }
function restart_web_server { function restart_web_server {
if [ -f /etc/init.d/nginx ]; then if [ -f /etc/init.d/nginx ]; then
/etc/init.d/nginx reload /etc/init.d/nginx reload
fi fi
} }
function make_cert_bundle { function make_cert_bundle {
# Create a bundle of your certificates # Create a bundle of your certificates
cat /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem > /etc/ssl/${PROJECT_NAME}-bundle.crt cat /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem > /etc/ssl/${PROJECT_NAME}-bundle.crt
tar -czvf /etc/ssl/${PROJECT_NAME}-certs.tar.gz /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem tar -czvf /etc/ssl/${PROJECT_NAME}-certs.tar.gz /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem
} }
function create_cert { function create_cert {
if [ $LETSENCRYPT_HOSTNAME ]; then if [ $LETSENCRYPT_HOSTNAME ]; then
add_cert_letsencrypt add_cert_letsencrypt
else else
add_cert_selfsigned add_cert_selfsigned
fi fi
} }
read_repo_servers read_repo_servers

View File

@ -77,6 +77,11 @@ INSTALL_DIR=$HOME/build
MESH_INSTALL_DIR=/var/lib MESH_INSTALL_DIR=/var/lib
source /usr/local/bin/${PROJECT_NAME}-utils-git
if [ -f /usr/bin/${PROJECT_NAME}-utils-git ]; then
source /usr/bin/${PROJECT_NAME}-utils-git
fi
function show_help { function show_help {
echo '' echo ''
echo $"${PROJECT_NAME}-mesh-install -f [function] -r [rootdir]" echo $"${PROJECT_NAME}-mesh-install -f [function] -r [rootdir]"
@ -91,23 +96,6 @@ function show_help {
exit 0 exit 0
} }
function git_clone {
repo_url="$1"
destination_dir="$2"
if [[ "$repo_url" == "ssh:"* ]]; then
if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git clone "$repo_url" "$destination_dir"
return
fi
fi
fi
fi
fi
git clone "$repo_url" "$destination_dir"
}
function mesh_babel { function mesh_babel {
$CHROOT_PREFIX apt-get -y install babeld $CHROOT_PREFIX apt-get -y install babeld

View File

@ -42,6 +42,11 @@ FRIENDS_MIRRORS_SSH_PORT=2222
FRIENDS_MIRRORS_PASSWORD= FRIENDS_MIRRORS_PASSWORD=
MY_MIRRORS_PASSWORD= MY_MIRRORS_PASSWORD=
source /usr/local/bin/${PROJECT_NAME}-utils-git
if [ -f /usr/bin/${PROJECT_NAME}-utils-git ]; then
source /usr/bin/${PROJECT_NAME}-utils-git
fi
function read_repo_servers { function read_repo_servers {
if [ -f $CONFIGURATION_FILE ]; then if [ -f $CONFIGURATION_FILE ]; then
if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then
@ -81,52 +86,6 @@ function read_repo_servers {
done done
} }
function git_clone {
repo_url="$1"
destination_dir="$2"
if [[ "$repo_url" == "ssh:"* ]]; then
if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git clone "$repo_url" "$destination_dir"
return
fi
fi
fi
fi
fi
git clone "$repo_url" "$destination_dir"
}
function git_pull {
if [ ! $1 ]; then
echo $'git_pull no repo specified'
fi
git stash
git remote set-url origin $1
git checkout master
if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git pull
if [ $2 ]; then
git checkout $2 -b $2
fi
return
fi
fi
fi
fi
git pull
if [ $2 ]; then
git checkout $2 -b $2
fi
}
if [ -f $CONFIGURATION_FILE ]; then if [ -f $CONFIGURATION_FILE ]; then
# read the location of the main project repo # read the location of the main project repo
if grep -q "PROJECT_REPO" $CONFIGURATION_FILE; then if grep -q "PROJECT_REPO" $CONFIGURATION_FILE; then