forked from LibrIT/passhport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·195 lines (173 loc) · 4.99 KB
/
install.sh
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env bash
# Installation script for Debian
# The script:
# Check distribution type
# Check if dependencies are met
# Check if the application has already been installed
# Initialize the database
# Create the first admin
# First of all: must be launched as root
if [ $EUID -ne 0 ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
############
# Variables
############
#Supported distributions.
DISTRIBUTIONS="Debian GNU/Linux 7 Debian GNU/Linux 8"
#Python includes needed for the work
DEPENDENCIES=( 'from docopt import docopt' 'from flask import Flask' 'from flask.ext.sqlalchemy import SQLAlchemy' 'from migrate.versioning import api' )
USERNAME="passhport"
GROUPNAME="${USERNAME}"
HOMEDIR="/home/${USERNAME}"
ADMINBINDIR="${HOMEDIR}/adminbin/"
SERVERBINDIR="${HOMEDIR}/serverbin/"
DATADIR="${HOMEDIR}/var"
PASSWORD="$(openssl passwd -crypt $( < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8))" #crypted
DIRNAME="$(dirname $0)"
###################
# Distribution type
###################
distrib="$( sed "s/ \\\n \\\l//" /etc/issue )"
echo ${DISTRIBUTIONS} | grep "${distrib}" &> /dev/null
result=?$
if [ ${result} = 1 ]
then
echo "Error: Passhport is validated only on this distirbutions: ${DISTRIBUTION}"
exit 126
fi
##############
# Dependencies
##############
# Passhport is a python software
which python &> /dev/null
if [ $? = 1 ]
then
echo "Error: you need python compiler on your PATH."
exit 126
fi
echo -n "Currently using "
python --version
# We test to import the different librairies with python
for dependence in "${DEPENDENCIES[@]}"
do
/usr/bin/env python -c "${dependence}" &> /dev/null
result=$?
if [ "$result" = "1" ]
then
echo "Error: Passhport missing a dependence to do this: ${dependence}"
echo "Maybe you have librairies for python 3 and you're using python 2.7"
echo "Check your environnement to knows the default python version on your distribution".
exit 126
fi
done
#################
# Old application
#################
# Testing the user existence
echo -n "Checking if \"${USERNAME}\" user already exist on the system... "
getent passwd | grep "^${USERNAME}:" > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Error !"
echo "The user \"${USERNAME}\" already exist..."
echo "Tip : remove the user \"${USERNAME}\" from /etc/passwd"
exit 126
else
echo "done."
fi
# Testing group existence
echo -n "Checking if \"${GROUPNAME}\" group already exist on the system... "
grep "^${GROUPNAME}:" /etc/group > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Error !"
echo "The group \"${GROUPNAME}\" already exist..."
echo "Tip : remove the group \"${GROUPNAME}\" from /etc/group"
exit 126
else
echo "done."
fi
# Testing Authorized keys file
echo -n "Checking if \"${HOMEDIR}/.ssh/authorized_keys2\" already exists... "
if [ -f "${HOMEDIR}/.ssh/authorized_keys2" ]
then
echo "Error !"
echo "The file \"${HOMEDIR}/.ssh/authorized_keys2\" already exist. Please create a new user or delete the file."
exit 126
else
echo "doesn't exist ! (good)"
fi
# Testing database (standard one...)
echo -n "Checking if passhport database (${DATADIR}/app.db) already exist... "
if [ -f "${DATADIR}/app.db" ]
then
echo "Error : the database \"${DATADIR}/app.db\" already exist. Please delete the file."
exit 126
else
echo "doesn't exist ! (good)"
fi
#################
# Create the user
#################
echo -n "Creating the ${USERNAME} user on the system... "
useradd --create-home --base-dir "${HOMEDIR}" --home-dir "${HOMEDIR}" --user-group --password ${PASSWORD} ${USERNAME} > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "done."
else
echo "Error while creating system user \"${USERNAME}\"."
exit 126
fi
#chown -R ${USERNAME}:${GROUPNAME} ${HOMEDIR}
##################
# Install server binaries
##################
echo -n "Installing server-side binaries... "
mkdir -p "${SERVERBINDIR}"
cp -r passhportd/* "${SERVERBINDIR}/."
if [ $? -eq 0 ]
then
echo "done."
else
echo "Error while copying server-side binaries."
exit 126
fi
chown -R ${USERNAME}:${GROUPNAME} "${SERVERBINDIR}"
##################
# Install admin binaries
##################
echo -n "Installing admin binaries... "
mkdir -p "${ADMINBINDIR}"
cp -r passhport_admin/* "${ADMINBINDIR}/."
if [ $? -eq 0 ]
then
echo "done."
else
echo "Error while copying admin binaries."
exit 126
fi
chown -R ${USERNAME}:${GROUPNAME} "${ADMINBINDIR}"
#####################
# Initialize database
#####################
echo -n "Initialize database... "
SOURCE_DIR=`pwd`
su ${USERNAME} -c "${SERVERBINDIR}/db_create.py"
if [ $? -eq 0 ]
then
echo "done."
else
echo "Error while creating database."
exit 126
fi
#######################
# Create the first user
#######################
#TODO
echo ""
echo "==> Great ! All actions finished successfully !"
echo "INFO : Server scripts directory is \"${SERVERBINDIR}\""
echo "INFO : Administration scripts directory is \"${ADMINBINDIR}\""
echo "INFO : Database directory is : \"${DATADIR}\""