| 
					
				 | 
			
			
				@@ -10,7 +10,7 @@ mkdir -p /run/wordpress/sessions 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # seem to leave the old wp_ tables behind. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 table_prefix=$(mysql --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD} --host=${MYSQL_HOST} ${MYSQL_DATABASE} -e 'SHOW TABLES' --batch 2>/dev/null | sed -n 's/\(.*_\)usermeta/\1/p' | grep -v ^wp_ | head -n1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 [[ -n "${table_prefix}" ]] || table_prefix="wp_" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-echo "Using table prefix ${table_prefix}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+echo "==> Using table prefix ${table_prefix}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # Settings to be updated on every run. Regenerating salts means users have to relogin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 sed -e "s/##MYSQL_DATABASE/${MYSQL_DATABASE}/" \ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -33,18 +33,19 @@ sed -e "s/##MYSQL_DATABASE/${MYSQL_DATABASE}/" \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 memory_limit=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) # this is the RAM. we have equal amount of swap 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 concurrency=$((memory_limit*2/1024/1024/50)) # wp has 40MB limit. 10MB to accomodate some leaks 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-echo "Setting max requests to ${concurrency}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+echo "==> Setting max requests to ${concurrency}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 sed -e "s/MaxRequestWorkers.*/MaxRequestWorkers ${concurrency}/" /etc/apache2/mods-available/mpm_prefork.conf.template > /run/wordpress/mpm_prefork.conf 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # Used for wp rewrite 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 touch /app/data/htaccess 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 if [[ ! -f "/app/data/.dbsetup" ]]; then 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    echo "Copying wp-content files on first run" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    echo "==> Copying wp-content files on first run" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     mkdir -p /app/data/wp-content/mu-plugins 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     cp -r /app/code/wp-content-vanilla/* /app/data/wp-content/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    admin_password="changeme" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # note: we cannot delete the admin user in ldap mode because the default posts are assigned to that user 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    admin_password=$([[ -n "${LDAP_SERVER:-}" ]] && pwgen -1y 16 || echo "changeme") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     admin_email="admin@cloudron.local" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # --skip-email is part of 0.23.0 https://github.com/wp-cli/wp-cli/pull/2345 and https://github.com/wp-cli/wp-cli/issues/1164 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -54,7 +55,7 @@ if [[ ! -f "/app/data/.dbsetup" ]]; then 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         --admin_user=admin \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         --admin_password="${admin_password}" \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         --admin_email="${admin_email}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    echo "WP is now installed" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    echo "==> WP is now installed" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # Set default post structure to what most people want 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # Curiously, installing some plugins prevents .htaccess getting written 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -63,7 +64,7 @@ if [[ ! -f "/app/data/.dbsetup" ]]; then 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     touch "/app/data/.dbsetup" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # Update wordpress 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    echo "Updating wordpress database" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    echo "==> Updating wordpress database" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $WP core update-db 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 fi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -71,7 +72,7 @@ fi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # sadly mu-plugins can still be re-configured, just not uninstallable 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # We have to do this on every run to get plugin updates 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 if [[ ! -f "/run/wordpress/plugins_unpacked" ]]; then 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    echo "Unpacking plugins" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    echo "==> Unpacking plugins" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # clear the directory, otherwise unzip/mv have to be forced 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     rm -rf /app/data/wp-content/mu-plugins/* 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -94,10 +95,10 @@ if [[ ! -f "/run/wordpress/plugins_unpacked" ]]; then 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     touch /run/wordpress/plugins_unpacked 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    echo "Plugins already unpacked from previous run" # restarts 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    echo "==> Plugins already unpacked from previous run" # restarts 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 fi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-echo "Updating domain related settings" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+echo "==> Updating domain related settings" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # Note that wp-config already sets WP_HOME and WP_SITEURL and the values in db below are ignored 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # This is only done for keeping the db dumps more useful 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 $WP option update siteurl "${APP_ORIGIN}" 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -106,12 +107,12 @@ $WP option update home "${APP_ORIGIN}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # If the user has not changed the email, update it to reflect it any domain change 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # TODO: remove this after this release 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 if [[ "$($WP option get admin_email)" == *.app@* ]]; then 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    echo "Updating admin email since it was unchanged" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    echo "==> Updating admin email since it was unchanged" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $WP option update admin_email "admin@cloudron.local" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 fi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # configure WP mail smtp plugin (smtp_user, smtp_pass can be set when supported) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-echo "Configuring smtp mail" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+echo "==> Configuring smtp mail" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 $WP option update mailer smtp 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 $WP option update mail_from "${MAIL_FROM}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # Let user customize the mail from name 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -132,7 +133,7 @@ if [[ -n "${LDAP_SERVER:-}" ]]; then 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # GroupOverUser means that if there is an existing wp group for the user, it won't be overwritten 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # The above implies that users can override the roles in wordpress and it 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # doesn't get overwritten on re-login 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    echo "Configuring LDAP" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    echo "==> Configuring LDAP" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ldapConfig=$(cat <<EOF 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         "Enabled"       : true, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -161,7 +162,7 @@ fi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 chown -R www-data:www-data /app/data /run/wordpress 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-echo "Starting apache" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+echo "==> Starting apache" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 APACHE_CONFDIR="" source /etc/apache2/envvars 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 rm -f "${APACHE_PID_FILE}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 exec /usr/sbin/apache2 -DFOREGROUND 
			 |