www-data installe node et directus

This commit is contained in:
Valentin 2024-02-26 13:14:54 +01:00
parent 24728c990f
commit 59b0533026
1 changed files with 30 additions and 26 deletions

View File

@ -190,17 +190,22 @@ fi
echo -e "${PURPLE}${BOLD}Install Node ? (y/N) ${RESET}"
read answer
if [[ "$answer" == "y" ]]; then
get_username
su -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash &&\
touch /var/www/.bashrc
chown www-data:www-data /var/www/.bashrc
mkdir /var/www/.nvm
chown www-data:www-data /var/www/.nvm
mkdir /var/www/.npm
chown www-data:www-data /var/www/.npm
su -s /bin/bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash &&\
export NVM_DIR="$HOME/.nvm" &&\
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&\
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" &&\
nvm install v18' $username
ln -sf /home/$username/.nvm/versions/node/v18.19.1/bin/node /usr/bin/node
ln -sf /home/$username/.nvm/versions/node/v18.19.1/bin/npm /usr/bin/npm
ln -sf /home/$username/.nvm/versions/node/v18.19.1/bin/npx /usr/bin/npx
mkdir /var/www/.npm
chown -R www-data:www-data /var/www/.npm
nvm install v18' www-data
ln -sf /var/www/.nvm/versions/node/v18.19.1/bin/node /usr/bin/node
ln -sf /var/www/.nvm/versions/node/v18.19.1/bin/npm /usr/bin/npm
ln -sf /var/www/.nvm/versions/node/v18.19.1/bin/npx /usr/bin/npx
echo -e "${PURPLE}${BOLD}Node installed${RESET}";
fi
@ -211,7 +216,6 @@ fi
echo -e "${PURPLE}${BOLD}Enter the domain name of the website${RESET}"
read domain_name
get_ip
cms_folder="cms_${domain_name}"
echo -e "${PURPLE}${BOLD}Configure the ${domain_name} DNS ZONE as the following${RESET}"
echo -e "${BLUE}Domain : ${domain_name} | Type : A | Target : ${ip}${RESET}"
@ -220,6 +224,11 @@ 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"
mkdir $repo_directory
chown www-data:www-data $repo_directory
cms_directory="${repo_directory}/cms_${domain_name}"
#
# DIRECTUS
#
@ -228,7 +237,6 @@ echo -e "${PURPLE}${BOLD}Install Directus ? (y/N) ${RESET}"
read answer
if [[ "$answer" == "y" ]]; then
install_pkg tmux
get_username
if [[ -z "$db_directus_password" ]]; then
echo -e "${PURPLE}${BOLD}Enter the MariaDB Directus password : ${RESET}"
@ -242,15 +250,16 @@ if [[ "$answer" == "y" ]]; then
echo -e "${PURPLE}${BOLD}Enter the Directus admin password : ${RESET}"
read -s directus_admin_password
env_file="${cms_folder}/.env"
env_file="${cms_directory}/.env"
port=8055
key=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')
secret=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')
su -c "cd &&\
mkdir ${cms_folder} &&\
mkdir ${cms_folder}/uploads &&\
echo "set -g default-shell /bin/sh" >> /etc/tmux.conf
su -s /bin/bash -c "mkdir ${cms_directory} &&\
mkdir ${cms_directory}/uploads &&\
echo \"HOST='${ip}'\" >> ${env_file} &&\
echo \"PORT=${port}\" >> ${env_file} &&\
echo \"PUBLIC_URL='https://cms.${domain_name}'\" >> ${env_file} &&\
@ -263,18 +272,12 @@ if [[ "$answer" == "y" ]]; then
echo \"SECRET='${secret}'\" >> ${env_file} &&\
echo \"KEY='${key}'\" >> ${env_file} &&\
echo \"CORS_ENABLED='true'\" >> ${env_file} &&\
echo \"CORS_ORIGIN='true'\" >> ${env_file}" $username
echo "set -g default-shell /bin/sh" >> /etc/tmux.conf
chown www-data:www-data /home/$username/$cms_folder
su -s /bin/bash -c "cd /home/${username}/${cms_folder} &&\
echo \"CORS_ORIGIN='true'\" >> ${env_file} &&\
cd ${cms_directory} &&\
npm init -y &&\
npx directus bootstrap --skipAdminInit &&\
tmux new-session -d -s directus &&\
tmux send-keys -t directus \"cd /home/${username}/${cms_folder} && npx directus start\" C-m" www-data
su -s /bin/bash -c "cd /home/${username}/${cms_folder} &&\
tmux send-keys -t directus \"cd ${cms_directory} && npx directus start\" C-m &&\
npx directus roles create --role Administrator --admin true &&\
npx directus roles create --role Website &&\
npx directus roles create --role User" www-data
@ -288,7 +291,7 @@ if [[ "$answer" == "y" ]]; then
website_password=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')
su -s /bin/bash -c "cd /home/${username}/${cms_folder} &&\
su -s /bin/bash -c "cd ${cms_directory} &&\
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
@ -308,6 +311,7 @@ if [[ "$answer" == "y" ]]; then
echo -e "${PURPLE}${BOLD}Import Directus data model ? (y/N) ${RESET}"
read answer
if [[ "$answer" == "y" ]]; then
get_username
echo -e "${PURPLE}${BOLD}Import local Directus data model${RESET}"
echo -e "${BLUE}npx directus schema snapshot ./snapshot.yaml${RESET}"
@ -315,8 +319,8 @@ if [[ "$answer" == "y" ]]; then
echo -e "${PURPLE}${BOLD}Press any key when done${RESET}"
read
su -s /bin/bash -c "cd /home/${username}/${cms_folder} &&\
npx directus schema apply --yes ../snapshot.yaml" www-data
su -s /bin/bash -c "cd ${cms_directory} &&\
npx directus schema apply --yes /home/${username}/snapshot.yaml" www-data
echo -e "${PURPLE}${BOLD}You can now add some content${RESET}"
echo -e "${ORANGE}${BOLD}Do not forget to set the permissions${RESET}"