You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Comrad/script/install

91 lines
2.5 KiB
Plaintext

4 years ago
#!/usr/bin/env python3
4 years ago
4 years ago
URL_PYENV = 'https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer'
import os,sys,urllib,shutil
from urllib import request
4 years ago
import distutils
from distutils import dir_util
4 years ago
print('''
4 years ago
# # ## # # ### ## ### ####
# # # # #### # # # # # # #
## # # #### ### # # # # ###
# # # # # # # # #### # # #
# # ## # # # # # # ### ####
4 years ago
4 years ago
installing...
4 years ago
''')
PATH_HOME = os.path.expanduser('~')
PATH_KOMRADE = os.path.join(PATH_HOME,'komrade')
path_pyenv = os.path.join(PATH_HOME,'.pyenv')
4 years ago
path_repo = os.path.join(PATH_KOMRADE,'code')
4 years ago
def is_tool(name):
"""Check whether `name` is on PATH and marked as executable."""
from shutil import which
return which(name) is not None
4 years ago
4 years ago
def main():
4 years ago
4 years ago
# 1) get path
path_komrade = input('Path to save komrade to:\n['+PATH_KOMRADE+'] ').strip()
path_komrade = PATH_KOMRADE if not path_komrade else path_komrade
if not os.path.exists(path_komrade): os.makedirs(path_komrade)
os.chdir(path_komrade)
4 years ago
4 years ago
# 2) install pyenv?
4 years ago
if not os.path.exists(path_pyenv):
4 years ago
pyenv_yn = input('\npyenv is not installed. Install?\n[Y/n] ').strip().lower()
if pyenv_yn != 'n':
print('installing pyenv...')
os.system('curl https://pyenv.run | bash')
4 years ago
4 years ago
# # 3) download komrade
4 years ago
print('\ndownloading Komrade...')
if is_tool('git'):
4 years ago
if os.path.exists(path_repo):
os.chdir(path_repo)
os.system('git pull')
else:
os.chdir(path_komrade)
os.system('git clone https://github.com/Komrade/Komrade.git')
else:
os.chdir(path_komrade)
4 years ago
request.urlretrieve(
'https://github.com/Komrade/Komrade/archive/master.zip',
'komrade-github.zip'
)
os.system('unzip -o komrade-github.zip')
distutils.dir_util.copy_tree("Komrade-master", "code")
shutil.rmtree('Komrade-master')
4 years ago
os.remove('komrade-github.zip')
4 years ago
4 years ago
## 4) install komrade
os.chdir(path_repo)
os.environ['PYENV_ROOT']=path_pyenv
os.environ['PATH'] = os.path.join(path_pyenv,'bin') + os.environ['PATH']
4 years ago
# os.system('. script/bootstrap')
os.system('''
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
echo `which pyenv`
#if command -v pyenv 1>/dev/null 2>&1; then
# eval "$(pyenv init -)"
#fi
. script/bootstrap
''')
4 years ago
main()