diff --git a/bin/add-site/install_directus.sh b/bin/add-site/install_directus.sh index f30ea5f..ccc6fe3 100644 --- a/bin/add-site/install_directus.sh +++ b/bin/add-site/install_directus.sh @@ -21,9 +21,13 @@ set_admin_credentials() { } set_port() { - # @TODO: random port - # @TODO: check if port is available - port=8055 + install_pkg net-tools + while true; do + port=$(shuf -i 8000-9000 -n 1) + if ! netstat -tuln | grep -q ":${port}"; then + break + fi + done sed -i "s/^PORT=.*/PORT=${port}/" "/home/${USERNAME}/cms.${DOMAIN_NAME}/.env" } @@ -61,11 +65,11 @@ if [[ "$answer" == "y" ]]; then echo -e "${PURPLE}${BOLD}Import the .tar.gz archive from your local storage${RESET}" echo -e "${PURPLE}The archive should contain the sql dump and the upload directory${RESET}" echo -e "${PURPLE}Make sure the Website Directus user permissions are setup${RESET}" - echo -e "${BLUE}scp -P ${SSH_PORT} /local/path/to/archive.tar.gz ${USERNAME}@${IP}:/home/${USERNAME}/${RESET}" + echo -e "${BLUE}scp -P ${SSH_PORT} /local/path/to/archive.tar.gz ${USERNAME}@${IP}:/home/${USERNAME}/cms.${DOMAIN_NAME}/${RESET}" echo -e "${PURPLE}${BOLD}Press any key when done${RESET}" read - directus_archive=$(ls /home/${USERNAME}/*.tar.gz); + directus_archive=$(ls /home/${USERNAME}/cms.${DOMAIN_NAME}/*.tar.gz); tar -xzf "${directus_archive}" -C "/home/${USERNAME}/cms.${DOMAIN_NAME}" --strip-components=1 rm "${directus_archive}" sql_dump=$(ls /home/${USERNAME}/cms.${DOMAIN_NAME}/*.sql) @@ -75,7 +79,8 @@ if [[ "$answer" == "y" ]]; then npx directus bootstrap --skipAdminInit &&\ npx directus database migrate:latest " - docker compose -f "/home/${URSERNAME}/cms.${DOMAIN_NAME}/docker-compose.yml" restart + docker compose -f "/home/${USERNAME}/cms.${DOMAIN_NAME}/docker-compose.yml" restart + # @TODO: check if the permissions are setup correctly else set_admin_credentials set_port