Skip to content
Snippets Groups Projects
remove-instance.sh 667 B
Newer Older
  • Learn to ignore specific revisions
  • #!/usr/bin/env bash
    
    # creates an instance with the default apps and grand lyon apps installed
    
    if [ $# -ne 1 ]; then
        echo "Usage: $0 <instance url>"
        exit 1
    fi
    INSTANCE_ID=$1
    
    source .env
    
    TMPFILE=$(mktemp /tmp/cozyXXX)
    
    echo "Removing instance ${INSTANCE_ID}.${COZY_TLD} ..."
    
    docker-compose exec cozy ./cozy instances destroy --host 0.0.0.0 "${INSTANCE_ID}.${COZY_TLD}" | tee "${TMPFILE}"
    
    # TODO find a better way to detect if there was an error
    TOKEN=""
    if [ $(grep -ic ERROR ${TMPFILE}) -eq 0 ]; then
        TOKEN=$(grep token "${TMPFILE}" | cut -f2 -d":" | tr -d '" ')
    fi
    
    rm "${TMPFILE}"
    
    if [ -z "${TOKEN}" ]; then
        echo No token found.
        exit 1
    fi