forked from sohutv/cachecloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachecloud-init.sh
More file actions
99 lines (80 loc) · 2.09 KB
/
cachecloud-init.sh
File metadata and controls
99 lines (80 loc) · 2.09 KB
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
#!/bin/bash
############################################################################
# @desc:
# - 1. create user;
# - 2. create default directories and authorize;
# - 3. @usage: sh cachecloud-init.sh [username]
# @author: leifu
# @time:
###########################################################################
set -o nounset
set -o errexit
readonly redisDir="/opt/cachecloud/redis"
readonly redisTarGz="redis-3.0.7.tar.gz"
# check if the user exists
checkExist() {
local num=`cat /etc/passwd | grep -w $1 | wc -l`
#cat /etc/passwd | grep -q "$1"
if [[ $num == 1 ]]; then
echo "user $1 exists, overwrite user and *init all data*: [y/n]?"
read replace
if [[ ${replace} == "y" ]]; then
echo "delete existed user: $1."
userdel -r "$1"
createUser "$1"
init "$1"
return 0
fi
else
createUser "$1"
init "$1"
fi
return 0
}
# create the user
createUser() {
# create a user
useradd -m -d /home/$1 -s /bin/bash $1
# give the user a password
passwd $1
# add the user to sudoers
# echo "$1 ALL=(ALL) ALL" >> /etc/sudoers
# Maximum number of days between password change
chage -M 9999 $1
echo "OK: create user: $1 done"
}
# create defautl dirs and authorize
init() {
# create working dirs and a tmp dir
mkdir -p /opt/cachecloud/data
mkdir -p /opt/cachecloud/conf
mkdir -p /opt/cachecloud/logs
mkdir -p /opt/cachecloud/redis
mkdir -p /tmp/cachecloud
# change owner
chown -R $1:$1 /opt/cachecloud
chown -R $1:$1 /tmp/cachecloud
echo "OK: init: $1 done"
}
# install redis
installRedis() {
#which redis-server
#if [[ $? == 0 ]]; then
# echo "WARN: redis is already installed, exit."
# return
#fi
yum install -y gcc
mkdir -p ${redisDir} && cd ${redisDir}
wget http://download.redis.io/releases/${redisTarGz} && mv ${redisTarGz} redis.tar.gz && tar zxvf redis.tar.gz --strip-component=1
make && make install
if [[ $? == 0 ]]; then
echo "OK: redis is installed, exit."
chown -R $1:$1 ${redisDir}
export PATH=$PATH:${redisDir}/src
return
fi
echo "ERROR: redis is NOT installed, exit."
}
username=$1
checkExist "${username}"
installRedis "${username}"