add .local/bin to PATH when installing (#33)

* add .local/bin to PATH when installing

* add .local/bin to PATH when installing
This commit is contained in:
Zejun Lin 2018-09-13 13:43:52 +08:00 коммит произвёл goooxu
Родитель 71cd5e2705
Коммит 7632ac767d
2 изменённых файлов: 9 добавлений и 6 удалений

Просмотреть файл

@ -1,5 +1,6 @@
#!/bin/bash
INSTALL_PREFIX=${HOME}/.local
mkdir -p ${INSTALL_PREFIX}/bin
mkdir -p ${INSTALL_PREFIX}
wget -4 -nc https://nodejs.org/dist/v10.9.0/node-v10.9.0-linux-x64.tar.xz --header "Referer: nodejs.org"
tar -xf 'node-v10.9.0-linux-x64.tar.xz'
@ -12,6 +13,7 @@ rm -rf yarn-v1.9.4*
NODE_BIN=${INSTALL_PREFIX}/node/bin
YARN_BIN=${INSTALL_PREFIX}/yarn/bin
export PATH=${INSTALL_PREFIX}/node/bin:${INSTALL_PREFIX}/yarn/bin:$PATH
echo $PATH|grep -q ${INSTALL_PREFIX}/bin || echo "export PATH=${INSTALL_PREFIX}/bin:\${PATH}" >> ${HOME}/.bashrc
echo $PATH|grep -q ${NODE_BIN} || echo "export PATH=${NODE_BIN}:\${PATH}" >> ${HOME}/.bashrc
echo $PATH|grep -q ${YARN_BIN} || echo "export PATH=${YARN_BIN}:\${PATH}" >> ${HOME}/.bashrc
source ${HOME}/.bashrc

Просмотреть файл

@ -37,23 +37,24 @@ class CustomInstallCommand(install):
print('Error: Make Install Failed')
exit(-1)
def writeEnvironmentVariables(self, variable_name):
'''write an environment variable into ~/.bashrc'''
def exportToPath(self, path):
'''add path to Path through ~/.bashrc'''
paths = os.getenv("PATH").split(':')
bin_path = os.path.join(os.getenv('HOME'),'.local/'+variable_name+'/bin')
bin_path = os.path.join(os.getenv('HOME'),'.local/'+path)
if bin_path not in paths:
bashrc_path = os.path.join(os.getenv('HOME'), '.bashrc')
process = Popen('echo export PATH=' + bin_path + ':\$PATH >> ' + bashrc_path, shell=True)
if process.wait() != 0:
print('Error: Write Environment Variables Failed')
print('Error: Write Bashrc Failed')
exit(-1)
def run(self):
install.run(self)
self.makeInstall()
self.writeEnvironmentVariables('node')
self.writeEnvironmentVariables('yarn')
self.exportToPath('bin')
self.exportToPath('node/bin')
self.exportToPath('yarn/bin')
setup(
name = 'NNI',