diff --git a/bin/addDatabaseAndUser.sh b/bin/addDatabaseAndUser.sh new file mode 100755 index 0000000..1d5dc05 --- /dev/null +++ b/bin/addDatabaseAndUser.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# create random password + +if [ -z "$1" ] +then + echo "Missing arguments, exit" + exit 0 +fi + +PASSWDDBnoQoutes="$(openssl rand -base64 12)" +PASSWDDB="'$PASSWDDBnoQoutes'" +SITE=$1 + +MAINDB="${SITE}_db" +echo Database: $MAINDB +echo Username: $MAINDB +echo Password: $PASSWDDBnoQoutes +any="'%'" + +docker-compose exec mysql su -c 'apk add mysql-client' +docker-compose exec mysql su -c 'mysql -uroot -ppassword -e "CREATE DATABASE '${MAINDB}' /*\!40100 DEFAULT CHARACTER SET utf8 */;"' +docker-compose exec mysql su -c 'mysql -uroot -ppassword -e "CREATE USER '${MAINDB}'@${any} IDENTIFIED BY '${PASSWDDB}';"' +docker-compose exec mysql su -c 'mysql -uroot -ppassword -e "GRANT ALL PRIVILEGES ON '${MAINDB}'.* TO '${MAINDB}'@${any};"' +docker-compose exec mysql su -c "mysql -uroot -ppassword -e 'FLUSH PRIVILEGES;'" diff --git a/bin/addDomainFolders.sh b/bin/addDomainFolders.sh new file mode 100755 index 0000000..57a6059 --- /dev/null +++ b/bin/addDomainFolders.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +docker-compose exec litespeed su -s /bin/bash lsadm -c "cd /usr/local/lsws/conf && addDomainCtl.sh $1" +[ ! -d "./sites/$1" ] && mkdir -p ./sites/$1/{html,logs} + diff --git a/bin/container/addDomainCtl.sh b/bin/container/addDomainCtl.sh index 5fbac4a..b826bd3 100755 --- a/bin/container/addDomainCtl.sh +++ b/bin/container/addDomainCtl.sh @@ -1,5 +1,19 @@ #!/usr/bin/env bash +domain=${1//\./\\.} +#replace . with \. +#so example.com becomes example\.com, this is because in regex . is used for matching any character +#so the regex would match on example.com and example7com, because . matches on "7" +#httpd_conf=`cat httpd_config.conf` +check=$(perl -0777 -ne 'print $1 if /(^ member '$domain' \{.*[^}]*})/m' httpd_config.conf) +#check=$(perl -0777 -le "print $1 if /(^ member $domain \{.*[^}]*})/m" httpd_config.conf) +if [ ! -z "$check" ]; then + echo "# It appears the domain already exist, therefor we won\'t add it. Check the httpd_config.conf if you believe this is a mistake" + exit 0 +else + echo "# Domain has been added" +fi + perl -0777 -p -i -e 's/(vhTemplate centralConfigLog \{[^}]+)\}*(^.*listeners.*$)/\1$2 member '$1' { vhDomain '$1' diff --git a/bin/container/rmDomainCtl.sh b/bin/container/rmDomainCtl.sh index 20e9d1e..d6a4574 100755 --- a/bin/container/rmDomainCtl.sh +++ b/bin/container/rmDomainCtl.sh @@ -3,7 +3,16 @@ domain=${1//\./\\.} #replace . with \. #so example.com becomes example\.com, this is because in regex . is used for matching any character #so the regex would match on example.com and example7com, because . matches on "7" -perl -0777 -p -i.bak -e "s/(vhtemplate centralConfigLog \{[^}]+)*(^.*member "$domain" \{.*[^}]*})/\1#thislinewillbedeletedj98311/gmi" httpd_config.conf + +check=$(perl -0777 -ne 'print $1 if /(^ member '$domain' \{.*[^}]*})/m' httpd_config.conf) +if [ ! -z "$check" ]; then + echo "# Domain has been removed" +else + echo "# We couldn't find the domain you wanted to remove, is it already removed?. Check the httpd_config.conf if you believe this is a mistake" + exit 0; +fi + +perl -0777 -p -i.bak -e "s/(^ member $domain \{.*[^}]*})/#thislinewillbedeletedj98311/gmi" httpd_config.conf perl -i -ne '/#thislinewillbedeletedj98311/ or print' httpd_config.conf #aboves replaces the matched group with a string and random numbers, then second command searches for that string and deletes the line #if anyone can figure out how to do above in oneline, feel free to let us know diff --git a/bin/dev/list-flagged-files.sh b/bin/dev/list-flagged-files.sh new file mode 100755 index 0000000..bde4f25 --- /dev/null +++ b/bin/dev/list-flagged-files.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +git ls-files -v|grep '^S' diff --git a/bin/dev/no-skip-worktree-conf.sh b/bin/dev/no-skip-worktree-conf.sh new file mode 100755 index 0000000..9bf83e7 --- /dev/null +++ b/bin/dev/no-skip-worktree-conf.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +find conf -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd && git ls-files -z ${pwd} | xargs -0 git update-index --no-skip-worktree" \; diff --git a/bin/dev/skip-worktree-conf.sh b/bin/dev/skip-worktree-conf.sh new file mode 100755 index 0000000..18b1618 --- /dev/null +++ b/bin/dev/skip-worktree-conf.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +find conf -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd && git ls-files -z ${pwd} | xargs -0 git update-index --skip-worktree" \; + diff --git a/bin/downloadWP.sh b/bin/downloadWP.sh new file mode 100644 index 0000000..f74c47c --- /dev/null +++ b/bin/downloadWP.sh @@ -0,0 +1,36 @@ +#!/bin/bash +cd /var/www/vhosts/$1/html +if [ ! -f "./wp-config.php" ]; then + # su -s /bin/bash www-data -c + COUNTER=0 + until [ "$(curl -v mysql:3306 2>&1 | grep native)" ]; + do + echo "Counter: ${COUNTER}" + COUNTER=$((COUNTER+1)) + if [ ${COUNTER} = 10 ]; then + echo '--- MySQL is starting, please wait... ---' + elif [ ${COUNTER} = 100 ]; then + echo '--- MySQL is timeout, exit! ---' + exit 1 + fi + sleep 1 + done + wp core download \ + --allow-root \ + --force + first_www_uid=$(stat -c "%u" /var/www/vhosts/localhost) + first_www_gid=$(stat -c "%g" /var/www/vhosts/localhost) + chown $first_www_uid:$first_www_gid /var/www/vhosts/localhost -R + +fi + + +www_uid=$(stat -c "%u" /var/www/vhosts/localhost) +if [ ${www_uid} -eq 0 ]; then + #echo "./sites/localhost is owned by root, auto changing ownership of ./sites/localhost to uid 1000" + chown 1000:1000 /var/www/vhosts/localhost -R +fi + +echo "WordPress installation finished." +exec "$@" +