fichiers séparés
This commit is contained in:
17
bin/import_directus_schema.sh
Normal file
17
bin/import_directus_schema.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
. bin/variables.sh
|
||||
. bin/functions.sh
|
||||
|
||||
get_username
|
||||
get_ip
|
||||
get_ssh_port
|
||||
|
||||
echo -e "${PURPLE}${BOLD}Import local Directus data model${RESET}"
|
||||
echo -e "${BLUE}npx directus schema snapshot ./snapshot.yaml${RESET}"
|
||||
echo -e "${BLUE}scp -P ${ssh_port} /local/path/to/snapshot.yaml ${username}@${ip}:/home/${username}/snapshot.yaml${RESET}"
|
||||
echo -e "${PURPLE}${BOLD}Press any key when done${RESET}"
|
||||
read
|
||||
|
||||
su -s /bin/bash -c "cd ${CMS_DIRECTORY} &&\
|
||||
npx directus schema apply --yes /home/${username}/snapshot.yaml" www-data
|
@ -24,4 +24,23 @@ if [[ "$answer" == "y" ]]; then
|
||||
. bin/import_directus_db.sh
|
||||
else
|
||||
. bin/setup_directus.sh
|
||||
fi
|
||||
|
||||
echo -e "${PURPLE}${BOLD}Import Directus data model ? (y/N) ${RESET}"
|
||||
read answer
|
||||
if [[ "$answer" == "y" ]]; then
|
||||
. bin/import_directus_schema.sh
|
||||
fi
|
||||
|
||||
echo -e "${PURPLE}${BOLD}You can now add some content${RESET}"
|
||||
echo -e "${ORANGE}${BOLD}Do not forget to set the permissions${RESET}"
|
||||
echo -e "${ORANGE}${BOLD}Website role ${RESET}${ORANGE}Read content collections and directus_files${RESET}"
|
||||
echo -e "${ORANGE}${BOLD}User role ${RESET}${ORANGE}All permissions on content collections, directus_files and directus_folders${RESET}"
|
||||
fi
|
||||
|
||||
echo "cms.${DOMAIN_NAME} {" >> $CADDYFILE
|
||||
echo "reverse_proxy ${ip}:${port}" >> $CADDYFILE
|
||||
echo "}" >> $CADDYFILE
|
||||
caddy fmt $CADDYFILE -w
|
||||
caddy reload -c $CADDYFILE
|
||||
|
||||
echo -e "${PURPLE}${BOLD}Access Directus ${RESET}${PURPLE}https://cms.${DOMAIN_NAME}${RESET}"
|
||||
|
50
bin/install_nuxt_front.sh
Normal file
50
bin/install_nuxt_front.sh
Normal file
@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
. bin/variables.sh
|
||||
. bin/functions.sh
|
||||
|
||||
get_ip
|
||||
|
||||
echo -e "${PURPLE}${BOLD}Create and push a prod branch on the repo${RESET}"
|
||||
echo -e "${BLUE}git fetch . main:prod${RESET}"
|
||||
echo -e "${BLUE}git push origin prod${RESET}"
|
||||
echo -e "${PURPLE}${BOLD}Enter the .git url of the repo${RESET}"
|
||||
read repo_url
|
||||
|
||||
front_repo_name=$(echo "$repo_url" | sed 's#.*/\([^/]*\)\.git#\1#')
|
||||
front_directory="${REPO_DIRECTORY}/${front_repo_name}"
|
||||
if [[ -z "$WEBSITE_TOKEN" ]]; then
|
||||
echo -e "${PURPLE}${BOLD}Enter the Directus Website user static token${RESET}"
|
||||
read -s WEBSITE_TOKEN
|
||||
fi
|
||||
|
||||
touch /var/www/.nuxtrc
|
||||
echo "telemetry.consent=0" > /var/www/.nuxtrc
|
||||
echo "telemetry.enabled=false" >> /var/www/.nuxtrc
|
||||
chown -R www-data:www-data /var/www/.nuxtrc
|
||||
|
||||
rm /var/www/html/*
|
||||
chown www-data:www-data /var/www/html
|
||||
|
||||
su -s /bin/bash -c "cd ${REPO_DIRECTORY} &&\
|
||||
git clone ${repo_url} &&\
|
||||
cd ${front_directory} &&\
|
||||
git checkout prod &&\
|
||||
echo \"DIRECTUS_API_TOKEN=${WEBSITE_TOKEN}\" > .env &&\
|
||||
echo \"URL=https://${DOMAIN_NAME}\" >> .env &&\
|
||||
echo \"DIRECTUS_URL=https://cms.${DOMAIN_NAME}\" >> .env &&\
|
||||
node --max-old-space-size=250 `which npm` install -y &&\
|
||||
node --max-old-space-size=250 `which npm` run generate --prerender" www-data
|
||||
|
||||
cp -r "${front_directory}/.output/public" /var/www/html
|
||||
chown -R www-data:www-data /var/www/html/public
|
||||
|
||||
echo "www.${DOMAIN_NAME} {" >> $CADDYFILE
|
||||
echo "redir ${DOMAIN_NAME}{uri} permanent" >> $CADDYFILE
|
||||
echo "}" >> $CADDYFILE
|
||||
echo "${DOMAIN_NAME} {" >> $CADDYFILE
|
||||
echo "root * /var/www/html/public" >> $CADDYFILE
|
||||
echo "file_server" >> $CADDYFILE
|
||||
echo "}" >> $CADDYFILE
|
||||
caddy fmt $CADDYFILE -w
|
||||
caddy reload -c $CADDYFILE
|
@ -14,7 +14,7 @@ echo -e "${BLUE}Domain : www.${DOMAIN_NAME} | Type : A | Target : ${ip}${RESET}"
|
||||
echo -e "${PURPLE}${BOLD}Press any key when done${RESET}"
|
||||
read
|
||||
|
||||
repo_directory="/var/www/repositories"
|
||||
REPO_DIRECTORY="/var/www/repositories"
|
||||
mkdir $repo_directory
|
||||
chown www-data:www-data $repo_directory
|
||||
CMS_DIRECTORY="${repo_directory}/cms_${DOMAIN_NAME}"
|
||||
|
@ -54,29 +54,7 @@ npx directus users create --email \"${directus_admin_email}\" \
|
||||
--password \"${directus_admin_password}\" --role \"${admin_role_uuid}\" &&\
|
||||
npx directus users create --email \"website@${DOMAIN_NAME}\" --password \"${website_password}\" --role \"${website_role_uuid}\"" www-data
|
||||
|
||||
website_token=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')
|
||||
WEBSITE_TOKEN=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')
|
||||
mariadb -u directus -p${DB_DIRECTUS_PASSWORD} -e "UPDATE directus.directus_roles SET icon='robot' WHERE name='Website'";
|
||||
mariadb -u directus -p${DB_DIRECTUS_PASSWORD} -e "UPDATE directus.directus_roles SET app_access='0' WHERE name='Website'";
|
||||
mariadb -u directus -p${DB_DIRECTUS_PASSWORD} -e "UPDATE directus.directus_users SET token=\"${website_token}\" WHERE email=\"website@${DOMAIN_NAME}\"";
|
||||
|
||||
echo -e "${PURPLE}${BOLD}Import Directus data model ? (y/N) ${RESET}"
|
||||
read answer
|
||||
if [[ "$answer" == "y" ]]; then
|
||||
get_username
|
||||
get_ip
|
||||
get_ssh_port
|
||||
|
||||
echo -e "${PURPLE}${BOLD}Import local Directus data model${RESET}"
|
||||
echo -e "${BLUE}npx directus schema snapshot ./snapshot.yaml${RESET}"
|
||||
echo -e "${BLUE}scp -P ${ssh_port} /local/path/to/snapshot.yaml ${username}@${ip}:/home/${username}/snapshot.yaml${RESET}"
|
||||
echo -e "${PURPLE}${BOLD}Press any key when done${RESET}"
|
||||
read
|
||||
|
||||
su -s /bin/bash -c "cd ${CMS_DIRECTORY} &&\
|
||||
npx directus schema apply --yes /home/${username}/snapshot.yaml" www-data
|
||||
fi
|
||||
|
||||
echo -e "${PURPLE}${BOLD}You can now add some content${RESET}"
|
||||
echo -e "${ORANGE}${BOLD}Do not forget to set the permissions${RESET}"
|
||||
echo -e "${ORANGE}${BOLD}Website role ${RESET}${ORANGE}Read content collections and directus_files${RESET}"
|
||||
echo -e "${ORANGE}${BOLD}User role ${RESET}${ORANGE}All permissions on content collections, directus_files and directus_folders${RESET}"
|
||||
mariadb -u directus -p${DB_DIRECTUS_PASSWORD} -e "UPDATE directus.directus_users SET token=\"${WEBSITE_TOKEN}\" WHERE email=\"website@${DOMAIN_NAME}\"";
|
42
bin/setup_webhook.sh
Normal file
42
bin/setup_webhook.sh
Normal file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
. bin/variables.sh
|
||||
. bin/functions.sh
|
||||
|
||||
echo -e "${PURPLE}${BOLD}If it does not already exists, create a webhook at the following url${RESET}"
|
||||
echo -e "${PURPLE}${BOLD}${repo_url}/settings/hooks/gitea/new${RESET}"
|
||||
echo -e "${BLUE}${BOLD}Target URL ${RESET}${BLUE}https://${domain_name}/webhook.php${RESET}"
|
||||
echo -e "${BLUE}${BOLD}Branch filter ${RESET}${BLUE}prod${RESET}"
|
||||
echo -e "${BLUE}${BOLD}Authorization Header ${RESET}${ORANGE}Generate a safe string using \`openssl rand -base64 32\`${RESET}"
|
||||
echo -e "${PURPLE}${BOLD}Enter the Authorization Header${RESET}"
|
||||
read -s auth_header
|
||||
|
||||
install_pkg php
|
||||
install_pkg php-fpm
|
||||
install_pkg jq
|
||||
|
||||
rm /var/www/html/index.html
|
||||
cp ./assets/webhook.php /var/www/html/
|
||||
mkdir /var/www/webhook
|
||||
cp ./assets/webhook.sh /var/www/webhook
|
||||
chown www-data:www-data /var/www/webhook/webhook.sh
|
||||
chmod u+x /var/www/webhook/webhook.sh
|
||||
mkdir /var/www/webhook/logs
|
||||
chown www-data:www-data /var/www/webhook/logs
|
||||
|
||||
get_ip
|
||||
|
||||
head -n $(($(wc -l < $CADDYFILE) - 2)) $CADDYFILE > temp_Caddyfile && mv temp_Caddyfile $CADDYFILE
|
||||
echo "handle /webhook.php {" >> $CADDYFILE
|
||||
echo "@unauthorized not header Authorization \"${auth_header}\"" >> $CADDYFILE
|
||||
echo "respond @unauthorized \"Unauthorized access\"" >> $CADDYFILE
|
||||
echo "root * /var/www/html" >> $CADDYFILE
|
||||
echo "php_fastcgi unix//run/php/php8.2-fpm.sock" >> $CADDYFILE
|
||||
echo "file_server" >> $CADDYFILE
|
||||
echo "}" >> $CADDYFILE
|
||||
echo "handle {" >> $CADDYFILE
|
||||
echo "reverse_proxy ${ip}:3000" >> $CADDYFILE
|
||||
echo "}" >> $CADDYFILE
|
||||
echo "}" >> $CADDYFILE
|
||||
caddy fmt $CADDYFILE -w
|
||||
caddy reload -c $CADDYFILE
|
@ -11,4 +11,9 @@ DB_ROOT_PASSWORD=""
|
||||
DB_DIRECTUS_PASSWORD=""
|
||||
|
||||
DOMAIN_NAME=""
|
||||
CMS_DIRECTORY=""
|
||||
CMS_DIRECTORY=""
|
||||
REPO_DIRECTORY=""
|
||||
|
||||
WEBSITE_TOKEN=""
|
||||
|
||||
CADDYFILE="/etc/caddy/Caddyfile"
|
Reference in New Issue
Block a user