-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·134 lines (110 loc) · 4.58 KB
/
install
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# -*- coding: utf8 filetype: py -*-
# Copyright (c) 2012 Svante Kvarnström <[email protected]>. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
import argparse
import subprocess
class colours:
BOLD = "\033[1m"
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable(self):
self.BOLD = ''
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''
def print_header(str):
line = '-' * len(str)
print(line)
print(colours.HEADER + colours.BOLD + str + colours.ENDC)
print(line)
def print_warning(str):
print(colours.WARNING + str + colours.ENDC)
def print_ok(str):
print(colours.OKGREEN + str + colours.ENDC)
def create_symlink(src, dest):
if os.path.isfile(dest) and not os.path.islink(dest):
print_warning("Will not symlink %s -> %s: file exists" % (src, dest))
return
if os.path.islink(dest):
os.unlink(dest)
os.symlink(src, dest)
print_ok("symlink: %s -> %s" % (src, dest))
def which(file):
for path in os.environ['PATH'].split(':'):
if os.path.exists(os.path.join(path, file)):
return os.path.join(path, file)
return None
def main():
home = os.environ['HOME']
home_bin = os.path.join(home, 'bin')
config_dir = os.path.join(home, 'config')
config_home = os.path.join(config_dir, 'home')
config_bin = os.path.join(config_home, 'bin')
parser = argparse.ArgumentParser(description='Install sjk dotfiles')
parser.add_argument('-u', '--update', action='store_true',
help='pull config updates from github')
parser.add_argument('-f', '--force', action='store_true',
help='set up symlinks etc even though there were no updates to repository')
args = parser.parse_args()
if args.update:
if b'Already up-to-date.' in subprocess.check_output(['git', 'pull']):
print_ok('Already got the latest timey-wimey, wobbly-bobbly config.')
if not args.force:
return
# Install submodules
print_header('Installing submodules')
subprocess.call(['git', 'submodule', 'init'])
subprocess.call(['git', 'submodule', 'update'])
os.chdir(config_home)
# Install .dotfiles
print_header('Installing home directory dotfiles')
for src in os.listdir(config_home):
if src in 'bin':
continue
create_symlink(os.path.abspath(src), os.path.join(home, '.' + src))
# Install binaries
print_header('Installing home directory binaries')
if not os.path.exists(home_bin):
print_ok('mkdir: %s' % home_bin)
os.makedirs(home_bin)
os.chdir(config_bin)
for src in os.listdir(config_bin):
create_symlink(os.path.abspath(src), os.path.join(home_bin, src))
# Check if zsh is available and if we are running it
if 'zsh' not in os.path.basename(os.environ['SHELL']):
print_warning('You are not currently using zsh.')
zsh_bin = which('zsh')
if zsh_bin is not None:
# print_ok('Zsh is in your path. Making it your default shell now...')
print_ok('You might want to make zsh your default shell.')
# subprocess.call(['chsh', '-s', zsh_bin], stdin=subprocess.PIPE)
main()