random directus port

This commit is contained in:
Valentin 2024-11-30 21:30:50 +01:00
parent dc18b66817
commit 9e3025e485
1 changed files with 11 additions and 6 deletions

View File

@ -21,9 +21,13 @@ set_admin_credentials() {
} }
set_port() { set_port() {
# @TODO: random port install_pkg net-tools
# @TODO: check if port is available while true; do
port=8055 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" 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}${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}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 "${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}" echo -e "${PURPLE}${BOLD}Press any key when done${RESET}"
read 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 tar -xzf "${directus_archive}" -C "/home/${USERNAME}/cms.${DOMAIN_NAME}" --strip-components=1
rm "${directus_archive}" rm "${directus_archive}"
sql_dump=$(ls /home/${USERNAME}/cms.${DOMAIN_NAME}/*.sql) sql_dump=$(ls /home/${USERNAME}/cms.${DOMAIN_NAME}/*.sql)
@ -75,7 +79,8 @@ if [[ "$answer" == "y" ]]; then
npx directus bootstrap --skipAdminInit &&\ npx directus bootstrap --skipAdminInit &&\
npx directus database migrate:latest 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 else
set_admin_credentials set_admin_credentials
set_port set_port