Created
March 21, 2024 16:33
-
-
Save kenguest/b2127cc155fd14cdc40adbe52d80559e to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/bash | |
suffix="`date +%Y%m%d%H%M%S`" | |
real="/var/www/html/myfirstproject_$suffix" # where the codebase really will be located | |
live="/var/www/html/myfirstproject-docker" # the live directory aka docroot for nginx | |
livetmp="/var/www/html/myfirstproject_tmp" # used temporarily for switching symlink target | |
db="/var/www/databases/myfirstproject/database.sqlite" # live sqlite database file | |
dbbackup="/var/www/databases/myfirstproject/database_$suffix.sqlite" | |
su -c "git clone git@github.com:WilECoyoteandAcme-Inc/myfirstproject-docker.git ~ubuntu/fresh" ubuntu | |
mv -v ~ubuntu/fresh/ $real | |
# do composer install and ensure everything in vendor is readable | |
su -c "cd $real; composer install -q" ubuntu | |
# back up copy of database | |
cp -v $db $dbbackup | |
# Set up database etc | |
ln -sv $db $real/database/database.sqlite | |
cp -v $live/.env $real | |
(cd $real; php artisan cache:clear) | |
(cd $real; php artisan route:cache) | |
# this may change the schema of the live sqlite database. check | |
(cd $real; php artisan migrate) | |
# ownerships and permissions | |
chown -R ubuntu.www-data $real | |
find $real/vendor -perm 700 -type d -exec chmod 755 \{\} \; | |
# Relink live to the newly cloned codebase | |
# Do this in an atomic acton by using ln -s .... mv -Tf | |
ln -sv $real $livetmp && mv -Tfv $livetmp $live | |
echo "To delete backup copy of database enter 'yes'" | |
read -r deletedb | |
if [ "$deletedb" == "yes" ]; then | |
rm $dbbackup -v | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment