-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·53 lines (52 loc) · 1.93 KB
/
configure.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
#!/bin/bash
# 获取当前文件夹地址
folderAddress=`pwd`
# 获取当前用户的根目录
userAddress=`echo $HOME`
# 指定安装地址 若不存在则建立
objectAddress="/usr/local/sbin/python-scripts"
if [[ ! -d $objectAddress ]]; then
sudo mkdir $objectAddress
fi
# 添加安装路径到环境变量中 首先获取当前的环境变量 若安装路径已存在于环境变量中则跳过 否则添加安装地址到环境变量中
allPATH=`echo $PATH`
if [[ `echo ${allPATH} | grep "${objectAddress}"` ]]; then
echo "The installation address is already added to \$PATH. Nothing to be done."
else
breaked=no
# 几个经常使用的用户配置文件
profileAddress=("${userAddress}/.zshrc" "${userAddress}/.bash_profile" "${userAddress}/.profile")
for one_address in ${profileAddress[@]}; do
if [[ -f ${one_address} ]]; then
echo "adding the installation address to ${one_address}"
cat <<- EOF >> ${one_address}
# this is added by configure.sh of python-template ([email protected])
export PATH="${objectAddress}:\$PATH"
EOF
source ${one_address}
breaked=yes
break
fi
done
# 预设的用户配置文件都不存在 则新建一个.bash_profile文件 添加环境变量
if [[ ${breaked} == "no" ]]; then
echo "made file ${userAddress}/.bash_profile"
echo "adding the installation address to ${userAddress}/.bash_profile"
cat <<- EOF > ${userAddress}/.bash_profile
# this is added by configure.sh of python-template ([email protected])
export PATH="${objectAddress}:\$PATH"
EOF
source ${userAddress}/.bash_profile
fi
fi
#找到所有后缀名为.py的脚本名称 存入数组
scriptName=( `ls *.py` )
for element in ${scriptName[@]}; do
objectName=${element%.*}
#若链接不存在 则建立
if [[ ! -L ${objectAddress}/${objectName} ]]; then
printf "creating links for "$objectName"... "
sudo ln -s ${folderAddress}/${element} ${objectAddress}/${objectName}
printf "done\n"
fi
done