Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
7ea4d33e
Commit
7ea4d33e
authored
Aug 21, 2014
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify the input_box function
parent
980b83b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
96 deletions
+104
-96
functions.sh
setup/functions.sh
+7
-17
start.sh
setup/start.sh
+97
-79
No files found.
setup/functions.sh
View file @
7ea4d33e
...
...
@@ -134,21 +134,11 @@ function message_box {
}
function
input_box
{
TMP
=
`
mktemp
`
dialog
--title
"
$1
"
--inputbox
"
$2
"
0 0
"
$3
"
2>
$TMP
respose
=
$?
case
$respose
in
0
)
result
=
$(
<
$TMP
)
;;
1
)
exit
;;
255
)
exit
esac
rm
$TMP
# input_box "title" "prompt" "defaultvalue" VARIABLE
# The user's input will be stored in the variable VARIABLE.
# The exit code from dialog will be stored in VARIABLE_EXITCODE.
declare
-n
result
=
$4
declare
-n
result_code
=
$4_EXITCODE
result
=
$(
dialog
--stdout
--title
"
$1
"
--inputbox
"
$2
"
0 0
"
$3
"
)
result_code
=
$?
}
setup/start.sh
View file @
7ea4d33e
...
...
@@ -38,11 +38,14 @@ fi
if
[
-t
0
]
;
then
# In an interactive shell...
# Install dialog
echo
"Preparing installation ... "
# Install 'dialog' so we can ask the user questions. The original motivation for
# this was being able to ask the user for input even if stdin has been redirected,
# e.g. if we piped a bootstrapping install script to bash to get started.
apt_install dialog
message_box
"Hello and thanks for deploying a Mail-in-a-Box!"
\
"I'm going to ask you a few questions. To change your answers later, just re-run this script."
message_box
"Mail-in-a-Box Installation"
\
"Hello and thanks for deploying a Mail-in-a-Box!
\n\n
I'm going to ask you a few questions.
\n\n
To change your answers later, just re-run this script."
fi
# Recall the last settings used if we're running this a second time.
...
...
@@ -63,26 +66,32 @@ if [ -z "$PRIMARY_HOSTNAME" ]; then
if
[
-z
"
$DEFAULT_PRIMARY_HOSTNAME
"
]
;
then
# This is the first run. Ask the user for his email address so we can
# provide the best default for the box's hostname.
input_box
"What email address are you setting this box up to manage?"
\
"The part after the @-sign must be a domain name or subdomain
\n
that you control. You can add other email addresses to this
\n
box later (including email addresses on other domain names
\n
or subdomains you control).
\n
\n
We've guessed an email address. Backspace it and type in what
\n
you really want.
\n
\n
Email Address (me@
`
get_default_hostname
`
): "
if
[
-z
"
$result
"
]
;
then
EMAIL_ADDR
=
me@
`
get_default_hostname
`
else
EMAIL_ADDR
=
$result
input_box
"Your Email Address"
\
"What email address are you setting this box up to manage?
\n\n
The part after the @-sign must be a domain name or subdomain
that you control. You can add other email addresses to this
box later (including email addresses on other domain names
or subdomains you control).
\n\n
We've guessed an email address. Backspace it and type in what
you really want.
\n\n
Email Address:"
\
me@
`
get_default_hostname
`
\
EMAIL_ADDR
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# user hit ESC/cancel
exit
fi
while
!
management/mailconfig.py validate-email
"
$EMAIL_ADDR
"
do
input_box
"What email address are you setting this box up to manage?"
\
"That's not a valid email address."
$EMAIL_ADDR
EMAIL_ADDR
=
$result
input_box
"Your Email Address"
\
"That's not a valid email address.
\n\n
What email address are you setting this box up to manage?"
\
$EMAIL_ADDR
\
EMAIL_ADDR
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# user hit ESC/cancel
exit
fi
done
# Take the part after the @-sign as the user's domain name, and add
...
...
@@ -91,17 +100,17 @@ if [ -z "$PRIMARY_HOSTNAME" ]; then
fi
input_box
"Hostname"
\
"This box needs a name, called a 'hostname'. The name will form a part
\n
of the box's web address.
\n
\n
We recommend that the name be a subdomain of the domain in your email
\n
address, so we're suggesting
$DEFAULT_PRIMARY_HOSTNAME
.
\n
You can change it, but we recommend you don't.
\n
\n
Hostname (
$DEFAULT_PRIMARY_HOSTNAME
): "
if
[
-z
"
$result
"
]
;
then
PRIMARY_HOSTNAME
=
$DEFAULT_PRIMARY_HOSTNAME
else
PRIMARY_HOSTNAME
=
$resul
t
"This box needs a name, called a 'hostname'. The name will form a part of the box's web address.
\n\n
We recommend that the name be a subdomain of the domain in your email
address, so we're suggesting
$DEFAULT_PRIMARY_HOSTNAME
.
\n\n
You can change it, but we recommend you don't
.
\n\n
Hostname:"
\
$DEFAULT_PRIMARY_HOSTNAME
\
PRIMARY_HOSTNAME
if
[
-z
"
$PRIMARY_HOSTNAME
"
]
;
then
# user hit ESC/cancel
exi
t
fi
fi
...
...
@@ -128,15 +137,15 @@ if [ -z "$PUBLIC_IP" ]; then
fi
if
[
-z
"
$PUBLIC_IP
"
]
;
then
input_box
"
Your public IP a
ddress"
\
"Enter the public IP address of this machine,
as given to you by your ISP.
\n
\n
Public IP (
$DEFAULT_PUBLIC_IP
): "
if
[
-z
"
$result
"
]
;
then
PUBLIC_IP
=
$DEFAULT_PUBLIC_IP
else
PUBLIC_IP
=
$resul
t
input_box
"
Public IP A
ddress"
\
"Enter the public IP address of this machine, as given to you by your ISP.
\n\n
Public IP address:"
\
$DEFAULT_PUBLIC_IP
\
PUBLIC_IP
if
[
-z
"
$PUBLIC_IP
"
]
;
then
# user hit ESC/cancel
exi
t
fi
fi
fi
...
...
@@ -159,15 +168,16 @@ if [ -z "$PUBLIC_IPV6" ]; then
fi
if
[[
-z
"
$PUBLIC_IPV6
"
&&
$MATCHED
==
0
]]
;
then
input_box
"IPv6 Optional"
\
"Enter the public IPv6 address of this machine, as given to you by your ISP.
\n
Leave blank if the machine does not have an IPv6 address.
\n
\n
Public IPv6 (
$DEFAULT_PUBLIC_IPV6
): "
if
[
-z
"
$result
"
]
;
then
PUBLIC_IPV6
=
$DEFAULT_PUBLIC_IPV6
else
PUBLIC_IPV6
=
$result
input_box
"IPv6 Address (Optional)"
\
"Enter the public IPv6 address of this machine, as given to you by your ISP.
\n\n
Leave blank if the machine does not have an IPv6 address.
\n\n
Public IPv6 address:"
$DEFAULT_PUBLIC_IPV6
\
PUBLIC_IPV6
if
[
!
$PUBLIC_IPV6_EXITCODE
]
;
then
# user hit ESC/cancel
exit
fi
fi
fi
...
...
@@ -182,11 +192,13 @@ if [ -z "$PRIVATE_IPV6" ]; then
PRIVATE_IPV6
=
$(
get_default_privateip 6
)
fi
if
[[
-z
"
$PRIVATE_IP
"
&&
-z
"
$PRIVATE_IPV6
"
]]
;
then
message_box
"Error"
\
"I could not determine the IP or IPv6 address of the network inteface
\n
for connecting to the Internet. Setup must stop.
\n
`
hostname
-I
`
\n
`
route
`
"
echo
echo
"I could not determine the IP or IPv6 address of the network inteface"
echo
"for connecting to the Internet. Setup must stop."
echo
hostname
-I
route
echo
exit
fi
...
...
@@ -201,23 +213,22 @@ if [ ! -z "$DEFAULT_STORAGE_ROOT" ] && [ ! -z "$DEFAULT_CSR_COUNTRY" ] && [ -f $
fi
if
[
-z
"
$CSR_COUNTRY
"
]
;
then
input_box
"Country Code"
\
"Enter the two-letter, uppercase country code for where you
\n
live or where your organization is based. (This is used to
\n
create an SSL certificate.)
\n
\n
Country Code (
$DEFAULT_CSR_COUNTRY
): "
if
[
-z
"
$result
"
]
;
then
CSR_COUNTRY
=
$DEFAULT_CSR_COUNTRY
else
CSR_COUNTRY
=
$result
fi
#if [ -z "$DEFAULT_CSR_COUNTRY" ]; then
# # set a default on first run
# DEFAULT_CSR_COUNTRY=...?
#fi
input_box
"Country Code"
\
"Enter the two-letter, uppercase country code for where you live or where your
organization is based. (This is used to create an SSL certificate.)
\n\n
Country Code:"
\
$DEFAULT_CSR_COUNTRY
\
CSR_COUNTRY
if
[
-z
"
$CSR_COUNTRY
"
]
;
then
# user hit ESC/cancel
exit
fi
fi
# Automatic configuration, e.g. as used in our Vagrant configuration.
...
...
@@ -307,22 +318,29 @@ if [ -z "`tools/mail.py user`" ]; then
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# In an interactive shell, ask the user for an email address.
if
[
-t
0
]
;
then
input_box
"Create your first mail user"
\
"Let's create your first mail user.
\n
\n
Email Address (user@
$PRIMARY_HOSTNAME
): "
if
[
-z
"
$result
"
]
;
then
EMAIL_ADDR
=
me@
`
get_default_hostname
`
else
EMAIL_ADDR
=
$result
input_box
"Mail Account"
\
"Let's create your first mail account.
\n\n
What email address do you want?"
\
me@
`
get_default_hostname
`
\
EMAIL_ADDR
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# user hit ESC/cancel
exit
fi
while
!
management/mailconfig.py validate-email
"
$EMAIL_ADDR
"
do
input_box
"What email address are you setting this box up to manage?"
\
"That's not a valid email address."
$EMAIL_ADDR
EMAIL_ADDR
=
$result
input_box
"Mail Account"
\
"That's not a valid email address.
\n\n
What email address do you want?"
\
$EMAIL_ADDR
\
EMAIL_ADDR
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# user hit ESC/cancel
exit
fi
done
# But in a non-interactive shell, just make something up.
# This is normally for testing.
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment