|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Bash script for SciELO Upload Installation/Update |
| 4 | +# |
| 5 | +# How it works: |
| 6 | +# ./install.sh <Upload version> |
| 7 | +# |
| 8 | +# Check the tag version at https://github.com/scieloorg/scms-upload/releases |
| 9 | + |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +if [ -z "$1" ]; then |
| 13 | + # Version is mandatory |
| 14 | + echo "Version not informed. Please, inform the Upload version. E.g.: v2.3.4, ./install.sh v2.3.4" |
| 15 | + exit 128 |
| 16 | +fi |
| 17 | + |
| 18 | +UPLOAD_DIR=./upload |
| 19 | +ENV_FILES_DIR=.envs/.production |
| 20 | +IS_UPDATE=0 |
| 21 | + |
| 22 | +echo "Checking directory $UPLOAD_DIR/$ENV_FILES_DIR ..." |
| 23 | + |
| 24 | +if [ ! -d "$UPLOAD_DIR/$ENV_FILES_DIR" ]; then |
| 25 | + echo "Installing version $1 ..." |
| 26 | + git clone --no-checkout --filter=blob:none --depth=1 --branch "$1" --sparse https://github.com/scieloorg/scms-upload "$UPLOAD_DIR" |
| 27 | + cd "$UPLOAD_DIR" |
| 28 | + git sparse-checkout init --cone |
| 29 | + git sparse-checkout set .envs/.production-template compose/production/postgres/maintenance Makefile production.yml |
| 30 | + git checkout "$1" |
| 31 | + mv .envs/.production-template "$ENV_FILES_DIR" |
| 32 | +else |
| 33 | + echo "Updating to version $1 ..." |
| 34 | + echo " Downloading files from Git repository ..." |
| 35 | + cd "$UPLOAD_DIR" |
| 36 | + wget -O Makefile "https://raw.githubusercontent.com/scieloorg/scms-upload/refs/tags/$1/Makefile" |
| 37 | + wget -O production.yml "https://raw.githubusercontent.com/scieloorg/scms-upload/refs/tags/$1/production.yml" |
| 38 | + IS_UPDATE=1 |
| 39 | +fi |
| 40 | + |
| 41 | +echo "$1" > VERSION |
| 42 | + |
| 43 | +echo "Version $(cat VERSION) installed/updated!" |
| 44 | + |
| 45 | +if [ "$IS_UPDATE" -eq 1 ]; then |
| 46 | + # For updating: update Django containers and make DB migrations |
| 47 | + make update_webapp compose=production.yml |
| 48 | + make django_migrate_fresh_migrations compose=production.yml |
| 49 | +else |
| 50 | + # For installation: make Docker login and build DB |
| 51 | + read -p "Enter the Docker login user: " DOCKER_USER |
| 52 | + docker login -u "$DOCKER_USER" |
| 53 | + make build compose=production.yml |
| 54 | + make django_migrate compose=production.yml |
| 55 | +fi |
| 56 | + |
| 57 | +make up compose=production.yml |
| 58 | +make ps compose=production.yml |
| 59 | + |
| 60 | +cd - |
| 61 | +exit 0 |
| 62 | + |
0 commit comments