-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
131 lines (93 loc) · 3.62 KB
/
setup.py
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
from fabric.api import run, sudo, cd, lcd, settings
from template import tput
def debian():
# start setup under root
with settings(user="root", no_keys=True):
# update packages index
run("aptitude update")
# install favorite packages
run("aptitude install -y sudo zsh git")
# allow sudo for root, admin group, and sudo group
# sudo group can use sudo without password
with lcd("templates"), cd("/etc"):
tput("sudoers", use_sudo=False, mode=0o440)
# create user with zsh and sudo group
run("useradd -ms /bin/zsh -G sudo vyacheslav")
# rewrite authorization keys
with lcd("templates/authorized_keys"), cd("/home/vyacheslav"):
run("rm -rf .ssh")
run("mkdir -m 0700 .ssh")
tput("vyacheslav", ".ssh/authorized_keys", use_sudo=False, mode=0o400)
run("chown vyacheslav:vyacheslav -R .ssh")
# continue under my user
# update dotfiles
with cd("/home/vyacheslav"):
sudo("git clone -n https://github.com/vslinko/dotfiles.git")
sudo("mv dotfiles/.git .")
sudo("rm -r dotfiles")
sudo("git reset --hard")
# upgrade system
sudo("aptitude upgrade -y")
# disable root password
sudo("passwd -d root")
def dotdeb(php54=False):
# add dotdeb key to aptitude as trusted
if sudo("apt-key list | grep dotdeb", quiet=True).failed:
sudo("wget -qO- http://www.dotdeb.org/dotdeb.gpg | apt-key add -")
# copy dotdeb source list
with lcd("templates/sources.list.d"), cd("/etc/apt/sources.list.d"):
tput("dotdeb.list", php54=php54)
# download new lists with available packages
sudo("aptitude update")
def www_data():
# try to create www-data directories
sudo("mkdir -p /var/www/.ssh")
# allow me to login as www-data
with lcd("templates/authorized_keys"), cd("/var/www/.ssh"):
tput("vyacheslav", "authorized_keys", mode=0o400)
# repair modes and owners
sudo("chmod 700 /var/www/.ssh")
sudo("chown www-data:www-data -R /var/www")
def php(modules=None, **kwargs):
# cli is required
if not modules:
modules = ["cli"]
elif "cli" not in modules:
modules.append("cli")
# install modules
sudo("aptitude install -y %s" % " ".join(map(lambda x: "php5-" + x, modules)))
# redefine some global configuration variables
with lcd("templates/php/conf.d"), cd("/etc/php5/conf.d"):
tput("php.ini", "00-php.ini")
# configure fpm if installed
if "fpm" in modules:
with lcd("templates/php"), cd("/etc/php5/fpm"):
tput("php-fpm.conf", **kwargs)
sudo("rm -r pool.d")
# restart with new configuration
sudo("service php5-fpm restart")
def nginx(template, package="light", **kwargs):
# install nginx package
sudo("aptitude install -y nginx-%s" % package)
# copy configuration
with lcd("templates/nginx/" + template), cd("/etc/nginx"):
tput("nginx.conf", **kwargs)
sudo("rm -r conf.d sites-available sites-enabled")
# restart with new configuration
sudo("service nginx restart")
def redis():
sudo("aptitude install -y redis-server")
def mongo():
sudo("aptitude install -y mongodb")
def nodejs():
sudo("aptitude install -y python g++ make")
run("mkdir nodejs")
with cd("nodejs"):
run("wget -N http://nodejs.org/dist/node-latest.tar.gz")
run("tar xzvf node-latest.tar.gz")
with cd(run("ls -rd node-v*")):
run("./configure")
sudo("make install")
sudo("rm -r nodejs")
def npm(package):
run("npm install %s" % package)