#!/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" source 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 (Or maybe elsewhere...)" read -erp \ ": Webserver URI ? " \ gsl_set_server [[ ${gsl_set_server: -1} == "/" ]] \ && gsl_set_server=${gsl_set_server::-1} gsl__check_settings $gsl_set_server || return #======================================================================= # 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" [[ -d "$gsl_dir_user_domains/$gsl_set_ndd" ]] \ && gsl_profile="HOME: $gsl_dir_user_domains/$gsl_set_ndd" \ && gsl_set_user_conf="Y" [[ -d "$gsl_dir_global_domains/$gsl_set_ndd" ]] \ && gsl_profile="System: $gsl_dir_global_domains/$gsl_set_ndd" \ && gsl_set_user_conf="N" if [[ "$gsl_profile" ]];then echo "! A Profile exists in your $gsl_profile" read -rp ": Continue (Y|*)" gsl_continue case "$gsl_continue" in Y|y) true ;; *) gsl__check_settings $blank || return esac 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 ? " ;; 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 || return #======================================================================= # Website Description #======================================================================= echo -e "\n# Description: writings about this website" read -rp \ ": Website Description ? " \ gsl_set_about gsl__check_settings $gsl_set_about || return #======================================================================= # Contact Mail #======================================================================= echo -e "\n# Mail: contact@example.com" read -rp \ ": Contact Mail ? " \ gsl_set_mail gsl__check_settings $gsl_set_mail || return #======================================================================= # Website Keywords #======================================================================= echo -e "\n# GENERIC pages Keywords: geek stuff,free (comma separated)" read -rp \ ": Website Keywords for all Pages ? " \ gsl_set_keys gsl__check_settings $gsl_set_keys || return #======================================================================= # Language #======================================================================= echo -e "\n# Language: fr (or en-GB...)" read -rp \ ": Website Lang ? " \ gsl_set_lang gsl__check_settings $gsl_set_lang || return #======================================================================= # Copyright #======================================================================= echo -e "\n# Copyright: 2022 TITLE CC-BY-SA" read -rp \ ": Website Copyright ? " \ gsl_set_cr gsl__check_settings $gsl_set_cr || return #======================================================================= # Website Logo #======================================================================= printf '\n%s\n %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 || return #======================================================================= # CSS Acronym #======================================================================= printf '\n%s\n %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 || return #======================================================================= # Author Reference #======================================================================= printf '\n%s\n %s\n' \ "# Author/Compagny URL Profile: https://..." \ "(Used for meta rel='me')" read -rp \ ": Author URL Profile ? " \ gsl_set_auth_url gsl__check_settings $gsl_set_auth_url || return #======================================================================= # Folder for Posts #======================================================================= printf '\n%s\n %s\n %s\n' \ "# You can set here a folder for your writings' Posts" \ "or manually do it later or add another one later" \ "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' \ "# 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" \ ": User folder writings' Posts|$gsl_dir_user_posts" \ | 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) if ! [[ -d "$gsl_save_dir_ndd" ]];then mkdir -p "$gsl_save_dir_ndd" && \ gsl__logs_print \ "$gsl_log_i" \ "Create" \ "Folder" \ "Configuration from $gsl_set_ndd" \ "$gsl_save_dir_ndd/" mkdir -p "$gsl_dir_user_posts" && \ gsl__logs_print \ "$gsl_log_i" \ "Create" \ "Folder" \ "User Posts from $gsl_set_ndd" \ "$gsl_dir_user_posts/" touch "$gsl_dir_user_posts/gsl.$gsl_set_ndd" && \ gsl__logs_print \ "$gsl_log_i" \ "Create" \ "File" \ "gsl.$gsl_set_ndd" \ "$gsl_dir_user_posts/" fi ;; *) 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() { [[ "$@" ]] && return echo "! Abandon... Maybe next time" return }