Welcome to mirror list, hosted at ThFree Co, Russian Federation.

INSTALL - github.com/lavabit/magma.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 144428b62e48236244a217690af8e73309043f35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# This script is targeting CentOS release 6.5

readonly PROGNAME=$(basename $0)

# Usage
usage () {
	cat <<- EOF
	Usage: $PROGNAME -d <install_directory> -u <mysql_user> -p <mysql_password> -s <mysql_schema>
	
	Installs Magma Classic to the provided directory

	OPTIONS:
	  -d        directory to install magma to
	  -u        mysql user
	  -p        mysql password
	  -s        mysql schema

	Example: $PROGNAME -d ~/ -u magma -p volcano -s Lavabit

	EOF
}

# Process user input
while getopts ":d:u:p:s:" opt; do
    case $opt in
        d)
            export BASE_DIR=$(readlink -m "$OPTARG/magma")
            ;;
        u)
            export MYSQL_USER="$OPTARG"
            ;;
        p)
            export MYSQL_PASSWORD="$OPTARG"
            ;;
        s)
            export MYSQL_SCHEMA="$OPTARG"
            ;;
        \?)
            echo "Invalid option: -$OPTARG" >&2
            exit 1
            ;;
        :)
            echo "Option -$OPTARG requires an argument" >&2
            exit 1
            ;;
    esac
done


if [ -z "$BASE_DIR" \
	-o -z "$MYSQL_USER" \
	-o -z "$MYSQL_PASSWORD" \
	-o -z "$MYSQL_SCHEMA" ]; then
	usage
	echo "None of the user input is optional"
	exit 1
fi

export SALT=`echo "$(dd if=/dev/urandom bs=33 count=1 | base64 --wrap=300)"`
export SESSION=`echo "$(dd if=/dev/urandom bs=33 count=1 | base64 --wrap=300)"`

# Check for prerequisites
if [ ! -e /etc/init.d/mysqld ]; then
	echo "Can't find /etc/init.d/mysqld"
	echo "Is mysql-server installed?"
	exit 1
fi

if [ ! -e /etc/init.d/memcached ]; then
	echo "Can't find /etc/init.d/memcached"
	echo "Is memcached installed?"
	exit 1
fi

if [ ! -e /tmp/mysql.sock ]; then
	if [ -S /var/lib/mysql/mysql.sock ]; then
		echo "Creating a link to the local mysql socket"
		echo "You may need to enter the root user password"
		su - -c 'ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock'
	else
		echo "/var/lib/mysql/mysql.sock is not a Socket file"
		echo "Is mysql-server installed?"
		exit 1
	fi
fi

# Check limits.conf for our entry
grep "*                hard    memlock         1024" /etc/security/limits.conf

if [ $? -ne 0 ]; then
	echo "Adding entries to /etc/security/limits.conf"
	echo "You may need to enter the root user password"
	su - -c 'printf "*                hard    memlock         1024\n*                soft    memlock         1024" >> /etc/security/limits.conf'
fi

# Check user is running script from inside the tarball
if [ ! -d scripts/ ]; then
	echo "Please run this script from the same directory as magma/"
	exit 1
fi

# Build magma.config
if [ ! -e res/magma.config.stub ]; then
	echo "Can't find magma.config.stub file"
	exit 1
fi

# Substitute the placeholders in magma.config.stub with user input
envsubst < res/magma.config.stub > magma.config

# Reset database to factory defaults
scripts/database/schema.init.sh $MYSQL_USER $MYSQL_PASSWORD $MYSQL_SCHEMA

if [ $? -ne 0 ]; then
	echo "Resetting the database failed"
	exit 1
fi

# Generate expected directories
if [ ! -d "$BASE_DIR" ]; then
	mkdir -p "${BASE_DIR}/logs/"
	mkdir -p "${BASE_DIR}/spool/"
	mkdir -p "${BASE_DIR}/storage/"
	mkdir -p "${BASE_DIR}/servers/local/"
fi

# Final step is to put everything in place
cp -rf bin res scripts ${BASE_DIR}/.
mv -f magma.config ${BASE_DIR}/.