-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.project_env.sh
114 lines (102 loc) · 3.19 KB
/
.project_env.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
#!/bin/bash
git config --global credential.helper 'store --file ~/.git-credentials'
export SCRIPT_DIR=`realpath .`
echo """
----------------------------------------------------------------------------------------------------------------
Make sure the root install dir is a full path and not a short path. This is very important to a correct install!
----------------------------------------------------------------------------------------------------------------
ROOT INSTALL DIR SCRIPT_DIR :$SCRIPT_DIR:
________________________________________________________________________________________________________________
"""
[[ -n "$SUDO_USER" ]] && export USER="$SUDO_USER" || export USER="$USER"
export HOME="/home/$USER"
export PROG="$HOME/Programs"
export ROUTE="$PROG/route-dns"
round() {
printf "%.${2:-0}f" "$1"
}
export CPU_CORE_COUNT=`cat /proc/stat | grep cpu | grep -E 'cpu[0-9]+' | wc -l`
export MEM_COUNT=$(round `grep MemTotal /proc/meminfo | awk '{print $2 / 1024}'` 0)
export INSTALL_CONFIG_DIR=/etc
export IP_REGEX="((([0-9]{1,3})((\.)?))"
export CONFIG_DIR=$SCRIPT_DIR/config
export CONF_PROG_DIR=$SCRIPT_DIR/prog
export SETUP_DIR=$SCRIPT_DIR/setup
export MASTER_DIR=$SCRIPT_DIR/master
export USR_DIR=$SCRIPT_DIR/user
export BIN_DIR=$USR_DIR/local/bin
export SBIN_DIR=$USR_DIR/local/sbin
export SHARE_DIR=$USR_DIR/share
export CONFIG_INSTALLED_STR='# CTP INSTALL -- DO NOT REMOVE THIS UNLESS YOU PLAN ON REMOVING INSTALL AND REINSTALLING'
DEFAUT_CONF_PROG_DIR=${CONF_PROG_DIR:-$PROG}
source $DEFAUT_CONF_PROG_DIR/all-scripts-exports.sh > /dev/null
#source $SCRIPT_DIR/bash_rc_sample
function load_env() {
for env in $( grep -Ev ^# /etc/environment ); do export $(echo $env | grep -v '#' | sed -e 's/"//g') > /dev/null; done
source /etc/environment
}
export -f load_env
load_env
function checkIsNotInstalled() {
local file="$1"
if ! [[ -f $file ]]; then
touch $file
fi
if [[ -z `grep -o "$CONFIG_INSTALLED_STR" $file` ]]; then
echo "true"
else
echo "false"
fi
}
function isNotInstalled() {
local file="$1"
local result=`checkIsNotInstalled $file`
if [[ "$result" == 'true' ]]; then
(
echo "$CONFIG_INSTALLED_STR" | sudo tee -a $file
)>/dev/null
fi
echo "$result"
}
function check_admin() {
set -e
if [ "$(id -u)" -eq 0 ]
then
if [ -n "$SUDO_USER" ]
then
set +e
printf "OK, script run as root (with sudo) as a admin user\n"
else
printf "This script has to run as root (with sudo) not as root\n" >&2
exit 1
fi
else
printf "This script has to run as root\n" >&2
exit 1
fi
}
function is_user_sure() {
set -e
read -r -p "Are you sure you want to install this script? The user: $USER will be the default admin with the home dir of $HOME [y/N]" response
case "$response" in
[yY][eE][sS]|[yY])
echo "Ok...continuing"
set +e
;;
*)
printf """
Try this
sudo -u ${USER} ./install.sh
Or...
sudo -u \${USER} ./install.sh
Ok exiting now
"""
exit 0
;;
esac
}
export -f isNotInstalled
export -f checkIsNotInstalled
export -f is_user_sure
export -f check_admin
echo "DONE"