328 lines
9.8 KiB
Bash
328 lines
9.8 KiB
Bash
#!/bin/bash
|
|
# file: gsl__new_website
|
|
# Folder: /var/lib/gsl/scripts
|
|
# By echolib
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
#=======================================================================
|
|
#
|
|
# Configure new WEBSITE from DOMAIN
|
|
#
|
|
#=======================================================================
|
|
gsl__new_website() {
|
|
gsl__check_file "$gsl_dir_helps/gsl_infos_new_website" || return
|
|
|
|
clear
|
|
cat $gsl_dir_helps/gsl_infos_new_website
|
|
printf '\n%s\n%s\n%s\n' \
|
|
"# Configuration of a new website..." \
|
|
"# Cancel with empty field" \
|
|
"# You will be asked to confirm at the end"
|
|
|
|
#=======================================================================
|
|
# Webserver URI
|
|
#=======================================================================
|
|
echo -e "\n# Webserver: /var/www ! NO ending / (Or maybe elsewhere...)"
|
|
read -erp \
|
|
": Webserver URI ? " \
|
|
gsl_set_server
|
|
|
|
gsl__check_settings $gsl_set_server \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Domain URL
|
|
#=======================================================================
|
|
printf '\n%s %s\n' \
|
|
"# URL: www.example.com !NO ending /" \
|
|
"(https:// will be added if missing or force with http://)"
|
|
read -rp \
|
|
": Website URL ? " \
|
|
gsl_set_url
|
|
|
|
gsl__check_settings $gsl_set_url \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
gsl_https='https://'
|
|
case "$gsl_set_url" in
|
|
"https://"*)
|
|
gsl_set_ndd=${gsl_set_url/$gsl_https/}
|
|
echo "D> Case: $gsl_set_ndd"
|
|
;;
|
|
"http://"*)
|
|
gsl_http="http://"
|
|
gsl_set_ndd=${gsl_set_url/$gsl_http/}
|
|
;;
|
|
*)
|
|
gsl_set_ndd="$gsl_set_url"
|
|
gsl_https+=$gsl_set_url
|
|
gsl_set_url=$gsl_https
|
|
;;
|
|
esac
|
|
|
|
# Domain NAME
|
|
gsl_set_ndd=`awk -F"." '{print $(NF-1)"."$NF}' <<< $gsl_set_ndd`
|
|
gsl_set_file_ndd="$gsl_set_ndd.conf"
|
|
|
|
#=======================================================================
|
|
# Personal use or global use ?
|
|
#=======================================================================
|
|
echo -e "\n# Save Domain in Home or Global"
|
|
read -rp \
|
|
": Home Use (y/n) ? " \
|
|
gsl_set_user_conf
|
|
case "$gsl_set_user_conf" in
|
|
y|Y)
|
|
gsl_save_dir_ndd="$gsl_dir_user_domains/$gsl_set_ndd"
|
|
gsl_save_conf_ndd="$gsl_save_dir_ndd/$gsl_set_file_ndd"
|
|
gsl_ask="# Save to $gsl_save_conf_ndd ? "
|
|
;;
|
|
n|N)
|
|
gsl_save_dir_ndd="$gsl_dir_global_domains/$gsl_set_ndd"
|
|
gsl_save_conf_ndd="$gsl_save_dir_ndd/$gsl_set_file_ndd"
|
|
gsl_ask="# Save to $gsl_save_conf_ndd ? "
|
|
;;
|
|
*) echo "! Abandon... Maybe next time" && return ;;
|
|
esac
|
|
|
|
#=======================================================================
|
|
# Website Title
|
|
#=======================================================================
|
|
echo -e "\n# Title: My Compagny (or My beautiful website)"
|
|
read -rp \
|
|
": Website Title ? " \
|
|
gsl_set_title
|
|
|
|
gsl__check_settings $gsl_set_title \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Website Description
|
|
#=======================================================================
|
|
echo -e "\n# Description: writings about this website"
|
|
read -rp \
|
|
": Website Description ? " \
|
|
gsl_set_about
|
|
gsl__check_settings $gsl_set_about\
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Contact Mail
|
|
#=======================================================================
|
|
echo -e "\n# Mail: contact@example.com"
|
|
read -rp \
|
|
": Contact Mail ? " \
|
|
gsl_set_mail
|
|
|
|
gsl__check_settings $gsl_set_mail \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Website Keywords
|
|
#=======================================================================
|
|
echo -e "\n# Keywords: geek,logiciels libre,friends (comma separated)"
|
|
read -rp \
|
|
": Website Keywords ? " \
|
|
gsl_set_keys
|
|
|
|
gsl__check_settings $gsl_set_keys \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Language
|
|
#=======================================================================
|
|
echo -e "\n# Language: fr (or en-GB...)"
|
|
read -rp \
|
|
": Website Lang ? " \
|
|
gsl_set_lang
|
|
|
|
gsl__check_settings $gsl_set_lang \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Copyright
|
|
#=======================================================================
|
|
echo -e "\n# Copyright: 2022 TITLE CC-BY-SA"
|
|
read -rp \
|
|
": Website Copyright ? " \
|
|
gsl_set_cr
|
|
|
|
gsl__check_settings $gsl_set_cr \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Website Logo
|
|
#=======================================================================
|
|
printf '\n%s %s\n' \
|
|
"# logo: my-logo.png" \
|
|
"(Put it in $gsl_save_dir_ndd/templates/)"
|
|
read -rp \
|
|
": Website logo file NAME ? " \
|
|
gsl_set_logo
|
|
|
|
gsl__check_settings $gsl_set_logo \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# CSS Acronym
|
|
#=======================================================================
|
|
printf '\n%s %s\n' \
|
|
"# CSS (short) Acronym: myweb !No need to end with _" \
|
|
"(Will create specific classes like myweb_paragraph)"
|
|
read -rp \
|
|
": CSS Acronym ? " \
|
|
gsl_set_css
|
|
|
|
gsl__check_settings $gsl_set_css \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Author Reference
|
|
#=======================================================================
|
|
printf '\n%s %s\n' \
|
|
"# Author URL Profile: https://..." \
|
|
"(Used for meta rel='me')"
|
|
read -rp \
|
|
": Author URL Profile ? " \
|
|
gsl_set_auth_url
|
|
|
|
gsl__check_settings $gsl_set_auth_url \
|
|
&& [[ "$gsl_process_stop" ]] \
|
|
&& return
|
|
|
|
#=======================================================================
|
|
# Show Resume
|
|
#=======================================================================
|
|
clear
|
|
printf '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' \
|
|
"# New Website configurations..." \
|
|
": Webserver|$gsl_set_server" \
|
|
": URL|$gsl_set_url" \
|
|
": Domain|$gsl_set_ndd" \
|
|
": Title|$gsl_set_title" \
|
|
": Description|$gsl_set_about" \
|
|
": Contact|$gsl_set_mail" \
|
|
": Keywords|$gsl_set_keys" \
|
|
": Language|$gsl_set_lang" \
|
|
": Copyright|$gsl_set_cr" \
|
|
": Logo File|$gsl_set_logo" \
|
|
": CSS Acro|$gsl_set_css" \
|
|
": Author URL|$gsl_set_auth_url" \
|
|
| column -t -s'|'
|
|
|
|
#=======================================================================
|
|
# Ask to Confirm
|
|
#=======================================================================
|
|
echo
|
|
if [[ -d "$gsl_save_dir_ndd" ]];then
|
|
printf '%s\n%s\n' \
|
|
"! A profile already exists in $gsl_save_dir_ndd" \
|
|
"- Remove (A)LL Directories: $gsl_save_dir_ndd" \
|
|
"- Remove (F)ile configurations : $gsl_save_conf_ndd" \
|
|
"- Any other key to cancel" && \
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Found" \
|
|
"Profile" \
|
|
"Configuration from $gsl_set_ndd" \
|
|
"$gsl_save_conf_ndd"
|
|
|
|
read -rp "! Remove (A|F|*) ? " \
|
|
gsl_ask_remove
|
|
|
|
case "$gsl_ask_remove" in
|
|
A)
|
|
rm -rf "$gsl_save_dir_ndd" && \
|
|
gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"Remove" \
|
|
"Folders" \
|
|
"Configuration from $gsl_set_ndd" \
|
|
"$gsl_save_dir_ndd"
|
|
;;
|
|
F)
|
|
rm -f "$gsl_save_conf_ndd" && \
|
|
gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"Remove" \
|
|
"File" \
|
|
"Configuration from $gsl_set_ndd" \
|
|
"$gsl_save_conf_ndd"
|
|
gsl_set_confirm="Y"
|
|
;;
|
|
*) echo "# Canceled";return ;;
|
|
esac
|
|
fi
|
|
|
|
! [[ "$gsl_set_confirm" ]] \
|
|
&& read -rp "$gsl_ask ?" gsl_set_confirm
|
|
|
|
case "$gsl_set_confirm" in
|
|
y|Y)
|
|
! [[ -d "$gsl_save_dir_ndd/templates" ]] \
|
|
&& mkdir -p "$gsl_save_dir_ndd/templates" \
|
|
&& gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"Create" \
|
|
"Folder" \
|
|
"Configuration from $gsl_set_ndd" \
|
|
"$gsl_save_dir_ndd/templates"
|
|
;;
|
|
*)
|
|
gsl__new_website && return
|
|
;;
|
|
esac
|
|
|
|
#=======================================================================
|
|
# Save config
|
|
#=======================================================================
|
|
printf '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' \
|
|
"gsl_site_server=\"$gsl_set_server\"" \
|
|
"gsl_site_url=\"$gsl_set_url\"" \
|
|
"gsl_site_ndd=\"$gsl_set_ndd\"" \
|
|
"gsl_site_title=\"$gsl_set_title\"" \
|
|
"gsl_site_about=\"$gsl_set_about\"" \
|
|
"gsl_site_mail=\"$gsl_set_mail\"" \
|
|
"gsl_site_keys=\"$gsl_set_keys\"" \
|
|
"gsl_site_lang=\"$gsl_set_lang\"" \
|
|
"gsl_site_cr=\"$gsl_set_cr\"" \
|
|
"gsl_site_logo=\"$gsl_set_logo\"" \
|
|
"gsl_site_css=\"$gsl_set_css\"" \
|
|
"gsl_site_auth_url=\"$gsl_set_auth_url\"" \
|
|
> "$gsl_save_conf_ndd"
|
|
|
|
if ! [[ `grep "$gsl_save_dir_ndd" "$gsl_file_db_domains"` ]];then
|
|
echo "$gsl_save_dir_ndd" >> "$gsl_file_db_domains" && \
|
|
gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"Create" \
|
|
"File" \
|
|
"Configuration from $gsl_set_ndd" \
|
|
"$gsl_file_db_domains"
|
|
fi
|
|
}
|
|
|
|
#=======================================================================
|
|
# Check if no Response from $@
|
|
#=======================================================================
|
|
gsl__check_settings() {
|
|
case "$@" in
|
|
"")
|
|
gsl_process_stop=true
|
|
echo "! Abandon... Maybe next time"
|
|
return
|
|
;;
|
|
esac
|
|
}
|