Last active
February 22, 2024 20:53
-
-
Save fiver-watson/b8318f3f65a7fc7d98747b2596015326 to your computer and use it in GitHub Desktop.
This is a bash script that can be used with the Access to Memory (AtoM) Vagrant box, to quickly purge the current environment and reload the demo data. Requirements: This script has been updated for the AtoM 2.7.0.0 and/or 2.6.0.2 vagrant boxes, and therefore works with Ubuntu 18.04, PHP 7.2, and MySQL 8. The uploads directory and the sqldump mu…
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
# AtoM bash script to load demo data into a vagrant environment | |
# Created by Dan Gillean, Artefactual Systems - [email protected] | |
# CC-BY-SA 4.0 | |
# v1 created June 29, 2018 | |
# v2 - fix typos, June 29, 2018 | |
# v3 - update for AtoM 2.6 compatibility, March 31, 2020 | |
# v4 - introduce optional choice for regen derivs, July 29, 2020 | |
# v5 - simplify uploads/downloads replacement; add change log, July 30, 2020 | |
# Requirements for this version: AtoM 2.6 or higher | |
# Usage: | |
# * create a copy of the atom database, named as atom2_demo.sql | |
# * create a copy of the uploads and downloads directories | |
# * place all of these, and this script, in the vagrant installation directory | |
# on your source computer | |
# * To run: /vagrant/load-demo.sh | |
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
# set -o xtrace --> FOR DEBUGGING! | |
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
__atom="/home/vagrant/atom" | |
__atom_uploads="${__atom}/uploads" | |
__atom_downloads="${__atom}/downloads" | |
__sf="${__atom}/symfony" | |
__uploads_source="/vagrant/uploads/r" | |
__downloads_source="/vagrant/downloads/" | |
clear_cache() | |
{ | |
echo "Clearing the cache" | |
${__sf} cc | |
} | |
populate_index() | |
{ | |
echo "Populating the search index" | |
${__sf} search:populate | |
} | |
upgrade_sql() | |
{ | |
echo "Running the upgrade task" | |
${__sf} tools:upgrade-sql -B | |
} | |
regen_derivs() | |
{ | |
echo "Regenerating the derivatives" | |
${__sf} digitalobject:regen-derivatives --force | |
} | |
purge() | |
{ | |
echo "Purging the DB" | |
${__sf} tools:purge --demo | |
} | |
# old options no longer needed now that we use rsync --delete | |
# remove_uploads() | |
# { | |
# echo "Removing the old uploads" | |
# rm -rf ${__atom_uploads} | |
# } | |
# remove_downloads() | |
# { | |
# echo "Removing the old downloads" | |
# rm -rf ${__atom_downloads} | |
# } | |
load_uploads() | |
{ | |
echo "Loading the uploads" | |
rsync -av --delete ${__uploads_source} ${__atom_uploads} | |
} | |
load_downloads() | |
{ | |
echo "Loading the downloads" | |
rsync -av --delete ${__downloads_source} ${__atom_downloads} | |
} | |
drop_db() | |
{ | |
echo "Dropping and recreating the DB" | |
mysql -u atom-user -pATOMPASSWORD -e 'DROP DATABASE atom; CREATE DATABASE atom CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;' | |
} | |
load_db() | |
{ | |
echo "Loading the demo data" | |
mysql -u atom-user -pATOMPASSWORD atom < /vagrant/atom2_demo.sql | |
} | |
restart() | |
{ | |
echo "Restarting services" | |
sudo systemctl restart php7.2-fpm | |
sudo systemctl restart memcached | |
sudo systemctl restart nginx | |
sudo systemctl reset-failed atom-worker | |
sudo systemctl restart atom-worker | |
} | |
read -p "Do you want to regenerate the derivatives? Only needed if AtoM code changes introduce derivative size or format changes... (y/n)" yn | |
case $yn in | |
[Yy]* ) | |
purge | |
load_uploads | |
load_downloads | |
drop_db | |
load_db | |
upgrade_sql | |
regen_derivs | |
clear_cache | |
populate_index | |
restart | |
clear_cache | |
;; | |
[Nn]* ) | |
purge | |
load_uploads | |
load_downloads | |
drop_db | |
load_db | |
upgrade_sql | |
clear_cache | |
populate_index | |
restart | |
clear_cache | |
;; | |
esac | |
if [ $? -eq 0 ] | |
then | |
echo "Successfully loaded demo data" | |
exit 0 | |
else | |
echo "Data load failed" >&2 | |
exit 1 | |
fi | |
exit $? |
Version for Docker Compose AtoM environment here:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary of recent changes:
v5 update: (2020-07-30)
rsync --delete
to speed up the loadv4 update: (2020-07-29)
v3 update: (2020-03-31)
More information on this script and its use: