代码拉取完成,页面将自动刷新
#!/bin/bash
# 获取当前文件夹地址
folderAddress=`pwd`
# 获取当前用户的根目录
userAddress=`echo $HOME`
# 指定安装地址 若不存在则建立
objectAddress="/usr/local/sbin"
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}/.bash_profile" "${userAddress}/.profile" "${userAddress}/.zshrc")
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 shell-template (zhangyi.cugwuhan@gmail.com)
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 shell-template (zhangyi.cugwuhan@gmail.com)
export PATH=${objectAddress}:\$PATH
EOF
source ${userAddress}/.bash_profile
fi
fi
#找到所有后缀名为.sh的脚本名称 存入数组
scriptName=( `ls *.sh` )
for element in ${scriptName[@]}; do
#排除configure.sh
if [[ $element != "configure.sh" ]]; then
objectName=${element%.*}
#若链接不存在 则建立
if [[ ! -L ${objectAddress}/${objectName} ]]; then
printf "creating links for ${objectName} ... "
sudo ln -s ${folderAddress}/${element} ${objectAddress}/${objectName}
printf "done\n"
fi
fi
done
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。