1ere analyse
This commit is contained in:
parent
4abc7ddd69
commit
98783b035f
|
@ -16,21 +16,21 @@ tplVHost="$MY_PATH/templates/vhost.txt"
|
||||||
###
|
###
|
||||||
# Get Arguments
|
# Get Arguments
|
||||||
###
|
###
|
||||||
args="$@"
|
args="$@"
|
||||||
domain="$1"
|
domain="$1"
|
||||||
ip="$2"
|
ip="$2"
|
||||||
port="$3"
|
port="$3"
|
||||||
|
|
||||||
parseArgs(){
|
parseArgs(){
|
||||||
i=0
|
i=0
|
||||||
for cmd in $args; do
|
for cmd in $args; do
|
||||||
arg[$i]=$cmd
|
arg[$i]=$cmd
|
||||||
[[ ${arg[$i]} =~ "domain=" ]] && domain=$(echo ${arg[$i]} | grep "\<domain=" | awk -F '=' '{ print $2 }')
|
[[ ${arg[$i]} =~ "domain=" ]] && domain=$(echo ${arg[$i]} | grep "\<domain=" | awk -F '=' '{ print $2 }')
|
||||||
[[ ${arg[$i]} =~ "ip=" ]] && ip=$(echo ${arg[$i]} | grep "\<ip=" | awk -F '=' '{ print $2 }')
|
[[ ${arg[$i]} =~ "ip=" ]] && ip=$(echo ${arg[$i]} | grep "\<ip=" | awk -F '=' '{ print $2 }')
|
||||||
[[ ${arg[$i]} =~ "port=" ]] && port=$(echo ${arg[$i]} | grep "\<port=" | awk -F '=' '{ print $2 }')
|
[[ ${arg[$i]} =~ "port=" ]] && port=$(echo ${arg[$i]} | grep "\<port=" | awk -F '=' '{ print $2 }')
|
||||||
[[ ${arg[$i]} =~ "ssl=" ]] && ssl=$(echo ${arg[$i]} | grep "\<ssl=" | awk -F '=' '{ print $2 }')
|
[[ ${arg[$i]} =~ "ssl=" ]] && ssl=$(echo ${arg[$i]} | grep "\<ssl=" | awk -F '=' '{ print $2 }')
|
||||||
((i++))
|
((i++))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
parseArgs
|
parseArgs
|
||||||
|
|
||||||
|
@ -39,61 +39,69 @@ newVHost="/etc/nginx/conf.d/$domain.conf"
|
||||||
[[ $ip == "local" ]] && ip="127.0.0.1"
|
[[ $ip == "local" ]] && ip="127.0.0.1"
|
||||||
|
|
||||||
addSSL(){
|
addSSL(){
|
||||||
echo "${yellow}Création du certificat SSL pour $domain...${reset}"
|
echo "${yellow}Création du certificat SSL pour $domain...${reset}"
|
||||||
sudo /usr/bin/certbot --nginx certonly -d $domain && echo "${green}Le certificat de $domain a bien été déployé${reset}" || echo "${red}Une erreur s'est produite lors de la création du certificat SSL${reset}"
|
sudo /usr/bin/certbot --nginx certonly -d $domain && echo "${green}Le certificat de $domain a bien été déployé${reset}" || echo "${red}Une erreur s'est produite lors de la création du certificat SSL${reset}"
|
||||||
|
|
||||||
sudo sed -i -e 's/listen 80;/listen 443 ssl;/' $newVHost
|
sudo sed -i -e 's/listen 80;/listen 443 ssl;/' $newVHost
|
||||||
sudo sed -i -e '/includes\/errors.conf/i \\ listen [::]:443 ssl;\n include includes/ssl.conf;' $newVHost
|
sudo sed -i -e '/includes\/errors.conf/i \\ listen [::]:443 ssl;\n include includes/ssl.conf;' $newVHost
|
||||||
sudo sed -i -e '/error_log/i \\ ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;\n ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;\n' $newVHost
|
sudo sed -i -e '/error_log/i \\ ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;\n ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;\n' $newVHost
|
||||||
sudo cat $sslRedir | sudo tee -a $newVHost > /dev/null
|
sudo cat $sslRedir | sudo tee -a $newVHost > /dev/null
|
||||||
sudo sed -i -e 's/$domain/'"$domain"'/g' $newVHost
|
sudo sed -i -e 's/$domain/'"$domain"'/g' $newVHost
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -e $newVHost ]]; then
|
if [[ -e $newVHost ]]; then
|
||||||
echo "${yellow}Le virtualhost existe déjà${reset}"
|
echo "${yellow}Le virtualhost existe déjà${reset}"
|
||||||
if [[ -z $(grep "ssl_certificate_key" $newVHost) ]]; then
|
if [[ -z $(grep "ssl_certificate_key" $newVHost) ]]; then
|
||||||
echo "Certificat SSL non présent"
|
echo "Certificat SSL non présent"
|
||||||
if [[ $ssl =~ ^(1|true|oui)$ ]]; then
|
if [[ $ssl =~ ^(1|true|oui)$ ]]; then
|
||||||
echo "Installation du certificat SSL ..."
|
echo "Installation du certificat SSL ..."
|
||||||
addSSL
|
addSSL
|
||||||
sudo service nginx reload && echo "${green}Le domaine $domain à bien été créé et configuré =)${reset}" || echo "${red}Impossible de recharger nginx${reset}"
|
sudo service nginx reload && echo "${green}Le domaine $domain à bien été créé et configuré =)${reset}" || echo "${red}Impossible de recharger nginx${reset}"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
echo "${yellow}Aucune action n'a été effectué${reset}"
|
echo "${yellow}Aucune action n'a été effectué${reset}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "${yellow}Le SSL est déjà configuré sur le VHost${reset}"
|
echo "${yellow}Le SSL est déjà configuré sur le VHost${reset}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
create_vhost(){
|
create_vhost(){
|
||||||
echo "${yellow}Génération du nouveau VirtualHost...${reset}"
|
echo "${yellow}Génération du nouveau VirtualHost...${reset}"
|
||||||
sudo cp $tplVHost $newVHost
|
sudo cp $tplVHost $newVHost
|
||||||
sudo sed -i -e 's/$_DOMAIN/'"$domain"'/g' $newVHost
|
sudo sed -i -e 's/$_DOMAIN/'"$domain"'/g' $newVHost
|
||||||
sudo sed -i -e 's/$_IP/'"$ip"'/g' $newVHost
|
sudo sed -i -e 's/$_IP/'"$ip"'/g' $newVHost
|
||||||
sudo sed -i -e 's/$_PORT/'"$port"'/g' $newVHost
|
sudo sed -i -e 's/$_PORT/'"$port"'/g' $newVHost
|
||||||
if [[ $ssl =~ ^(1|true|oui)$ ]]; then
|
if [[ $ssl =~ ^(1|true|oui)$ ]]; then
|
||||||
printf "${yellow}Configuration SSL du VHost...${reset}"
|
printf "${yellow}Configuration SSL du VHost...${reset}"
|
||||||
addSSL && echo "${green}OK${reset}" || echo "${red}KO${reset}"
|
addSSL && echo "${green}OK${reset}" || echo "${red}KO${reset}"
|
||||||
else
|
else
|
||||||
echo "${yellow}Aucune configuration SSL ne sera effectué.${reset}"
|
echo "${yellow}Aucune configuration SSL ne sera effectué.${reset}"
|
||||||
fi
|
fi
|
||||||
sudo service nginx reload && echo "${green}Le domaine $domain à bien été créé et configuré =)${reset}" || echo "${red}Impossible de recharger nginx${reset}"
|
sudo service nginx reload && echo "${green}Le domaine $domain à bien été créé et configuré =)${reset}" || echo "${red}Impossible de recharger nginx${reset}"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Nous allons créer le domaine ${blue}$domain ${reset}qui sera lié au port ${blue}$port ${reset}de l'IP ${blue}$ip.${reset}"
|
echo "Nous allons créer le domaine ${blue}$domain ${reset}qui sera lié au port ${blue}$port ${reset}de l'IP ${blue}$ip.${reset}"
|
||||||
if [[ $p2vmProvided != 1 ]]; then
|
if [[ $p2vmProvided != 1 ]]; then
|
||||||
read -p "${bold}Confirmez-vous cette action ?${reset} (${green}y${reset} ou ${red}n${reset}) : " yn
|
read -p "${bold}Confirmez-vous cette action ?${reset} (${green}y${reset} ou ${red}n${reset}) : " yn
|
||||||
case $yn in
|
case $yn in
|
||||||
[Yy]* ) create_vhost break;;
|
[Yy]* ) create_vhost break;;
|
||||||
[Nn]* ) echo "${red}Fermeture du script${reset}" && exit;;
|
[Nn]* ) echo "${red}Fermeture du script${reset}" && exit;;
|
||||||
* ) echo "Merci de sélectionner yes ou no";;
|
* ) echo "Merci de sélectionner yes ou no";;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
create_vhost
|
create_vhost
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## 1ere analyse
|
||||||
|
# A priori utiliser avec domain=$IPFSNODEID ip=local port=10101 ssl=no
|
||||||
|
# [[ ! $(ipfs p2p ls | grep '/x/10101') ]] && ipfs p2p listen /x/10101 /ip4/127.0.0.1/tcp/10101
|
||||||
|
# Chaque station publie ses services/API sur un port numéroté /x/10101 relayé en 127.0.0.1/tcp/20101
|
||||||
|
# Elle publie cette information aux bootstrap (gateway) qui prennent en charge le relai https "ipfs p2p"
|
||||||
|
# [[ ! $(ipfs p2p ls | grep '/x/10101') ]] && ipfs --timeout=5s ping -n 1 /p2p/$IPFSNODEID && ipfs p2p forward /x/10101 /ip4/127.0.0.1/tcp/20101 /p2p/$IPFSNODEID
|
||||||
|
# A l'autre boût on sort domain=tata.toto.com ip=local port=20101 ssl=yes
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue