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 {
...
@@ -134,21 +134,11 @@ function message_box {
}
}
function
input_box
{
function
input_box
{
TMP
=
`
mktemp
`
# input_box "title" "prompt" "defaultvalue" VARIABLE
dialog
--title
"
$1
"
--inputbox
"
$2
"
0 0
"
$3
"
2>
$TMP
# The user's input will be stored in the variable VARIABLE.
# The exit code from dialog will be stored in VARIABLE_EXITCODE.
respose
=
$?
declare
-n
result
=
$4
declare
-n
result_code
=
$4_EXITCODE
case
$respose
in
result
=
$(
dialog
--stdout
--title
"
$1
"
--inputbox
"
$2
"
0 0
"
$3
"
)
0
)
result_code
=
$?
result
=
$(
<
$TMP
)
;;
1
)
exit
;;
255
)
exit
esac
rm
$TMP
}
}
setup/start.sh
View file @
7ea4d33e
...
@@ -38,11 +38,14 @@ fi
...
@@ -38,11 +38,14 @@ fi
if
[
-t
0
]
;
then
if
[
-t
0
]
;
then
# In an interactive shell...
# In an interactive shell...
# Install dialog
# Install 'dialog' so we can ask the user questions. The original motivation for
echo
"Preparing installation ... "
# 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
apt_install dialog
message_box
"Hello and thanks for deploying a Mail-in-a-Box!"
\
message_box
"Mail-in-a-Box Installation"
\
"I'm going to ask you a few questions. To change your answers later, just re-run this script."
"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
fi
# Recall the last settings used if we're running this a second time.
# Recall the last settings used if we're running this a second time.
...
@@ -63,26 +66,32 @@ if [ -z "$PRIMARY_HOSTNAME" ]; then
...
@@ -63,26 +66,32 @@ if [ -z "$PRIMARY_HOSTNAME" ]; then
if
[
-z
"
$DEFAULT_PRIMARY_HOSTNAME
"
]
;
then
if
[
-z
"
$DEFAULT_PRIMARY_HOSTNAME
"
]
;
then
# This is the first run. Ask the user for his email address so we can
# This is the first run. Ask the user for his email address so we can
# provide the best default for the box's hostname.
# provide the best default for the box's hostname.
input_box
"What email address are you setting this box up to manage?"
\
input_box
"Your Email Address"
\
"The part after the @-sign must be a domain name or subdomain
"What email address are you setting this box up to manage?
\n
that you control. You can add other email addresses to this
\n\n
The part after the @-sign must be a domain name or subdomain
\n
box later (including email addresses on other domain names
that you control. You can add other email addresses to this
\n
or subdomains you control).
\n
box later (including email addresses on other domain names
\n
We've guessed an email address. Backspace it and type in what
or subdomains you control).
\n
you really want.
\n
\n\n
We've guessed an email address. Backspace it and type in what
\n
Email Address (me@
`
get_default_hostname
`
): "
you really want.
\n\n
Email Address:"
\
if
[
-z
"
$result
"
]
;
then
me@
`
get_default_hostname
`
\
EMAIL_ADDR
=
me@
`
get_default_hostname
`
EMAIL_ADDR
else
EMAIL_ADDR
=
$result
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# user hit ESC/cancel
exit
fi
fi
while
!
management/mailconfig.py validate-email
"
$EMAIL_ADDR
"
while
!
management/mailconfig.py validate-email
"
$EMAIL_ADDR
"
do
do
input_box
"What email address are you setting this box up to manage?"
\
input_box
"Your Email Address"
\
"That's not a valid email address."
$EMAIL_ADDR
"That's not a valid email address.
\n\n
What email address are you setting this box up to manage?"
\
EMAIL_ADDR
=
$result
$EMAIL_ADDR
\
EMAIL_ADDR
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# user hit ESC/cancel
exit
fi
done
done
# Take the part after the @-sign as the user's domain name, and add
# Take the part after the @-sign as the user's domain name, and add
...
@@ -91,17 +100,17 @@ if [ -z "$PRIMARY_HOSTNAME" ]; then
...
@@ -91,17 +100,17 @@ if [ -z "$PRIMARY_HOSTNAME" ]; then
fi
fi
input_box
"Hostname"
\
input_box
"Hostname"
\
"This box needs a name, called a 'hostname'. The name will form a part
"This box needs a name, called a 'hostname'. The name will form a part of the box's web address.
\n
of the box's web address.
\n
\n\n
We recommend that the name be a subdomain of the domain in your email
\n
We recommend that the name be a subdomain of the domain in your email
address, so we're suggesting
$DEFAULT_PRIMARY_HOSTNAME
.
\n
address, so we're suggesting
$DEFAULT_PRIMARY_HOSTNAME
.
\n\n
You can change it, but we recommend you don't
.
\n
You can change it, but we recommend you don't.
\n
\n\n
Hostname:"
\
\n
Hostname (
$DEFAULT_PRIMARY_HOSTNAME
): "
$DEFAULT_PRIMARY_HOSTNAME
\
PRIMARY_HOSTNAME
if
[
-z
"
$result
"
]
;
then
PRIMARY_HOSTNAME
=
$DEFAULT_PRIMARY_HOSTNAME
if
[
-z
"
$PRIMARY_HOSTNAME
"
]
;
then
else
# user hit ESC/cancel
PRIMARY_HOSTNAME
=
$resul
t
exi
t
fi
fi
fi
fi
...
@@ -128,15 +137,15 @@ if [ -z "$PUBLIC_IP" ]; then
...
@@ -128,15 +137,15 @@ if [ -z "$PUBLIC_IP" ]; then
fi
fi
if
[
-z
"
$PUBLIC_IP
"
]
;
then
if
[
-z
"
$PUBLIC_IP
"
]
;
then
input_box
"
Your public IP a
ddress"
\
input_box
"
Public IP A
ddress"
\
"Enter the public IP address of this machine,
"Enter the public IP address of this machine, as given to you by your ISP.
as given to you by your ISP.
\n
\n\n
Public IP address:"
\
\n
Public IP (
$DEFAULT_PUBLIC_IP
): "
$DEFAULT_PUBLIC_IP
\
PUBLIC_IP
if
[
-z
"
$result
"
]
;
then
PUBLIC_IP
=
$DEFAULT_PUBLIC_IP
if
[
-z
"
$PUBLIC_IP
"
]
;
then
else
# user hit ESC/cancel
PUBLIC_IP
=
$resul
t
exi
t
fi
fi
fi
fi
fi
fi
...
@@ -159,15 +168,16 @@ if [ -z "$PUBLIC_IPV6" ]; then
...
@@ -159,15 +168,16 @@ if [ -z "$PUBLIC_IPV6" ]; then
fi
fi
if
[[
-z
"
$PUBLIC_IPV6
"
&&
$MATCHED
==
0
]]
;
then
if
[[
-z
"
$PUBLIC_IPV6
"
&&
$MATCHED
==
0
]]
;
then
input_box
"IPv6 Optional"
\
input_box
"IPv6 Address (Optional)"
\
"Enter the public IPv6 address of this machine, as given to you by your ISP.
"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\n
Leave blank if the machine does not have an IPv6 address.
\n
Public IPv6 (
$DEFAULT_PUBLIC_IPV6
): "
\n\n
Public IPv6 address:"
$DEFAULT_PUBLIC_IPV6
\
if
[
-z
"
$result
"
]
;
then
PUBLIC_IPV6
PUBLIC_IPV6
=
$DEFAULT_PUBLIC_IPV6
else
if
[
!
$PUBLIC_IPV6_EXITCODE
]
;
then
PUBLIC_IPV6
=
$result
# user hit ESC/cancel
exit
fi
fi
fi
fi
fi
fi
...
@@ -182,11 +192,13 @@ if [ -z "$PRIVATE_IPV6" ]; then
...
@@ -182,11 +192,13 @@ if [ -z "$PRIVATE_IPV6" ]; then
PRIVATE_IPV6
=
$(
get_default_privateip 6
)
PRIVATE_IPV6
=
$(
get_default_privateip 6
)
fi
fi
if
[[
-z
"
$PRIVATE_IP
"
&&
-z
"
$PRIVATE_IPV6
"
]]
;
then
if
[[
-z
"
$PRIVATE_IP
"
&&
-z
"
$PRIVATE_IPV6
"
]]
;
then
message_box
"Error"
\
echo
"I could not determine the IP or IPv6 address of the network inteface
echo
"I could not determine the IP or IPv6 address of the network inteface"
\n
for connecting to the Internet. Setup must stop.
\n
echo
"for connecting to the Internet. Setup must stop."
`
hostname
-I
`
\n
echo
`
route
`
"
hostname
-I
route
echo
exit
exit
fi
fi
...
@@ -201,23 +213,22 @@ if [ ! -z "$DEFAULT_STORAGE_ROOT" ] && [ ! -z "$DEFAULT_CSR_COUNTRY" ] && [ -f $
...
@@ -201,23 +213,22 @@ if [ ! -z "$DEFAULT_STORAGE_ROOT" ] && [ ! -z "$DEFAULT_CSR_COUNTRY" ] && [ -f $
fi
fi
if
[
-z
"
$CSR_COUNTRY
"
]
;
then
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
#if [ -z "$DEFAULT_CSR_COUNTRY" ]; then
# # set a default on first run
# # set a default on first run
# DEFAULT_CSR_COUNTRY=...?
# DEFAULT_CSR_COUNTRY=...?
#fi
#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
fi
# Automatic configuration, e.g. as used in our Vagrant configuration.
# Automatic configuration, e.g. as used in our Vagrant configuration.
...
@@ -307,22 +318,29 @@ if [ -z "`tools/mail.py user`" ]; then
...
@@ -307,22 +318,29 @@ if [ -z "`tools/mail.py user`" ]; then
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# In an interactive shell, ask the user for an email address.
# In an interactive shell, ask the user for an email address.
if
[
-t
0
]
;
then
if
[
-t
0
]
;
then
input_box
"Create your first mail user"
\
input_box
"Mail Account"
\
"Let's create your first mail user.
\n
"Let's create your first mail account.
\n
Email Address (user@
$PRIMARY_HOSTNAME
): "
\n\n
What email address do you want?"
\
me@
`
get_default_hostname
`
\
if
[
-z
"
$result
"
]
;
then
EMAIL_ADDR
EMAIL_ADDR
=
me@
`
get_default_hostname
`
else
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
EMAIL_ADDR
=
$result
# user hit ESC/cancel
exit
fi
fi
while
!
management/mailconfig.py validate-email
"
$EMAIL_ADDR
"
while
!
management/mailconfig.py validate-email
"
$EMAIL_ADDR
"
do
do
input_box
"What email address are you setting this box up to manage?"
\
input_box
"Mail Account"
\
"That's not a valid email address."
$EMAIL_ADDR
"That's not a valid email address.
EMAIL_ADDR
=
$result
\n\n
What email address do you want?"
\
$EMAIL_ADDR
\
EMAIL_ADDR
if
[
-z
"
$EMAIL_ADDR
"
]
;
then
# user hit ESC/cancel
exit
fi
done
done
# But in a non-interactive shell, just make something up.
# But in a non-interactive shell, just make something up.
# This is normally for testing.
# This is normally for testing.
else
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