#!/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__if_file "$gsl_dir_helps/gsl_infos_new_website" read 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" #======================================================================= # Domain URL #======================================================================= printf '\n%s\n %s\n' \ "# URL: www.example.com" \ "(https:// will be added if missing or force with http://)" read -rp \ ": Website URL ? " \ gsl_set_url [[ ${gsl_set_url: -1} == "/" ]] \ && gsl_set_url=${gsl_set_url::-1} gsl__check_settings $gsl_set_url || return gsl_https='https://' case "$gsl_set_url" in "https://"*) gsl_set_ndd=${gsl_set_url/$gsl_https/} ;; "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" [[ -f "$gsl_dir_user_domains/$gsl_set_ndd/$gsl_set_file_ndd" ]] \ && gsl_profile="$gsl_dir_user_domains/$gsl_set_ndd/$gsl_set_file_ndd" \ && gsl_set_user_conf="Y" [[ -f "$gsl_dir_global_domains/$gsl_set_ndd/$gsl_set_file_ndd" ]] \ && gsl_profile="$gsl_dir_global_domains/$gsl_set_ndd/$gsl_set_file_ndd" \ && gsl_set_user_conf="N" if [[ "$gsl_profile" ]];then gsl__logs_print \ "$gsl_log_w" \ "New" \ "Profile" \ "Found configuration from $gsl_set_ndd" \ "$gsl_profile" echo -e "\n! A Profile exists: $gsl_profile" read -rp ": Continue (Y|*) " gsl_continue case "$gsl_continue" in Y|y) source "$gsl_profile" && \ gsl__logs_print \ "$gsl_log_i" \ "New" \ "Profile" \ "Load configuration from $gsl_set_ndd" \ "$gsl_profile" gsl_profile_exists=true ;; *) return ;; esac fi #======================================================================= # Webserver URI #======================================================================= [[ $gsl_profile_exists ]] \ && echo -e "\n# Webserver registred: $gsl_site_server" \ || echo -e "\n# Webserver: /var/www (Or maybe elsewhere...)" read -erp \ ": Webserver URI ? " \ gsl_set_server [[ ${gsl_set_server: -1} == "/" ]] \ && gsl_set_server=${gsl_set_server::-1} if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_server" ]];then [[ "$gsl_site_server" ]] \ && gsl_set_server="$gsl_site_server" \ || gsl__check_settings $gsl_set_server || return fi else gsl__check_settings $gsl_set_server || return fi #======================================================================= # Personal use or global use ? #======================================================================= if ! [[ "$gsl_set_user_conf" ]];then echo -e "\n# Save Domain in Home or Global" read -rp \ ": Home Use (y/n) ? " \ gsl_set_user_conf fi 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 (y|*) ? " ;; 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 (y|*) ? " ;; *) echo "! Abandon... Maybe next time" && return ;; esac #======================================================================= # Website Title #======================================================================= [[ $gsl_profile_exists ]] \ && echo -e "\n# Title registred: $gsl_site_title" \ || echo -e "\n# Title: My Compagny (or My beautiful website)" read -rp \ ": Website Title ? " \ gsl_set_title if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_title" ]];then [[ "$gsl_site_title" ]] \ && gsl_set_title="$gsl_site_title" \ || gsl__check_settings $gsl_set_title || return fi else gsl__check_settings $gsl_set_title || return fi #======================================================================= # Website Description #======================================================================= [[ $gsl_profile_exists ]] \ && echo -e "\n# Description registred: $gsl_site_about" \ || echo -e "\n# Description: writings about this website" read -rp \ ": Website Description ? " \ gsl_set_about if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_about" ]];then [[ "$gsl_site_about" ]] \ && gsl_set_about="$gsl_site_about" \ || gsl__check_settings $gsl_set_about || return fi else gsl__check_settings $gsl_set_about || return fi #======================================================================= # Contact Mail #======================================================================= [[ $gsl_profile_exists ]] \ && echo -e "\n# Mail registred: $gsl_site_mail" \ || echo -e "\n# Mail: contact@example.com" read -rp \ ": Contact Mail ? " \ gsl_set_mail if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_mail" ]];then [[ "$gsl_site_mail" ]] \ && gsl_set_mail="$gsl_site_mail" \ || gsl__check_settings $gsl_set_mail || return fi else gsl__check_settings $gsl_set_mail || return fi #======================================================================= # Website Keywords #======================================================================= if [[ $gsl_profile_exists ]];then printf '\n%s\n %s\n' \ "# GENERIC pages Keywords registred: $gsl_site_keys" \ "! Will be used on each post !" else printf '\n%s\n %s\n' \ "# GENERIC pages Keywords: geek stuff,free (comma separated)" \ "! Will be used on each post !" fi read -rp \ ": Website Keywords for all Pages ? " \ gsl_set_keys if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_keys" ]];then [[ "$gsl_site_keys" ]] \ && gsl_set_keys="$gsl_site_keys" \ || gsl__check_settings $gsl_set_keys || return fi else gsl__check_settings $gsl_set_keys || return fi #======================================================================= # Language #======================================================================= [[ $gsl_profile_exists ]] \ && echo -e "\n# Language registred: $gsl_site_lang" \ || echo -e "\n# Language: fr (or en-GB...)" read -rp \ ": Website Lang ? " \ gsl_set_lang if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_lang" ]];then [[ "$gsl_site_lang" ]] \ && gsl_set_lang="$gsl_site_lang" \ || gsl__check_settings $gsl_set_lang || return fi else gsl__check_settings $gsl_set_lang || return fi #======================================================================= # Copyright #======================================================================= [[ $gsl_profile_exists ]] \ && echo -e "\n# Copyright registred: $gsl_site_cr" \ || echo -e "\n# Copyright: 2022 TITLE CC-BY-SA" read -rp \ ": Website Copyright ? " \ gsl_set_cr if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_cr" ]];then [[ "$gsl_site_cr" ]] \ && gsl_set_cr="$gsl_site_cr" \ || gsl__check_settings $gsl_set_cr || return fi else gsl__check_settings $gsl_set_cr || return fi #======================================================================= # Website Logo #======================================================================= if [[ $gsl_profile_exists ]];then printf '\n%s\n %s\n' \ "# logo registred: $gsl_site_logo" \ "Put it in $gsl_save_dir_ndd/templates/" else printf '\n%s\n %s\n' \ "# logo: my-logo.png" \ "Put it in $gsl_save_dir_ndd/templates/" fi read -rp \ ": Website logo file NAME ? " \ gsl_set_logo if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_logo" ]];then [[ "$gsl_site_logo" ]] \ && gsl_set_logo="$gsl_site_logo" \ || gsl__check_settings $gsl_set_logo || return fi else gsl__check_settings $gsl_set_logo || return fi #======================================================================= # Last Posts listing name header #======================================================================= if [[ $gsl_profile_exists ]];then printf '\n%s\n %s\n' \ "# Title List Name registred: $gsl_site_listname" \ "Title List to show before last posts" else printf '\n%s\n %s\n' \ "# Title List Name: My Last Posts" \ "Title List to show before last posts" fi read -rp \ ": Title List Name ? " \ gsl_set_listname if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_listname" ]];then [[ "$gsl_site_listname" ]] \ && gsl_set_listname="$gsl_site_listname" \ || gsl__check_settings $gsl_set_listname || return fi else gsl__check_settings $gsl_set_listname || return fi #======================================================================= # CSS Acronym #======================================================================= if [[ $gsl_profile_exists ]];then printf '\n%s\n %s\n' \ "# CSS (short) Acronym registred: $gsl_site_css" \ "Will create specific HTML classes like ${gsl_site_css}_paragraph" else printf '\n%s\n %s\n' \ "# CSS (short) Acronym: myweb !No need to end with _" \ "Will create specific HTML classes like myweb_paragraph" fi read -rp \ ": CSS Acronym ? " \ gsl_set_css if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_css" ]];then [[ "$gsl_site_css" ]] \ && gsl_set_css="$gsl_site_css" \ || gsl__check_settings $gsl_set_css || return fi else gsl__check_settings $gsl_set_css || return fi #======================================================================= # Author Reference #======================================================================= if [[ $gsl_profile_exists ]];then printf '\n%s\n %s\n' \ "# Author/Compagny URL Profile registred: $gsl_site_auth_url" \ "Used for meta rel='me'" else printf '\n%s\n %s\n' \ "# Author/Compagny URL Profile: https://..." \ "Used for meta rel='me'" fi read -rp \ ": Author URL Profile ? " \ gsl_set_auth_url if [[ $gsl_profile_exists ]];then if ! [[ "$gsl_set_auth_url" ]];then [[ "$gsl_site_auth_url" ]] \ && gsl_set_auth_url="$gsl_site_auth_url" \ || gsl__check_settings $gsl_set_auth_url || return fi else gsl__check_settings $gsl_set_auth_url || return fi #======================================================================= # Folder for Posts #======================================================================= printf '\n%s\n %s\n %s\n' \ "# You can set here a folder for your writings' Posts" \ "Leave Empty to manually do it later (see help)" \ "Autocompletion /NEWFOLDER (name of choice)" read -erp \ ": Where will you add your files' [post].gsl ? " \ gsl_dir_user_posts #======================================================================= # 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%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" \ ": Title List|$gsl_set_listname" \ ": CSS Acro|$gsl_set_css" \ ": Author URL|$gsl_set_auth_url" \ ": User folder writings' Posts|$gsl_dir_user_posts" \ | column -t -s'|' #======================================================================= # Ask to Confirm #======================================================================= echo read -rp "$gsl_ask " gsl_set_confirm case "$gsl_set_confirm" in y|Y) gsl__logs_print \ "$gsl_log_w" \ "New" \ "Profile" \ "Confirmed configuration from $gsl_set_ndd" \ "$gsl_save_conf_ndd" if ! [[ -d "$gsl_save_dir_ndd" ]];then mkdir -p "$gsl_save_dir_ndd" && \ gsl__logs_print \ "$gsl_log_i" \ "New" \ "Profile" \ "Create Folder configuration for $gsl_set_ndd" \ "$gsl_save_dir_ndd/" fi # Create et set a folder for writings' posts if [[ $gsl_dir_user_posts ]];then mkdir -p "$gsl_dir_user_posts" && \ gsl__logs_print \ "$gsl_log_i" \ "New" \ "Profile" \ "Create Folder Posts for $gsl_set_ndd" \ "$gsl_dir_user_posts/" touch "$gsl_dir_user_posts/gsl.$gsl_set_ndd" && \ gsl__logs_print \ "$gsl_log_i" \ "New" \ "Profile" \ "Folder set with gsl.$gsl_set_ndd" \ "$gsl_dir_user_posts/" fi ;; *) 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%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_listname=\"$gsl_set_listname\"" \ "gsl_site_css=\"$gsl_set_css\"" \ "gsl_site_auth_url=\"$gsl_set_auth_url\"" \ > "$gsl_save_conf_ndd" && \ gsl__logs_print \ "$gsl_log_w" \ "New" \ "Profile" \ "Write configuration for $gsl_set_ndd" \ "$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_w" \ "New" \ "Profile" \ "Add $gsl_save_dir_ndd to DB for $gsl_set_ndd" \ "$gsl_file_db_domains" fi } #======================================================================= # Check if no Response from $@ #======================================================================= gsl__check_settings() { [[ "$@" ]] && return echo "! Abandon... Maybe next time" exit }