#!/bin/bash # Name: Statique Littérateur # Type: Domain manager # file: manage__domain # Folder: /var/lib/stl/scripts/ # By echolib (XMPP: im@echolib.re) # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 #====================================================================== # -------------- # DOMAIN Section # -------------- #====================================================================== #---------------------------------------------------------------------- # domain OPTIONS | Manage arguments from command line # $1: main argument # $2: change #---------------------------------------------------------------------- domain__OPTIONS() { domain_check=true case "$2" in '') ;; new) domain_add=true; [[ "$3" ]] && domain_name="$3" ;; edit) domain_edit=true ;; *) noarg "$2" ;; esac domain__get } #---------------------------------------------------------------------- # Check for PWD config file and source # Indepdant call: just source config domain file (exit, if not exists) #---------------------------------------------------------------------- domain__get() { if [[ -f "$stl_file_pwd_conf" ]];then source "$stl_file_pwd_conf" # Source config PWD file else echo "# No domain set from this directory" [[ $domain_add ]] && domain__set [[ $domain_check ]] || exit # exit if domain__get call fi # From command line domain if [[ $domain_check ]] && [[ $domain_name ]];then [[ $domain_edit ]] \ && nano "$stl_file_pwd_conf" echo "# Domain set from this directory: $domain_name" exit fi } #---------------------------------------------------------------------- # New domain creation # Create .stl.conf in PWD directoryy # Register settings for domain #---------------------------------------------------------------------- domain__set() { if__writeable "$PWD" # Check if anwser is not empty, else exit # $1: answer # --------------------------------------- is__set() { ! [[ "$1" ]] \ && echo "# Maybe later..." \ && exit } # If DOMAIN already have protocol # $1 # ------------------------------- is__protocol() { [[ "${domain_name: -1}" == "/" ]] \ && domain_name=${domain_name::-1} # Confirm, configuration not already exists if [[ -f "$stl_dir_db/$domain_name/$domain_name.conf" ]];then source "$stl_dir_db/$domain_name/$domain_name.conf" if [[ "$PWD" != "$conf_pwd" ]];then echo "! A configuration for '$domain_name' exists in $pwd_conf" exit fi fi case "$domain_name" in "http://"*) domain_protocol="http://" domain_name=${domain_name/$domain_protocol/} ;; "https://"*) domain_protocol="https://" domain_name=${domain_name/$domain_protocol/} ;; esac if [[ "$domain_protocol" ]];then domain_name=${domain_name/$domain_protocol/} domain_ask+="$domain_name with protocol $domain_protocol" else read -rp "- Use 'https://' protocol (N for 'http://') ? " set_prot case "$set_prot" in Y) domain_protocol="https://" ;; N) domain_protocol="http://" ;; *) echo "# Maybe later...";exit ;; esac domain_ask+="$domain_name" fi } # ---------- # Processing question to config domain # ---------- echo -e "\n# You will be asked to confirm after resume" # DOMAIN is set in command line ? case "$domain_name" in '') read -rp "- Which domain to set ? " domain_name is__set "$domain_name" is__protocol ;; *) domain_ask="- Add your domain here: " is__protocol read -rp "$domain_ask (Y|*) ? " domain_confirm case "$domain_confirm" in Y) true ;; *) echo "# Maybe later...";exit ;; esac ;; esac # Where is the server ? /var/www ? read -erp "- Where is your server URI ? " srv_uri is__set "srv_uri" [[ "${srv_uri: -1}" == "/" ]] \ && srv_uri=${srv_uri::-1} ! [[ -d "$srv_uri" ]] \ && echo "! Missing directory" \ && exit if__writeable "$srv_uri" domain_srv="$srv_uri/$domain_name" # Installation: server or local read -rp "- STL server installed (Y|N for local ; use wip only) ? " install case "$install" in Y|y) stl_install="server" ;; N|n) stl_install="local" ;; *) echo "# Maybe later..." ;; esac # Domain TITLE read -rp "- Domain Title ? " domain_title is__set "$domain_title" # Domain ABOUT read -rp "- Domain About ? " domain_about is__set "$domain_about" # Domain LANG read -rp "- Domain lang (i.e. fr) ? " domain_lang is__set "$domain_lang" # Domain MAIL read -rp "- Domain mail ? " domain_mail is__set "$domain_mail" # Domain TAGS read -rp "- Domain tags (comma separated) ? " domain_tags is__set "$domain_tags" # Domain TAGS read -rp "- Domain copyright ? " domain_cr is__set "$domain_cr" # Domain SIDEBAR TITLE read -rp "- Domain sidebar title ? " domain_sidebar_title is__set "$domain_sidebar_title" # Domain SIDEBAR TITLE read -rp "- Domain sidebar items (1-24) ? " domain_sidebar_items is__set "$domain_sidebar_items" ! [[ $domain_sidebar_items =~ ^[0-9]+$ ]] \ && echo "! $domain_sidebar_items is not digits between 1-24" \ && exit ! (( $domain_sidebar_items >= 1 && $domain_sidebar_items <= 24 )) \ && echo "! $domain_sidebar_items is not between 1-24" \ && exit # Domain CSS PREFIX read -rp "- Domain CSS prefix (alnum,-) ? " domain_css is__set "$domain_css" ! [[ $domain_css =~ ^[a-zA-Z0-9_-]+$ ]] \ && echo "! '$domain_css' is not alpha numeric. '-' is authorized" \ && exit case "${domain_css: -1}" in "_"|"-") domain_css=${domain_css::-1} ;; esac domain_css=${domain_css,,} # Domain LOGO read -rp "- Domain logo filename ? " domain_logo # External URL Profile read -rp "- Domain external URL Profile ? " domain_ext_url # Statoolinfos read -rp "- Generate file stats (Statoolinfos) ? " domain_stats case "$domain_stats" in Y|y) domain_stats="yes" ;; N|n) domain_stats="no" ;; *) echo "# Maybe later..." ;; esac # Resume before writing conf # ------ clear echo -e "# Resume configuration...\n" cat < "$stl_dir_db/$domain_name/$domain_name.conf" conf_pwd="$PWD" EODBCONF cat < "$stl_file_pwd_conf" # Domain Configuration domain_name="$domain_name" domain_url="$domain_protocol$domain_name" domain_srv="$domain_srv" domain_title="$domain_title" domain_about="$domain_about" domain_lang="$domain_lang" domain_logo="$domain_logo" domain_mail="$domain_mail" domain_tags="$domain_tags" domain_cr="$domain_cr" domain_sidebar_title="$domain_sidebar_title" domain_sidebar_items=$domain_sidebar_items domain_css="$domain_css" domain_ext_url="$domain_ext_url" # You must know what you do if you change from here... # STL configurationn stl_install="$stl_install" domain_stats="$domain_stats" domain_db_articles="$stl_dir_db/$domain_name/articles" domain_conf="$PWD/$stl_file_pwd_conf" # Domain directories for articles domain_dir="$PWD" domain_dir_articles="$PWD/articles" domain_dir_images="$PWD/articles/images" domain_dir_files="$PWD/articles/files" # Domain directories for server domain_dir_wip="$domain_srv/wip" domain_dir_wip_tpl="$domain_srv/wip/template" domain_dir_wip_images="$domain_srv/wip/images" domain_dir_wip_files="$domain_srv/wip/files" EODOMAINCONF # Create a backup of the config in db rsync -a "$PWD/$stl_file_pwd_conf" \ "$stl_dir_db/$domain_name/$stl_file_pwd_conf.bkp" # Create folders base in PWD mkdir -p "$PWD/articles" mkdir -p "$PWD/articles/images" mkdir -p "$PWD/articles/files" # Create conf, according to installation (server, local) case "$stl_install" in server) printf '%s\n%s\n%s\n%s\n' \ "domain_dir_www=\"$domain_srv/www\"" \ "domain_dir_www_tpl=\"$domain_srv/www/template\"" \ "domain_dir_www_images=\"$domain_srv/www/images\"" \ "domain_dir_www_files=\"$domain_srv/www/files\"" \ >> "$stl_file_pwd_conf" mkdir -p "$domain_srv/www" mkdir -p "$domain_srv/www/template" mkdir -p "$domain_srv/www/files" mkdir -p "$domain_srv/www/images" mkdir -p "$domain_srv/wip" mkdir -p "$domain_srv/wip/template" mkdir -p "$domain_srv/wip/files" mkdir -p "$domain_srv/wip/images" printf '%s%s\n\n' \ "! files template (logo, style.css...) must be put in " \ "$domain_srv/wip/template/" ;; local) mkdir -p "$domain_srv/wip" mkdir -p "$domain_srv/wip/template" mkdir -p "$domain_srv/wip/files" mkdir -p "$domain_srv/wip/images" printf '%s%s\n\n' \ "! Your logo, styles.css... must be put in " \ "$domain_srv/wip/template" ;; esac }