-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsetup-old-fashioned
executable file
·151 lines (121 loc) · 4.45 KB
/
setup-old-fashioned
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python3
"""
This is a setup script for the Ubuntu Old-Fashioned image builder. Its
purpose is to make the process of setting up a new build environment
(e.g. a VPS) more hands-free.
Note that any "extra" build hooks must still be manually copied into the
appropriate hooks directory.
"""
import os
from subprocess import call, PIPE, run
try:
import distro
DISTRO_VERSION = (distro.name(), distro.version(), distro.codename())
except ImportError:
import platform
DISTRO_VERSION = platform.linux_distribution()
from typing import Dict, List, Text, Tuple # noqa
PKG_INSTALL_CMDS = [
["sudo", "add-apt-repository", "-y", "ppa:cloud-images/old-fashioned"],
["sudo", "apt-key", "adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "43BC59850A456E28"],
["sudo", "add-apt-repository", "-y", "ppa:launchpad/ubuntu/buildd"],
["sudo", "apt-get", "update"],
["sudo", "apt-get", "install", "-y", "oldfashioned"],
["sudo", "apt-get", "install", "-y", "launchpad-buildd", "bzr",
"python3-ubuntutools", "python3-launchpadlib", "distro-info",
],
]
LIVECD_ROOTFS_GIT = "https://git.launchpad.net/livecd-rootfs"
def input_repo():
# type: () -> List[Text]
vcs = {
'1': "git",
'2': "bzr",
}
def print_opts(ks):
# type: (List[Text]) -> None
for key in ks:
print("{}: {}".format(key, vcs[key]))
print("Which VCS?")
ks = sorted(list(vcs.keys()), key=lambda x: int(x))
print_opts(ks)
choice = ""
while choice not in ks:
choice = input("> ")
if choice not in ks:
print("Please choose a VCS from the options listed.")
print_opts(ks)
cmd = [vcs[choice]]
if choice == '1':
cmd += ["clone"]
else:
cmd += ["branch"]
repo_prompt = ("Please enter the repo you would like to clone, as well "
"as any additional options to the 'git clone' command:")
prompt = "> "
print(repo_prompt)
repo = input(prompt)
correct = False
done = "n"
while not correct:
print(repo)
print("Is the above correct? [y/n]")
done = input("> ")
if done.lower()[0] == 'y':
break
else:
print(repo_prompt)
repo = input(prompt)
cmd += repo.split()
return cmd
def print_sorted(d):
ordered = sorted(list(d.keys()), key=lambda x: int(x))
for key in ordered:
print("{}: {}".format(key, d.get(key)))
def ubuntu_distro_info(options):
return run("ubuntu-distro-info {}".format(options).split(),
stdout=PIPE).stdout.decode("utf-8").split('\n')
if __name__ == '__main__':
if '20.04' not in DISTRO_VERSION:
print("Old-fashioned must be run on Ubuntu Focal.")
exit(1)
for cmd in PKG_INSTALL_CMDS:
call(cmd)
supported_suites = ubuntu_distro_info("--supported")
devel_suites = ubuntu_distro_info("--devel")
suites_with_branches = [suite for suite in supported_suites if
suite not in devel_suites]
devel_release_branch = ['master']
extra_options = ['package', 'custom', 'none']
user_options = suites_with_branches + devel_release_branch + extra_options
LIVECD_ROOTFS_OPTIONS = {str(i): opt for i, opt in enumerate(user_options)}
ks = LIVECD_ROOTFS_OPTIONS.keys()
choice = ""
while choice not in ks:
print()
print("Please choose from the options listed.")
print_sorted(LIVECD_ROOTFS_OPTIONS)
choice = input("> ")
selection = LIVECD_ROOTFS_OPTIONS[choice]
if selection not in extra_options:
cmd = ["git", "clone", "-b",
'ubuntu/{}'.format(LIVECD_ROOTFS_OPTIONS[choice]),
LIVECD_ROOTFS_GIT]
repo_dir = "/livecd-rootfs"
home_dir = os.path.expanduser("~")
cmd += [home_dir + repo_dir]
elif selection == 'package':
cmd = ["sudo", "apt-get", "install", "-y", "livecd-rootfs"]
elif selection == 'custom':
cmd = input_repo()
else:
cmd = []
print("'none' option selected. Skipping livecd-rootfs install...")
if cmd:
print("Executing {}".format(' '.join(cmd)))
call(cmd)
print("Done installing tools. All that's left to do is clone and copy any "
"additional hooks you might want to run.")
print("Run old-fashioned via:")
print(" cd <livecd-rootfs repo>")
print(" sudo -E old-fashioned-image-build --series <series>")