deployment-dcdn/bin/import_directus_db.sh

39 lines
1.3 KiB
Bash

#!/bin/bash
. bin/variables.sh
. bin/functions.sh
get_ssh_port
get_username
get_ip
echo -e "${PURPLE}${BOLD}Import the .tar.gz archive from your local storage${RESET}"
echo -e "${PURPLE}The archive should contain the sql dump, the upload directory and the .env file${RESET}"
echo -e "${BLUE}scp -P ${ssh_port} /local/path/to/archive.tar.gz ${username}@${ip}:/home/${username}/${RESET}"
echo -e "${PURPLE}${BOLD}Press any key when done${RESET}"
read
directus_archive=$(ls /home/${username}/*.tar.gz);
tar -xzf "${directus_archive}" -C "${CMS_DIRECTORY}" --strip-components=2
rm "${directus_archive}"
sed -i "s/^\(DB_PASSWORD=\)'.*'$/\1'$DB_DIRECTUS_PASSWORD'/" "${CMS_DIRECTORY}/.env"
port=$(cat ${CMS_DIRECTORY}/.env | grep "^PORT=" | sed 's/^PORT=//')
sql_dump=$(ls ${CMS_DIRECTORY}/*.sql)
install_pkg expect
mariadb -u directus -p"$DB_DIRECTUS_PASSWORD" directus < "$sql_dump"
rm $sql_dump
chown -R www-data:www-data $CMS_DIRECTORY
su -s /bin/bash -c "cd ${CMS_DIRECTORY} &&\
npm init -y &&\
npx directus bootstrap --skipAdminInit &&\
npx directus database migrate:latest
tmux new-session -d -s directus &&\
tmux send-keys -t directus \"cd ${CMS_DIRECTORY} && npx directus start\" C-m" www-data
echo -e "${PURPLE}Directus launched with imported database${RESET}"