forked from dannyti/seedbox-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
createMySQLUserInstall
executable file
·64 lines (51 loc) · 2.14 KB
/
createMySQLUserInstall
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
#!/bin/bash
# Hellish Tech
# No commercial usage without authorization
exec 1> >(logger -s -t $(basename $0)) 2>&1
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-u|--username)
USERNAME="$2"
shift # past argument
;;
-v|--version)
VERSION="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
SERVERPORT=$(/etc/seedbox-from-scratch/sfsgetAvailablePort -sp 3307 -ep 3406)
USERPASSWDGENED=$(/etc/seedbox-from-scratch/sfsGenerateRandomPasswordString)
ROOTPASSWDGENED=$(/etc/seedbox-from-scratch/sfsGenerateRandomPasswordString)
SYSTEMHOSTNAME=`cat /etc/seedbox-from-scratch/hostname.info`
docker pull mysql:${VERSION}
docker create --restart=always -d --name ${USERNAME}_mysql -h ${SYSTEMHOSTNAME} -v /home/${USERNAME}/mysql:/docker-entrypoint-initdb.d/ -p ${SERVERPORT}:3306 -e MYSQL_ROOT_PASSWORD=${ROOTPASSWDGENED} -e MYSQL_USER=${USERNAME} -e MYSQL_PASSWORD=${USERPASSWDGENED} -v /etc/localtime:/etc/localtime:ro mysql:${VERSION}
sleep 5
CHECKIFRUNNING=$(/etc/seedbox-from-scratch/sfsRunningUserDockerInfo -u ${USERNAME} -d mysql | tr -cd '[[:alnum:]]._-' )
if [[ (${CHECKIFRUNNING} == "STOPPED") || (${CHECKIFRUNNING} == "RUNNING") ]]; then
echo "SERVICE: MYSQL" > /home/${USERNAME}/private/mysql.serviceinfo
echo "SERVERPORT: $SERVERPORT" >> /home/${USERNAME}/private/mysql.serviceinfo
echo "ROOTPASSWORD: $ROOTPASSWDGENED" >> /home/${USERNAME}/private/mysql.serviceinfo
echo "USERNAME: $USERNAME" >> /home/${USERNAME}/private/mysql.serviceinfo
echo "USERPASSWORD: $USERPASSWDGENED" >> /home/${USERNAME}/private/mysql.serviceinfo
chown www-data:www-data /home/${USERNAME}/private/*.serviceinfo
if [ ! -d "/home/${USERNAME}/mysql" ]; then
mkdir /home/${USERNAME}/mysql
chown ${USERNAME}:${USERNAME} /home/${USERNAME}/mysql/ -R
fi
if [ ! -f /home/${USERNAME}/mysql/my.cnf ]; then
cp /etc/seedbox-from-scratch/templates/my.cnf.template /home/${USERNAME}/mysql/my.cnf
chown ${USERNAME}:${USERNAME} /home/${USERNAME}/mysql/ -R
fi
fi
docker start ${USERNAME}_mysql
if [[ -n $1 ]]; then
echo "Last line of file specified as non-opt/last argument:"
tail -1 $1
fi