forked from peter-m-shi/ztool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
69 lines (57 loc) · 1.73 KB
/
setup.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
#!/bin/bash
ROOT_PROFILE="$HOME/.profile"
PG_PROFILE="$HOME/ztool/profile"
function includeString(){
echo "$1" | grep -q "$2" && return 0 || return 1
}
#判断shell环境
if includeString "$SHELL" "/bin/zsh"; then
RC_FILE="$HOME/.zshrc"
elif includeString "$SHELL" "/bin/bash"; then
RC_FILE="$HOME/.bashrc"
fi
function addStringToFile(){
ret=$(cat $2 | grep "$1")
if [ "$ret" = "" ] ;then
echo "
$1
">>$2
echo "[setup] \"$1\" ---> \"$2\"."
fi
}
function setupTool(){
echo 'source '$1"/profile" $PG_PROFILE
addStringToFile 'source '$1"/profile" $PG_PROFILE
sh "$1/setup.sh"
successString="$1 setup success !"
sh "$HOME/ztool/utility/echoColor.sh" "-green" "$successString"
}
#在.profile里面添加source代码
addStringToFile "source $PG_PROFILE" $ROOT_PROFILE
#在.zshrc/.bashrc里面添加source代码
addStringToFile "source $ROOT_PROFILE" $RC_FILE
addStringToFile "env ZSH=$ZSH "'PGTOOLS_AUTO_CHECK=$PGTOOLS_AUTO_CHECK PGTOOLS_AUTO_HOURS=$PGTOOLS_AUTO_HOURS'" zsh -f $HOME/ztool/check_update.sh" $RC_FILE
if [[ "$1" != "" ]]; then
if [[ -d "$1" ]]; then
sh "$HOME/ztool/utility/echoColor.sh" "-yellow" "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
setupTool $1
sh "$HOME/ztool/utility/echoColor.sh" "-yellow" ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
else
failedString="$1 not exsit!"
sh "$HOME/ztool/utility/echoColor.sh" "-red" "$failedString"
fi
else
for file in $HOME/ztool/*
do
if test -d $file
then
if [[ "${file##*/}" != "shell" ]] && [[ "${file##*/}" != "image" ]]; then
echo ${file##*/}
sh "$HOME/ztool/utility/echoColor.sh" "-yellow" "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
setupTool $file
sh "$HOME/ztool/utility/echoColor.sh" "-yellow" ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo
fi
fi
done
fi