mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-20 02:52:11 +00:00
comments and touch-ups
This commit is contained in:
parent
2abaa7415d
commit
5262f53be0
@ -1,21 +1,26 @@
|
||||
# This script deals with the Mail-in-a-Box configuration
|
||||
# (usually located at /home/user-data/settings.yaml)
|
||||
# to see if the user has agreed to Mail-in-a-Box.
|
||||
# This script can either check, or write in the configuration
|
||||
# that the user has agreed.
|
||||
|
||||
#usage: python setup/agreement.py [set, check] [YAML file]
|
||||
#example: python setup/agreement.py set /home/user-data/settings.yaml
|
||||
# prints: (nothing)
|
||||
#example: python setyp/agreement.py check /home/user-data/settings.yaml
|
||||
# prints: "true" or "false"
|
||||
|
||||
|
||||
import sys
|
||||
import rtyaml
|
||||
import collections
|
||||
import os.path
|
||||
|
||||
def load_environment():
|
||||
# Load settings from a KEY=VALUE file.
|
||||
import collections
|
||||
env = collections.OrderedDict()
|
||||
for line in open("/etc/mailinabox.conf"): env.setdefault(*line.strip().split("=", 1))
|
||||
return env
|
||||
|
||||
def write_settings(config, env):
|
||||
def write_settings(config):
|
||||
fn = sys.argv[2]
|
||||
with open(fn, "w") as f:
|
||||
f.write(rtyaml.dump(config))
|
||||
|
||||
def load_settings(env):
|
||||
def load_settings():
|
||||
fn = sys.argv[2]
|
||||
try:
|
||||
config = rtyaml.load(open(fn, "r"))
|
||||
@ -24,8 +29,6 @@ def load_settings(env):
|
||||
except:
|
||||
return { }
|
||||
|
||||
env = load_environment()
|
||||
|
||||
if(sys.argv[2]):
|
||||
|
||||
if( sys.argv[1] == "check" ):
|
||||
@ -38,7 +41,7 @@ if(sys.argv[2]):
|
||||
|
||||
|
||||
elif( sys.argv[1] == "set" ):
|
||||
config = load_settings(env)
|
||||
config = load_settings()
|
||||
|
||||
config["mailinabox-agreement"] = True
|
||||
write_settings( config, env )
|
||||
write_settings( config )
|
@ -227,6 +227,7 @@ function git_clone {
|
||||
function set_storage_user {
|
||||
# Set STORAGE_USER to default values ( user-data ), unless
|
||||
# we've already got those values from a previous run.
|
||||
|
||||
if [ -z "${STORAGE_USER:-}" ]; then
|
||||
STORAGE_USER=$([[ -z "${DEFAULT_STORAGE_USER:-}" ]] && echo "user-data" || echo "$DEFAULT_STORAGE_USER")
|
||||
fi
|
||||
@ -235,6 +236,7 @@ function set_storage_user {
|
||||
function set_storage_root {
|
||||
# Set STORAGE_ROOT to default values ( /home/user-data ), unless
|
||||
# we've already got those values from a previous run.
|
||||
|
||||
if [ -z "${STORAGE_USER:-}" ]; then
|
||||
STORAGE_USER=$([[ -z "${DEFAULT_STORAGE_USER:-}" ]] && echo "user-data" || echo "$DEFAULT_STORAGE_USER")
|
||||
fi
|
||||
@ -244,28 +246,32 @@ function set_storage_root {
|
||||
}
|
||||
|
||||
function check_config_agreed {
|
||||
#This function has no arguments
|
||||
#This will check Mail-in-a-Box's configuration to see if the user has agreed to Mail-in-a-Box
|
||||
#The configuration is usually held in /home/user-data/settings.yaml
|
||||
|
||||
set_storage_user;
|
||||
set_storage_root;
|
||||
|
||||
if [ -z "${I_AGREE_MAILINABOX:-}" ]; then
|
||||
if [ ! -d $STORAGE_ROOT ]; then
|
||||
return 1
|
||||
fi
|
||||
if [ ! -f $STORAGE_ROOT/settings.yaml ]; then
|
||||
return 1
|
||||
fi
|
||||
local current_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
local yaml_agreed=$(python "${current_directory}"/agreement.py check "${STORAGE_ROOT}/settings.yaml")
|
||||
if [ "$yaml_agreed" -eq "true"]; then
|
||||
return 0
|
||||
fi
|
||||
if [ ! -d $STORAGE_ROOT ]; then
|
||||
return 1
|
||||
else
|
||||
fi
|
||||
if [ ! -f $STORAGE_ROOT/settings.yaml ]; then
|
||||
return 1
|
||||
fi
|
||||
local current_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
local yaml_agreed=$(python "${current_directory}"/agreement.py check "${STORAGE_ROOT}"/settings.yaml; echo "${1:-}")
|
||||
if [ $yaml_agreed == "true" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
function set_config_agreed {
|
||||
#This function has no arguments
|
||||
#This will write down in Mail-in-a-Box's configuration that the user has agreed to Mail-in-a-Box.
|
||||
#The configuration is usually held in /home/user-data/settings.yaml
|
||||
|
||||
set_storage_user;
|
||||
set_storage_root;
|
||||
|
||||
|
@ -9,13 +9,15 @@ if [ -z "${NONINTERACTIVE:-}" ]; then
|
||||
if [ ! -f /usr/bin/dialog ] || [ ! -f /usr/bin/python3 ] || [ ! -f /usr/bin/pip3 ]; then
|
||||
echo Installing packages needed for setup...
|
||||
apt-get -q -q update
|
||||
apt_get_quiet install dialog python3 python3-pip || exit 1
|
||||
apt_get_quiet install dialog python3 python3-pip python-pip || exit 1
|
||||
fi
|
||||
|
||||
# Installing email_validator is repeated in setup/management.sh, but in setup/management.sh
|
||||
# we install it inside a virtualenv. In this script, we don't have the virtualenv yet
|
||||
# so we install the python package globally.
|
||||
hide_output pip3 install "email_validator>=1.0.0" || exit 1
|
||||
# Installing rtyaml, so that we can check if the user has already agreed to Mail-in-a-Box.
|
||||
hide_output pip install rtyaml || exit 1
|
||||
|
||||
message_box "Mail-in-a-Box Installation" \
|
||||
"Hello and thanks for deploying a Mail-in-a-Box!
|
||||
@ -23,9 +25,11 @@ if [ -z "${NONINTERACTIVE:-}" ]; then
|
||||
\n\nTo change your answers later, just run 'sudo mailinabox' from the command line.
|
||||
\n\nNOTE: You should only install this on a brand new Ubuntu installation 100% dedicated to Mail-in-a-Box. Mail-in-a-Box will, for example, remove apache2."
|
||||
|
||||
# Checks if there is already a variable that says the user has agreed to Mail-in-a-Box's Legal Notice.
|
||||
if [ -z "${I_AGREE_MAILINABOX:-}" ]; then
|
||||
|
||||
|
||||
# Checks if there is already a variable that says the user has agreed to Mail-in-a-Box's Legal Notice.
|
||||
if [ $(check_config_agreed; echo $?) -eq "1" ]; then
|
||||
|
||||
#makes sure the user is aware of our legal stuff.
|
||||
@ -43,13 +47,20 @@ if [ -z "${NONINTERACTIVE:-}" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
#sets I-agree variable
|
||||
I_AGREE_MAILINABOX="$(/bin/true)"
|
||||
|
||||
|
||||
#what to do if we are not running interactive mode.
|
||||
else
|
||||
|
||||
#checks if the configuration file says the user has already agreed
|
||||
if [ $(check_config_agreed; echo $?) -eq "0" ]; then
|
||||
#sets I-agree variable
|
||||
I_AGREE_MAILINABOX="$(/bin/true)"
|
||||
fi
|
||||
|
||||
#Checks if I-agree variable exists.
|
||||
#This is so a user can programmatically agree to our legal notice
|
||||
if [ -z "${I_AGREE_MAILINABOX:-}" ]; then
|
||||
echo "ERROR: You must agree to Mail-in-a-Box's Legal Notice. You can either:"
|
||||
@ -58,6 +69,7 @@ else
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
#sets I-agree variable
|
||||
I_AGREE_MAILINABOX=$(/bin/true)
|
||||
fi
|
||||
|
||||
|
@ -55,17 +55,22 @@ chmod +x /usr/local/bin/mailinabox
|
||||
# if values have not already been set in environment variables. When running
|
||||
# non-interactively, be sure to set values for all! Also sets STORAGE_USER and
|
||||
# STORAGE_ROOT.
|
||||
# Also provides legal notice and consdent from user to (for example) auto-agree
|
||||
# Let's Encrypt.
|
||||
source setup/questions.sh
|
||||
|
||||
|
||||
# Checks configuration to see if the user has agreed to Mail-in-a-Box's legal notice.
|
||||
I_AGREE_MAILINABOX=$(check_config_agreed; echo $?)
|
||||
|
||||
# Errors if no legal agreement was met.
|
||||
if [ -z "${I_AGREE_MAILINABOX:-}" ]; then
|
||||
echo "ERROR: You must agree to Mail-in-a-Box's Legal Notice. You can either:"
|
||||
echo "run this in interactive mode; or"
|
||||
echo "set I_AGREE_MAILINABOX variable before running."
|
||||
exit 1;
|
||||
else
|
||||
#Writes to configuration that the user has agreed to Mail-in-a-Box's legal notice.
|
||||
set_config_agreed;
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user