Last active
March 15, 2017 04:56
-
-
Save brianoflan/a049d12c010f17a4a56e99360944c56c to your computer and use it in GitHub Desktop.
For hastily installing WordPress on a LightSail instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
fix() { | |
export lightsail_wordpress_fix=true ; | |
check ; | |
exit 0 ; | |
} | |
check() { | |
export checks_failed=0 ; | |
[[ $DEBUGN -lt 2 ]] || set -x ; | |
_check_git ; | |
_check_letsencrypt1 ; | |
_check_owners ; | |
_check_disable_banner ; | |
[[ $DEBUGN -lt 2 ]] || set +x ; | |
exit $checks_failed ; | |
} | |
die() { | |
echo "$1" 1>&2 ; | |
exit 1 ; | |
} | |
_check_disable_banner() { | |
[[ -e /opt/bitnami/apps/bitnami/banner/disable-banner ]] || { | |
export checks_failed=1 ; | |
if [[ $lightsail_wordpress_fix == true ]] ; then | |
true ; # XXX | |
else | |
echo "ERROR: The Bitnami banner has not been disabled." ; | |
fi ; | |
} | |
} | |
_check_letsencrypt1() { | |
local d=/opt/bitnami/apps/wordpress/letsencrypt | |
[[ -d $d ]] || { | |
export checks_failed=1 ; | |
if [[ $lightsail_wordpress_fix == true ]] ; then | |
sudo mkdir -p $d ; | |
sudo chown bitnami:daemon $d ; | |
chmod ug+rwx $d ; | |
else | |
echo "ERROR: Found no $d folder." ; | |
fi ; | |
} | |
} | |
_check_owners() { | |
local check_user="apps/wordpress/htdocs" | |
local check_group="apps/wordpress/htdocs" | |
local check_perm="apps/wordpress/htdocs/wp-content" | |
local tmpf="tmpf.names$(date -u +'%Y%m%dT%H%Mz')" ; | |
local tmpf2="tmpf.details$(date -u +'%Y%m%dT%H%Mz')" ; | |
# apps/wordpress/htdocs/wp-content/uploads covered: | |
{ | |
for d in $check_user ; do | |
find /opt/bitnami/$d \! -user bitnami -print | egrep -v '\/wflogs(\/|$)' | |
done ; | |
for d in $check_group ; do | |
find /opt/bitnami/$d \! -group daemon -print | |
done ; | |
for d in $check_perm ; do | |
find /opt/bitnami/$d \! -perm -ug+rw -print | |
done ; | |
} > $tmpf ; | |
sort $tmpf | while read f ; do | |
ls -ld "$f" ; | |
done > $tmpf2 ; | |
# ls -lart $tmpf2 ; # XXX | |
if [[ -s $tmpf2 ]] ; then | |
export checks_failed=1 ; | |
if [[ $lightsail_wordpress_fix == true ]] ; then | |
for d in $check_user ; do | |
sudo chown -R bitnami /opt/bitnami/"$d" ; | |
done ; | |
for d in $check_group ; do | |
sudo chgrp -R daemon /opt/bitnami/"$d" ; | |
done ; | |
for d in $check_perm ; do | |
sudo chmod -R ug+rwX /opt/bitnami/"$d" ; | |
done ; | |
else | |
echo "ERROR: Found ownership issues:" | |
tail $tmpf2 | perl -ne 'print " $_"' ; | |
echo ; | |
fi ; | |
else | |
echo "NOTE: Found no ownership issues." 1>&2 | |
fi ; | |
rm -rf tmpf.* ; | |
} | |
_check_git() { | |
[[ -d /opt/bitnami/.git ]] || { | |
export checks_failed=1 ; | |
if [[ $lightsail_wordpress_fix == true ]] ; then | |
[[ $GIT_URL ]] || die "ERROR: No GIT_URL set." ; | |
which git || sudo apt-get -y install git ; | |
pushd /opt/bitnami ; | |
git init ; | |
[[ $GIT_EMAIL ]] || export GIT_EMAIL='[email protected]' | |
[[ $GIT_USER ]] || export GIT_USER='some user' | |
git config --global user.email "$GIT_EMAIL" ; | |
git config --global user.name "$GIT_USER" ; | |
touch ~/.gitignore ; | |
sudo mv ~/.gitignore ./ ; | |
git checkout -b init ; | |
git add .gitignore ; | |
git commit -m 'init' ; | |
git remote add origin $GIT_URL ; | |
git fetch origin ; | |
popd ; | |
else | |
echo "ERROR: Git is not set up." ; | |
[[ $GIT_URL ]] || echo "ERROR: No GIT_URL set." ; | |
[[ $GIT_EMAIL ]] || echo "ERROR: No GIT_EMAIL set." ; | |
[[ $GIT_NAME ]] || echo "ERROR: No GIT_NAME set." ; | |
fi ; | |
} | |
} | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment