dotfiles/envsetup.py

106 lines
2.6 KiB
Python
Raw Normal View History

2012-01-05 17:39:46 +00:00
#!/usr/bin/env python
#Personal environment setup script
2012-01-05 18:19:14 +00:00
#Dependencies - Supported distros, sudo
2012-01-05 17:39:46 +00:00
import os
from subprocess import call
import platform
import urllib2
#global vars
vimrcurl = "https://raw.github.com/staticsafe/dotfiles/master/.vimrc"
zshrcurl = "https://raw.github.com/staticsafe/dotfiles/master/.zshrc"
tmuxurl = "https://raw.github.com/staticsafe/dotfiles/master/.tmux.conf"
2012-01-05 19:19:47 +00:00
vimdirurl = "https://github.com/staticsafe/dotfiles/raw/master/vimdir.tar.bz2"
2012-01-05 17:39:46 +00:00
2012-01-05 19:19:47 +00:00
def sudocheck():
#sudocheck
sudopath = "/usr/bin/sudo"
if os.path.isfile(sudopath) == True:
print 'This script needs sudo to run!'
2012-01-05 17:39:46 +00:00
raise SystemExit
2012-01-05 18:19:14 +00:00
else:
2012-01-05 19:19:47 +00:00
print 'Sudo check: PASSED!'
2012-01-05 18:19:14 +00:00
def urldownload(confurl = ""):
#Thanks PabloG from StackExchange for this little snippet - http://stackoverflow.com/a/22776
2012-01-05 18:19:14 +00:00
url = confurl
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
2012-01-05 18:28:53 +00:00
2012-01-05 18:19:14 +00:00
while True:
2012-01-05 18:32:08 +00:00
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
2012-01-05 18:33:57 +00:00
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
2012-01-05 18:32:08 +00:00
status = status + chr(8)*(len(status)+1)
print status,
2012-01-05 18:19:14 +00:00
f.close()
def confdownload():
urldownload(confurl = vimrcurl)
urldownload(confurl = zshrcurl)
urldownload(confurl = tmuxurl)
2012-01-05 19:19:47 +00:00
urldownload(confurl = vimdirurl)
untar = call("tar xvf vimdir.tar.bz2", shell = True)
2012-01-05 18:19:14 +00:00
def envArch():
#Install relevant packagtes
installpackages = call("sudo pacman --noconfirm -S vim zsh tmux git subversion", shell=True)
#Get relevant dotfiles
confdownload()
def envFedora():
#Install relevant packages
installpackages = call ("sudo yum install -y vim zsh tmux git subversion", shell=True)
#Get relevant dotfiles
confdownload()
def envDebian():
#Install relevant packages
installpackages = call ("sudo apt-get install --assume-yes vim zsh tmux git subversion", shell=True)
#Get relevant dotfiles
confdownload()
2012-01-05 17:39:46 +00:00
def main():
#homedircheck
homedir = os.environ['HOME']
currentdir = os.getcwd()
if currentdir != homedir:
os.chdir(homedir)
else:
print "Home directory check : PASSED!"
2012-01-05 18:19:14 +00:00
2012-01-05 17:39:46 +00:00
#distrocheck
userdistro = platform.linux_distribution()
if userdistro[0] == "Fedora":
2012-01-05 18:35:12 +00:00
envFedora()
2012-01-05 17:39:46 +00:00
elif userdistro[0] == "debian":
2012-01-05 18:19:14 +00:00
envDebian()
2012-01-05 17:39:46 +00:00
elif userdistro[0] == "Arch" or os.path.isfile("/etc/arch-release") == True:
2012-01-05 18:19:14 +00:00
envArch()
2012-01-05 17:39:46 +00:00
elif userdistro[0] == "Ubuntu":
2012-01-05 18:19:14 +00:00
envDebian()
2012-01-05 17:39:46 +00:00
else:
print "This script is not supported for your distro, exiting."
raise SystemExit
if __name__ == "__main__":
main()