Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compose.libre.sh
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timothee Gosselin
compose.libre.sh
Commits
68636a02
"utils/provision" did not exist on "d2c621d625a01d56fbf43e018634274735fa859f"
Commit
68636a02
authored
10 years ago
by
Pierre Ozoux
Browse files
Options
Downloads
Patches
Plain Diff
Updates provision to be more flexible
parent
d852074a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/provision.sh
+102
-41
102 additions, 41 deletions
scripts/provision.sh
with
102 additions
and
41 deletions
scripts/provision.sh
+
102
−
41
View file @
68636a02
#!/usr/bin/env bash
#
Registe
r a user for IndiePaaS
#
Provision an application fo
r a user for IndiePaaS
#
# This file:
# - Registers the domain name to NameCheap
...
...
@@ -7,13 +7,13 @@
# - Configures the DNS
# - Configures the mail forwarding
#
# Version 0.0.
1
# Version 0.0.
2
#
# Authors:
# - Pierre Ozoux (pierre-o.fr)
#
# Usage:
# LOG_LEVEL=7 ./
register.sh -n
example.org -
d
# LOG_LEVEL=7 ./
provision.sh -e test@test.org -a known -u
example.org -
g -b -c
#
# Licensed under AGPLv3
...
...
@@ -27,7 +27,13 @@ LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency
# Commandline options. This defines the usage page, and is used to parse cli
# opts & defaults from. The parsing is unforgiving so be precise in your syntax
read
-r
-d
''
usage
<<-
'
EOF
'
-n [arg] Domain name to process. Required.
-a [arg] Application to provision (static, wordpress or known). Required.
-e [arg] Email of the user of the application. Required.
-u [arg] URL to process. Required.
-f [arg] Certificate file to use.
-g Generate the necessary certificate.
-b Buy the associated domain name.
-c Configure DNS on Namecheap.
-d Enables debug mode
-h This page
EOF
...
...
@@ -49,17 +55,18 @@ function contains () {
}
function
TLD
()
{
echo
${
arg_
n
}
|
cut
-d
.
-f2
,3
echo
${
arg_
u
}
|
cut
-d
.
-f2
,3
}
function
SLD
()
{
echo
${
arg_
n
}
|
cut
-d
.
-f1
echo
${
arg_
u
}
|
cut
-d
.
-f1
}
function
call_API
()
{
output
=
$(
curl
-s
"https://api.
$NAMECHEAP_URL
/xml.response
\?
ApiUser=
${
NAMECHEAP_API_USER
}
&ApiKey=
${
NAMECHEAP_API_KEY
}
&UserName=
${
NAMECHEAP_API_USER
}
&ClientIp=
${
IP
}
$1
"
)
url
=
"https://api.
$NAMECHEAP_URL
/xml.response
\?
ApiUser=
${
NAMECHEAP_API_USER
}
&ApiKey=
${
NAMECHEAP_API_KEY
}
&UserName=
${
NAMECHEAP_API_USER
}
&ClientIp=
${
IP
}
$1
"
output
=
$(
curl
-s
${
url
}
)
if
[
-z
$(
echo
${
output
}
|
grep
'Status="OK"'
)
]
;
then
if
[
$(
echo
${
output
}
|
grep
-c
'Status="OK"'
)
-eq
0
]
;
then
error
"API call failed. Please read the output"
echo
${
output
}
exit
1
...
...
@@ -69,17 +76,54 @@ function call_API () {
}
function
create_domain_name
()
{
function
scaffold
()
{
supported_applications
=(
"static"
"wordpress"
"known"
)
if
[
$(
contains
"
${
supported_applications
[@]
}
"
"
${
arg_a
}
"
)
==
"n"
]
;
then
error
"Application
${
arg_a
}
is not yet supported."
exit
1
fi
info
"ceating application folder"
mkdir
-p
${
FOLDER
}
info
"creating .env"
echo
"EMAIL=
${
arg_e
}
"
>
${
FOLDER
}
/.env
case
"
${
arg_a
}
"
in
"static"
)
echo
APPLICATION
=
nginx
>>
${
FOLDER
}
/.env
echo
DOCKER_ARGUMENTS
=
"-v
${
APP_FODLER
}
/www-content:/app"
>>
${
FOLDER
}
/.env
;;
"wordpress"
)
echo
APPLICATION
=
${
arg_a
}
>>
${
FOLDER
}
/.env
echo
DOCKER_ARGUMENTS
=
"--link mysql-
${
arg_u
}
:db
\
-v
${
APP_FODLER
}
/data:/app/wp-content
\
-v
${
APP_FODLER
}
/.htaccess:/app/.htaccess
\
--env-file
${
APP_FODLER
}
/.env"
>>
${
FOLDER
}
/.env
;;
"known"
)
echo
APPLICATION
=
${
arg_a
}
>>
${
FOLDER
}
/.env
echo
DOCKER_ARGUMENTS
=
"--link mysql-
${
arg_u
}
:db
\
-v
${
APP_FODLER
}
/data:/app/Uploads
\
-v
${
APP_FODLER
}
/.htaccess:/app/.htaccess
\
--env-file
${
APP_FODLER
}
/.env"
>>
${
FOLDER
}
/.env
;;
esac
info
"Scaffold created with success."
}
function
buy_domain_name
()
{
not_supported_extensions
=(
"us"
"eu"
"nu"
"asia"
"ca"
"co.uk"
"me.uk"
"org.uk"
"com.au"
"net.au"
"org.au"
"es"
"nom.es"
"com.es"
"org.es"
"de"
"fr"
""
)
not_supported_extensions
=(
"us"
"eu"
"nu"
"asia"
"ca"
"co.uk"
"me.uk"
"org.uk"
"com.au"
"net.au"
"org.au"
"es"
"nom.es"
"com.es"
"org.es"
"de"
"fr"
)
if
[
$(
contains
"
${
not_supported_extensions
[@]
}
"
"
$(
TLD
)
"
)
==
"y"
]
;
then
error
"Extension .
$
{
extension
}
is not yet supported.."
error
"Extension .
$
(
TLD
)
is not yet supported.."
exit
1
fi
info
"Buying Domain name."
arguments
=
"&Command=namecheap.domains.create
\
&DomainName=
${
arg_
n
}
\
&DomainName=
${
arg_
u
}
\
&Years=1
\
&AuxBillingFirstName=
${
FirstName
}
\
&AuxBillingLastName=
${
LastName
}
\
...
...
@@ -122,36 +166,47 @@ function create_domain_name () {
info
"Changing email forwarding."
arguments
=
"&Command=namecheap.domains.dns.setEmailForwarding
\
&DomainName=
${
arg_
n
}
\
&DomainName=
${
arg_
u
}
\
&mailbox1=hostmaster
\
&ForwardTo1=
${
EmailAddress
}
"
call_API
${
arguments
}
}
function
generate_certificate
()
{
function
provision_certificate
()
{
filename
=
$(
basename
"
${
arg_f
}
"
)
extension
=
"
${
filename
##*.
}
"
if
[
"
${
extension
}
"
!=
"pem"
]
;
then
error
"File extension must be pem."
exit
1
fi
TLS_FOLDER
=
/data/import/
${
arg_n
}
/TLS
info
"Provisionning certificate."
cp
-Ra
$(
dirname
${
arg_f
}
)
${
TLS_FOLDER
}
cd
${
TLS_FOLDER
}
mv
*
.pem
${
arg_u
}
.pem
}
info
"Creating import folder."
function
generate_certificate
()
{
info
"creating TLS ans CSR folder."
mkdir
-p
${
TLS_FOLDER
}
/CSR
info
"Generating the key."
openssl genrsa
-out
${
TLS_FOLDER
}
/
/
CSR/
${
arg_
n
}
.key 4096
openssl genrsa
-out
${
TLS_FOLDER
}
/CSR/
${
arg_
u
}
.key 4096
info
"Creating the request."
openssl req
-new
\
-key
${
TLS_FOLDER
}
/CSR/
${
arg_
n
}
.key
\
-out
${
TLS_FOLDER
}
/CSR/
${
arg_
n
}
.csr
\
-subj
"/C=
${
CountryCode
}
/ST=
${
City
}
/L=
${
City
}
/O=
${
arg_
n
}
/OU=/CN=
${
arg_
n
}
/emailAddress=
${
EmailAddress
}
"
-key
${
TLS_FOLDER
}
/CSR/
${
arg_
u
}
.key
\
-out
${
TLS_FOLDER
}
/CSR/
${
arg_
u
}
.csr
\
-subj
"/C=
${
CountryCode
}
/ST=
${
City
}
/L=
${
City
}
/O=
${
arg_
u
}
/OU=/CN=
${
arg_
u
}
/emailAddress=
${
EmailAddress
}
"
info
"Here is your CSR, paste it in your Certificate authority interface."
echo
""
cat
${
TLS_FOLDER
}
/CSR/
${
arg_
n
}
.csr
cat
${
TLS_FOLDER
}
/CSR/
${
arg_
u
}
.csr
echo
""
info
"You should have received a certificate"
info
"Please paste your certificate now"
info
"You should have received a certificate
.
"
info
"Please paste your certificate now
:
"
IFS
=
read
-d
''
-n
1 certificate
while
IFS
=
read
-d
''
-n
1
-t
2 c
do
...
...
@@ -162,16 +217,16 @@ function generate_certificate () {
echo
${
certificate
}
fi
echo
${
certificate
}
>
${
TLS_FOLDER
}
/CSR/
${
arg_
n
}
.cert
echo
${
certificate
}
>
${
TLS_FOLDER
}
/CSR/
${
arg_
u
}
.cert
info
"Concat certificate, CA and key into pem file"
cat
${
TLS_FOLDER
}
/CSR/
${
arg_
n
}
.cert /data/indiehosters/scripts/sub.class2.server.ca.pem
${
TLS_FOLDER
}
/CSR/
${
arg_
n
}
.key
>
${
TLS_FOLDER
}
/
${
arg_
n
}
.pem
info
"Concat certificate, CA and key into pem file
.
"
cat
${
TLS_FOLDER
}
/CSR/
${
arg_
u
}
.cert /data/indiehosters/scripts/sub.class2.server.ca.pem
${
TLS_FOLDER
}
/CSR/
${
arg_
u
}
.key
>
${
TLS_FOLDER
}
/
${
arg_
u
}
.pem
}
function
configure_dns
()
{
info
"Configuring DNS."
arguments
=
"&Command=namecheap.domains.dns.setHosts
\
&DomainName=
${
arg_
n
}
\
&DomainName=
${
arg_
u
}
\
&SLD=
$(
SLD
)
\
&TLD=
$(
TLD
)
\
&HostName1=@
\
...
...
@@ -179,14 +234,15 @@ function configure_dns () {
&Address1=
${
IP
}
\
&HostName2=www
\
&RecordType2=CNAME
\
&Address2=
${
arg_
n
}
\
&Address2=
${
arg_
u
}
\
&HostName3=mail
\
&RecordType3=A
\
&Address3=
${
IP
}
\
&HostName4=@
\
&RecordType4=MX
\
&Address4=mail.
${
arg_n
}
\
&MXPref4=10"
&Address4=mail.
${
arg_u
}
\
&MXPref4=10
\
&EmailType=mx"
call_API
${
arguments
}
...
...
@@ -226,11 +282,6 @@ function help () {
exit
1
}
function
cleanup_before_exit
()
{
info
"Cleaning up. Done"
}
trap
cleanup_before_exit EXIT
### Parse commandline options
#####################################################################
...
...
@@ -299,8 +350,10 @@ fi
### Validation (decide what's required for running your script and error out)
#####################################################################
[
-z
"
${
arg_n
}
"
]
&&
help
"Setting a domain name with -n is required"
[
-z
"
${
LOG_LEVEL
}
"
]
&&
emergency
"Cannot continue without LOG_LEVEL. "
[
-z
"
${
arg_a
}
"
]
&&
help
"Application is required."
[
-z
"
${
arg_e
}
"
]
&&
help
"Email is required."
[
-z
"
${
arg_u
}
"
]
&&
help
"URL is required."
[
-z
"
${
LOG_LEVEL
}
"
]
&&
emergency
"Cannot continue without LOG_LEVEL."
### Runtime
...
...
@@ -320,6 +373,14 @@ if [[ "${OSTYPE}" == "darwin"* ]]; then
info
"You are on OSX"
fi
create_domain_name
generate_certificate
configure_dns
FOLDER
=
/data/domains/
${
arg_u
}
APP_FODLER
=
${
FOLDER
}
/
${
arg_a
}
TLS_FOLDER
=
${
FOLDER
}
/TLS
[
${
arg_b
}
-eq
1
]
&&
buy_domain_name
scaffold
[
${
arg_g
}
-eq
1
]
&&
generate_certificate
[
!
-z
"
${
arg_f
}
"
]
&&
provision_certificate
[
${
arg_c
}
-eq
1
]
&&
configure_dns
exit
0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment