forked from vibe-d/vibe.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-linux.sh
executable file
·91 lines (74 loc) · 2.53 KB
/
setup-linux.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
#!/bin/sh
set -e
# root privileges required
[ "root" != "$USER" ] && echo "root privileges required..." && exec sudo $0 "$@"
# set variables
USER_NAME="www-vibe"
GROUP_NAME="www-vibe"
USER_COMMENT="Vibe user"
CONFIG_FILE="/etc/vibe/vibe.conf"
SYMLINK_FILE="/usr/bin/vibe"
LOG_FILE="/var/spool/vibe/install.log"
# remove user, group, log file and configuration file
if [ "$1" = "-r" ]
then
# remove obsolete "vibe" user/group
/usr/sbin/userdel vibe 2>/dev/null || true
/usr/sbin/groupdel vibe 2>/dev/null || true
# remove user if present in log file
if grep "^user: $USER_NAME$" $LOG_FILE >/dev/null 2>&1
then
/usr/sbin/userdel $USER_NAME >/dev/null 2>&1 && echo "'$USER_NAME' user removed."
sed -i "/^user: $USER_NAME$/d" $LOG_FILE >/dev/null 2>&1
fi
# remove group if present in log file
if grep "^group: $GROUP_NAME$" $LOG_FILE >/dev/null 2>&1
then
/usr/sbin/groupdel $GROUP_NAME >/dev/null 2>&1 && echo "'$GROUP_NAME' group removed."
sed -i "/^group: $GROUP_NAME$/d" $LOG_FILE >/dev/null 2>&1
fi
# remove log file if no data
if [ -f $LOG_FILE ] && [ -z $(tr -d '[ \t\r\n]' 2>/dev/null <$LOG_FILE) ]
then
rm -f $LOG_FILE
rmdir $(dirname $LOG_FILE) >/dev/null 2>&1 || true
fi
# remove config file
echo "Removing configuration file $CONFIG_FILE..."
rm -f $CONFIG_FILE
rmdir $(dirname $CONFIG_FILE) >/dev/null 2>&1 || true
# remove symlink
echo "Removing symlink $SYMLINK_FILE..."
rm -f $SYMLINK_FILE
exit
fi
# create a symlink to the vibe script
echo "Creating symlink in $SYMLINK_FILE..."
ln -sf $(pwd)/bin/vibe $SYMLINK_FILE
# creating group if he isn't already there
if ! getent group $GROUP_NAME >/dev/null; then
echo "Creating group $GROUP_NAME..."
/usr/sbin/groupadd -r $GROUP_NAME >/dev/null
mkdir -p $(dirname $LOG_FILE)
echo "group: $GROUP_NAME" >>$LOG_FILE
fi
# creating user if he isn't already there
if ! getent passwd $USER_NAME >/dev/null; then
echo "Creating user $USER_NAME..."
/usr/sbin/useradd -r -g $GROUP_NAME -c "$USER_COMMENT" $USER_NAME >/dev/null
mkdir -p $(dirname $LOG_FILE)
echo "user: $USER_NAME" >>$LOG_FILE
fi
# create config dir if not there
mkdir -p $(dirname $CONFIG_FILE)
# create/update config file
echo "Creating new config file in $CONFIG_FILE..."
USER_ID=$(getent passwd $USER_NAME | cut -d: -f3)
GROUP_ID=$(getent group $GROUP_NAME | cut -d: -f3)
echo '{
"uid": '$USER_ID',
"gid": '$GROUP_ID'
}' >$CONFIG_FILE
# if everything went fine
echo "Setup finished successfully."
echo "You can now run 'vibe' from any vibe.d application directory to run an app (e.g. in examples/http_server/)."