-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenvset.sh
executable file
·95 lines (82 loc) · 2.36 KB
/
envset.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
#!/usr/bin/env bash
#
# Determin basic host env variable
#
# Copyright (C) 2017 Gwangmin Lee
#
# Author: Gwangmin Lee <gwangmin0123@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
if [ $(whoami) != root ];then
SUDO="sudo"
else
SUDO=""
fi
LOCAL_DIR=${LOCAL_DIR:-$HOME/.local}
TMP_DIR=${TMP_DIR:-/tmp/devsetting}
if [ $(echo $OSTYPE | grep 'linux') ];then
ENVFILE="$HOME/.bashrc"
NPROC=$(nproc)
if [[ -f /etc/os-release ]]; then
OS=$(cat /etc/os-release | grep ^ID= | sed 's/ID=[^a-zA-Z]*\([a-zA-Z]\+\)[^a-zA-Z]*/\1/')
elif [ $(which yum 2>/dev/null) ]; then
OS='centos'
else
eecho "Unknown linux distro"
exit 1
fi
elif [ $(echo $OSTYPE | grep 'darwin') ];then
ENVFILE="$HOME/.bash_profile"
NPROC=$(sysctl -n hw.physicalcpu)
OS="mac"
else
eecho "Unkown distro"
exit 1
fi
SET_BOLD="\e[1m"
UNSET_BOLD="\e[0m"
COLOR_RED="\e[38;5;9m"
COLOR_YELLOW="\e[38;5;11m"
COLOR_GREEN="\e[38;5;2m"
COLOR_INFO="\e[38;5;14m"
COLOR_NONE="\e[38;m"
function eecho {
>&2 echo -e "${SET_BOLD}${COLOR_RED}$1${COLOR_NONE}${UNSET_BOLD}"
}
function wecho {
>&2 echo -e "${SET_BOLD}${COLOR_YELLOW}$1${COLOR_NONE}${UNSET_BOLD}"
}
function gecho {
>&2 echo -e "${SET_BOLD}${COLOR_GREEN}$1${COLOR_NONE}${UNSET_BOLD}"
}
function iecho {
>&2 echo -e "${SET_BOLD}${COLOR_INFO}$1${COLOR_NONE}${UNSET_BOLD}"
}
# Given two arguments, true if first argument is smaller version than second argument
function compare_version {
if [ $# != 2 ];then
eecho "compare_version requires exactly two arguments!!!"
return 1
fi
if [ "$(echo -e "$1\n$2" | sort -V | head -n1)" = "$2" ];then
return 1
else
return 0
fi
}
if [ -r $ENVFILE ];then
. $ENVFILE
fi
LEVEL=$(( ${LEVEL:-"0"}+1 ))