Skip to content
Snippets Groups Projects
Commit c10f770d authored by Olli Jalonen's avatar Olli Jalonen :disguised_face:
Browse files

Initial version of scripts

parent e4ef5fa2
No related branches found
No related tags found
No related merge requests found
/*!
* University of Turku
*
* Custom GeoNode CSS
*
* Copyright 2019
* https://geonode.utu.fi
*
*/
#!/bin/bash
# UTU GeoNode customisation script
#
# Usually this file does not need to be executed manually.
#
# Execute update.sh that will pull latest changes from git
# and execute this script afterwards.
#
# If you modify files list please keep the custom css file
# first or file verification check might not give planned
# results. New files should be added at the bottom of the
# lists.
#
# This file is supposed to be more readable and simple
# than efficient and smart. Please keep it that way.
#
# softdev@utu.fi
# Directory to store the backups
BACKUPS='backups'
# Temporary direction for backup creation
TMP='tmp'
# Image files path
IMAGES='images'
# Image path inside container
CONTAINER_IMAGE_PATH='/usr/src/geonode/geonode/static/geonode/img'
# File names inside container
CONTAINER_FILES=(
'geonode-utu.css' # 0 (does not exist inside container on first run)
)
# File paths inside container
CONTAINER_PATHS=(
'/usr/src/geonode/geonode/static/geonode/css/' # 0
)
# File names outside container (here)
# This is needed because there are files with same name on different path
LOCAL_FILES=(
'geonode-utu.css' # 0
)
# Image files, these are not backed up but existence is checked
IMAGE_FILES=(
)
# Get django container id
CONTAINER=$(docker ps -aqf "name=django4resilienceacademy")
# Exit if django container is not found
if [ -z "$CONTAINER" ]; then
echo "No django container found. Halting script exection."
exit 1
fi
# Create backups directory if it does not exist
if [ ! -d "$BACKUPS" ]; then
mkdir "$BACKUPS"
fi
# Remove temp directory if it exists already
if [ -d "$TMP" ]; then
echo "Temp directory $TMP already exists. Removing it before creating a new one."
rm -rf "$TMP"
fi
# Create the temp directory
mkdir "$TMP"
# Copy all container files to local temp and ensure that file exists (exit if not)
for ((i = 0; i < ${#CONTAINER_FILES[@]};++i)); do
# Copy file to temp directory
docker cp $CONTAINER:${CONTAINER_PATHS[$i]}${CONTAINER_FILES[$i]} $TMP/${LOCAL_FILES[$i]}
# Check every file but the first (custom CSS) and exit if it does not exist
if [ ! -s "$TMP/${LOCAL_FILES[$i]}" ]; then
if (($i > 0)); then
echo "Copied file $i: $CONTAINER:${CONTAINER_PATHS[$i]}${CONTAINER_FILES[$i]} -> $TMP/${LOCAL_FILES[$i]} is empty or does not exist! Halting script exection."
exit 1
else
echo "Custom CSS file: $TMP/${LOCAL_FILES[$i]} not found on container - continue running script"
fi
#else
# echo "Successfully copied file $i: $CONTAINER:${CONTAINER_PATHS[$i]}${CONTAINER_FILES[$i]} -> $TMP/${LOCAL_FILES[$i]}"
fi
done
# Create a zip file from backups
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
zip -rq "$BACKUPS/utu-originals-$TIMESTAMP.zip" "$TMP"
# Check that the zip file is found
if [ ! -s "$BACKUPS/ra-originals-$TIMESTAMP.zip" ]; then
echo "Created backup $BACKUPS/utu-originals-$TIMESTAMP.zip is missing! Halting script exection.."
exit 1
fi
# Check that every customisation file exists locally and is not empty
for ((i = 0; i < ${#CONTAINER_FILES[@]};++i)); do
if [ ! -s "${LOCAL_FILES[$i]}" ]; then
echo "Required customisation file ${LOCAL_FILES[$i]} is empty or does not exist! Halting script exection."
exit 1
fi
done
# Check that every image file exists locally and is not empty
for ((i = 0; i < ${#IMAGE_FILES[@]};++i)); do
if [ ! -s "$IMAGES/${IMAGE_FILES[$i]}" ]; then
echo "Required image file ${IMAGE_FILES[$i]} is empty or does not exist! Halting script exection."
exit 1
fi
done
# Update container files
for ((i = 0; i < ${#CONTAINER_FILES[@]};++i)); do
# Copy file to container
docker cp ${LOCAL_FILES[$i]} $CONTAINER:${CONTAINER_PATHS[$i]}${CONTAINER_FILES[$i]}
done
# Update container images
for ((i = 0; i < ${#IMAGE_FILES[@]};++i)); do
# Copy image to container
docker cp $IMAGES/${IMAGE_FILES[$i]} $CONTAINER:${CONTAINER_IMAGE_PATH}/${IMAGE_FILES[$i]}
done
# Remove temp directory
rm -rf "$TMP"
# Run 'collectstatic' management command
docker exec -it $CONTAINER bash -c "/usr/src/resilienceacademy/manage.sh collectstatic --noinput"
# Restart django container to show customisation (test without)
# echo "Restarting django container, this will take some seconds"
# docker restart "$CONTAINER"
# Tell user that customisation is up to date
echo "Customisation update ready."
echo "Restart the django container if updates are not showing up"
\ No newline at end of file
#!/bin/bash
# TODO: help
# Update files
git pull
# Process updated files
./process_files.sh
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment