Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13613ab6d5 | ||
|
|
9eb88078eb |
+154
-63
@@ -1,110 +1,151 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
###TODO###
|
||||||
|
#available functions - can be used as a function list or a direct execute by passing action - done
|
||||||
|
#would write domains into file/list on issuance so it can be used for renewal - done using cron
|
||||||
|
#revoked certificate names would be removed from existing list of issued certificates - done
|
||||||
|
#cron jobs would be created for renew function - done
|
||||||
|
#add auto update for lego tool - (also to cron) - done, not using cron making manual from menu
|
||||||
|
|
||||||
|
#add install for webserver type either apache/nginx - pending
|
||||||
|
|
||||||
|
#auto create default config file for created domains (man i really wish i can do this. lol)
|
||||||
|
|
||||||
#Export to be based on user preference
|
#Export to be based on user preference
|
||||||
#Enviromental Variables for certificate paths, this is to make sure certificates are always issued in same path
|
#Enviromental Variables for certificate paths, this is to make sure certificates are always issued in same path
|
||||||
#if cert in used by multiple applications. can be placed in central path
|
#if cert in used by multiple applications. can be placed in central path
|
||||||
#Can be run without root - root only needed to install dependencies from apt
|
#Can be run without root - root only needed to install dependencies from apt/yum
|
||||||
|
#should be folder that doesn't need root permission
|
||||||
#should be folder that doesn't have root permission
|
|
||||||
export CERT_PATH=/etc/nginx/ssl
|
|
||||||
export CONTACT_MAIL=xxxxxxxxxxxxxxxxxxxxxxxx
|
|
||||||
|
|
||||||
#Use case - namecheap (environment variable depends on dns provider)
|
#Use case - namecheap (environment variable depends on dns provider)
|
||||||
#check out https://go-acme.github.io/lego/dns/index.html for dns provider variables
|
#check out https://go-acme.github.io/lego/dns/index.html for dns provider variables
|
||||||
|
|
||||||
|
install_as_sudo() {
|
||||||
|
if [ -z "$SUDO_PASS" ] && [ "$EUID" -ne 0 ]; then
|
||||||
|
echo 'Sudo access needed to install dependencies'
|
||||||
|
read -sp 'Enter Sudo Password:' SUDO_PASS
|
||||||
|
printf '\n\n'
|
||||||
|
|
||||||
|
fi
|
||||||
|
get_os_type
|
||||||
|
}
|
||||||
|
|
||||||
|
set_env_variables() {
|
||||||
|
#envs for lego
|
||||||
|
export CERT_PATH=/etc/acme
|
||||||
|
export CONTACT_MAIL=xxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
export DNS_PROVIDER=namecheap
|
export DNS_PROVIDER=namecheap
|
||||||
export NAMECHEAP_PROPAGATION_TIMEOUT=60
|
export NAMECHEAP_PROPAGATION_TIMEOUT=60
|
||||||
export NAMECHEAP_POLLING_INTERVAL=2
|
export NAMECHEAP_POLLING_INTERVAL=2
|
||||||
export NAMECHEAP_API_USER=xxxxxxxxxxxxxxxxxxxxxxxx
|
export NAMECHEAP_API_USER=xxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
export NAMECHEAP_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxx
|
export NAMECHEAP_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
|
||||||
install_as_sudo() {
|
#envs for path
|
||||||
|
export LEGO_PATH=$CERT_PATH
|
||||||
|
export GOPATH=$HOME/.go
|
||||||
|
export GO_HOME=/usr/local/go
|
||||||
|
export PATH=$PATH:$GO_HOME/bin:$GOPATH/bin
|
||||||
|
|
||||||
if [ -z "$SUDO_PASS"] && [ $EUID -ne 0 ]; then
|
|
||||||
|
|
||||||
echo 'Sudo access needed to install dependencies'
|
|
||||||
read -sp "Enter Sudo Password:" SUDO_PASS
|
|
||||||
printf "\n\n"
|
|
||||||
|
|
||||||
fi
|
|
||||||
env_file=~/.profile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_dependencies() {
|
check_dependencies() {
|
||||||
|
|
||||||
echo "Checking dependencies..."
|
echo "Checking dependencies..."
|
||||||
check_install_curl
|
install_tar
|
||||||
check_install_jq
|
install_curl
|
||||||
check_install_go
|
install_jq
|
||||||
check_install_lego
|
install_git
|
||||||
|
install_go
|
||||||
|
install_lego
|
||||||
echo "Check compelete"
|
echo "Check compelete"
|
||||||
if [ "$dependency_install" == "yes" ]; then
|
if [ "$dependency_install" == "yes" ]; then
|
||||||
echo "restart shell session"
|
echo "restart shell session"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_install_curl() {
|
install_tar() {
|
||||||
|
if ! command -v tar 2>&1 >/dev/null; then
|
||||||
|
install_as_sudo
|
||||||
|
echo 'tar module not installed'
|
||||||
|
echo "now installing tar..."
|
||||||
|
|
||||||
|
###download and install curl
|
||||||
|
eval "echo $SUDO_PASS | sudo -S $install_cmd install tar -y"
|
||||||
|
echo "tar succcesfully installed"
|
||||||
|
eval "tar --version"
|
||||||
|
dependency_install=yes
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_curl() {
|
||||||
if ! command -v curl 2>&1 >/dev/null; then
|
if ! command -v curl 2>&1 >/dev/null; then
|
||||||
install_as_sudo
|
install_as_sudo
|
||||||
echo 'curl module not installed'
|
echo 'curl module not installed'
|
||||||
echo "now installing curl..."
|
echo "now installing curl..."
|
||||||
|
|
||||||
###download and install curl
|
###download and install curl
|
||||||
eval "sudo apt install curl -y"
|
eval "echo $SUDO_PASS | sudo -S $install_cmd install curl -y"
|
||||||
echo "curl succcesfully installed"
|
echo "curl succcesfully installed"
|
||||||
eval "curl -V"
|
eval "curl -V"
|
||||||
dependency_install=yes
|
dependency_install=yes
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_install_jq() {
|
install_jq() {
|
||||||
|
|
||||||
if ! command -v jq 2>&1 >/dev/null; then
|
if ! command -v jq 2>&1 >/dev/null; then
|
||||||
install_as_sudo
|
install_as_sudo
|
||||||
echo 'jq module not installed'
|
echo 'jq module not installed'
|
||||||
echo "now installing jq..."
|
echo "now installing jq..."
|
||||||
|
|
||||||
###download and install curl
|
###download and install curl
|
||||||
eval "sudo apt install jq -y"
|
eval "echo $SUDO_PASS | sudo -S $install_cmd install jq -y"
|
||||||
echo "jq succcesfully installed"
|
echo "jq succcesfully installed"
|
||||||
eval "jq -V"
|
eval "jq -V"
|
||||||
dependency_install=yes
|
dependency_install=yes
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_install_go() {
|
install_git() {
|
||||||
|
if ! command -v git 2>&1 >/dev/null; then
|
||||||
if ! command -v go 2>&1 >/dev/null; then
|
|
||||||
install_as_sudo
|
install_as_sudo
|
||||||
echo 'go module not installed'
|
echo 'git module not installed'
|
||||||
|
echo "now installing git..."
|
||||||
|
|
||||||
echo "now installing go..."
|
###download and install curl
|
||||||
echo "export GOPATH=$""HOME/go" >>$env_file
|
eval "echo $SUDO_PASS | sudo -S $install_cmd install git -y"
|
||||||
echo "export GO_HOME=/usr/local/go" >>$env_file
|
echo "git succcesfully installed"
|
||||||
echo "export PATH=$""PATH:$""GO_HOME/bin:$""GOPATH/bin" >>$env_file
|
eval "git -v"
|
||||||
eval "source $env_file"
|
|
||||||
|
|
||||||
###download and install go
|
|
||||||
get_system_information
|
|
||||||
eval "sudo rm -rf $GO_HOME"
|
|
||||||
command=$(curl $url | sudo tar -xz -C /usr/local)
|
|
||||||
eval "$command"
|
|
||||||
|
|
||||||
echo "go succcesfully installed"
|
|
||||||
eval "source $env_file"
|
|
||||||
eval "go version"
|
|
||||||
dependency_install=yes
|
dependency_install=yes
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_install_lego() {
|
install_go() {
|
||||||
|
if ! command -v go 2>&1 >/dev/null; then
|
||||||
|
install_as_sudo
|
||||||
|
echo 'go module not installed'
|
||||||
|
echo "now installing go..."
|
||||||
|
|
||||||
|
###download and install go
|
||||||
|
get_system_information
|
||||||
|
eval "echo $SUDO_PASS | sudo -S rm -rf $GO_HOME"
|
||||||
|
command=$(curl -o /tmp/$file_name $url)
|
||||||
|
eval "$command"
|
||||||
|
command=$(echo $SUDO_PASS | sudo -S tar -xf /tmp/$file_name -C /usr/local)
|
||||||
|
eval "$command"
|
||||||
|
|
||||||
|
echo "go succcesfully installed"
|
||||||
|
eval "go version"
|
||||||
|
|
||||||
|
command=$(rm /tmp/$file_name)
|
||||||
|
eval "$command"
|
||||||
|
dependency_install=yes
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_lego() {
|
||||||
if ! command -v lego 2>&1 >/dev/null; then
|
if ! command -v lego 2>&1 >/dev/null; then
|
||||||
|
|
||||||
echo 'lego could not be found'
|
echo 'lego could not be found'
|
||||||
|
|
||||||
echo 'now installing lego...'
|
echo 'now installing lego...'
|
||||||
export GO111MODULE=on
|
export GO111MODULE=on
|
||||||
|
|
||||||
@@ -113,8 +154,6 @@ check_install_lego() {
|
|||||||
sudo chown $USER:$USER -R $CERT_PATH
|
sudo chown $USER:$USER -R $CERT_PATH
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "export LEGO_PATH=$CERT_PATH/lego" >>$env_file
|
|
||||||
eval "source $env_file"
|
|
||||||
eval "go install github.com/go-acme/lego/v4/cmd/lego@latest"
|
eval "go install github.com/go-acme/lego/v4/cmd/lego@latest"
|
||||||
|
|
||||||
#add crontab for auto renewal of certificates (occurence is at monday,thursdays - can be changed)
|
#add crontab for auto renewal of certificates (occurence is at monday,thursdays - can be changed)
|
||||||
@@ -126,24 +165,73 @@ check_install_lego() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_system_information() {
|
install_web_server() {
|
||||||
|
install_as_sudo
|
||||||
|
echo "Install WebServer"
|
||||||
|
PS3="Select Option to enter option or and key to exit: "
|
||||||
|
options=("nginx" "apache" "haproxy")
|
||||||
|
select option in "${options[@]}"; do
|
||||||
|
case $option in
|
||||||
|
"nginx")
|
||||||
|
eval "echo $SUDO_PASS | sudo -S $install_cmd install nginx* -y"
|
||||||
|
printf "\n\n\n"
|
||||||
|
echo "run below command as admin on rhel type OS to allow network connections"
|
||||||
|
echo "setsebool httpd_can_network_connect 1"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
"apache")
|
||||||
|
eval "echo $SUDO_PASS | sudo -S $install_cmd install apach2e* -y"
|
||||||
|
printf "\n\n\n"
|
||||||
|
echo "run below command as admin on rhel type OS to allow network connections"
|
||||||
|
echo "setsebool httpd_can_network_connect 1"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
"haproxy")
|
||||||
|
eval "echo $SUDO_PASS | sudo -S $install_cmd install haproxy* -y"
|
||||||
|
printf "\n\n\n"
|
||||||
|
echo "run below command as admin on rhel type OS to allow network connections"
|
||||||
|
echo "setsebool httpd_can_network_connect 1"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
update_lego() {
|
||||||
|
export GO111MODULE=on
|
||||||
|
eval "go install github.com/go-acme/lego/v4/cmd/lego@latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_system_information() {
|
||||||
##go1.24.3.linux-amd64.tar.gz
|
##go1.24.3.linux-amd64.tar.gz
|
||||||
##https://dl.google.com/go/go1.24.3.linux-amd64.tar.gz
|
##https://dl.google.com/go/go1.24.3.linux-amd64.tar.gz
|
||||||
###As at writing script - go version is 1.24.3 (could find api to get current version)
|
###As at writing script - go version is 1.24.3 (could find api to get current version)
|
||||||
version="1.24.3"
|
version="1.24.5"
|
||||||
|
|
||||||
#Get System Information (Adapted to Debian - This would need changes for other OS's)
|
#Get System Information (Adapted to Debian - This would need changes for other OS's)
|
||||||
sys=$(uname -s)
|
sys=$(uname -s)
|
||||||
system=$(echo $sys | tr '[:upper:]' '[:lower:]')
|
system=$(echo $sys | tr '[:upper:]' '[:lower:]')
|
||||||
archictecture=$(dpkg --print-architecture)
|
|
||||||
|
|
||||||
#Form URL Based on system information
|
#Form URL Based on system information
|
||||||
url="https://dl.google.com/go/go$version.$system-$archictecture.tar.gz"
|
file_name="go$version.$system-amd64.tar.gz"
|
||||||
printf "\n"
|
url="https://dl.google.com/go/$file_name"
|
||||||
echo $url
|
}
|
||||||
printf "\n"
|
|
||||||
|
|
||||||
|
get_os_type() {
|
||||||
|
#get OSTYPE - modify to know defualt package name to use for installation
|
||||||
|
os_type=$(awk -F'=' '/ID_LIKE/ {print $2}' /etc/os-release | awk -F'"' '{print $2}')
|
||||||
|
if [[ $os_type == *"debian"* ]]; then
|
||||||
|
install_cmd="apt"
|
||||||
|
elif [[ $os_type == *"ubuntu"* ]]; then
|
||||||
|
install_cmd="apt"
|
||||||
|
elif [[ $os_type == *"almalinux"* ]]; then
|
||||||
|
install_cmd="yum"
|
||||||
|
elif [[ $os_type == *"redhat"* ]]; then
|
||||||
|
install_cmd="yum"
|
||||||
|
elif [[ $os_type == *"centos"* ]]; then
|
||||||
|
install_cmd="yum"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
@@ -202,9 +290,9 @@ autorenew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
functionlist() {
|
functionlist() {
|
||||||
echo "Usage: {run, renew, revoke, list}"
|
echo "Usage: {run, renew, revoke, list, update lego}"
|
||||||
PS3="Select Option to enter option or and key to exit: "
|
PS3="Select Option to enter option or and key to exit: "
|
||||||
options=("run" "revoke" "renew" "list")
|
options=("run" "revoke" "renew" "list" "update lego" "install web server")
|
||||||
select option in "${options[@]}"; do
|
select option in "${options[@]}"; do
|
||||||
case $option in
|
case $option in
|
||||||
"run")
|
"run")
|
||||||
@@ -219,6 +307,14 @@ functionlist() {
|
|||||||
"list")
|
"list")
|
||||||
list
|
list
|
||||||
;;
|
;;
|
||||||
|
"update lego")
|
||||||
|
update_lego
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
"install web server")
|
||||||
|
install_web_server
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
@@ -227,7 +323,6 @@ functionlist() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
functionvar() {
|
functionvar() {
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
"run")
|
"run")
|
||||||
run
|
run
|
||||||
@@ -247,6 +342,7 @@ functionvar() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_env_variables
|
||||||
check_dependencies
|
check_dependencies
|
||||||
|
|
||||||
cd $CERT_PATH
|
cd $CERT_PATH
|
||||||
@@ -255,11 +351,6 @@ echo "Acme Script for $DNS_PROVIDER"
|
|||||||
echo "Usage: only dns challenge function available"
|
echo "Usage: only dns challenge function available"
|
||||||
command="lego --email $CONTACT_MAIL --dns $DNS_PROVIDER "
|
command="lego --email $CONTACT_MAIL --dns $DNS_PROVIDER "
|
||||||
IFS=","
|
IFS=","
|
||||||
###TODO###
|
|
||||||
#available functions - can be used as a function list or a direct execute by passing action
|
|
||||||
#would write domains into file/list on issuance so it can be used for renewal
|
|
||||||
#revoked certificate names would be removed from existing list of issued certificates
|
|
||||||
#cron jobs would be created for renew function
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
functionlist
|
functionlist
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user