-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·242 lines (205 loc) · 5.72 KB
/
main.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/env python3
# Imports {{{
import argparse
import configparser
import getpass
import os
import sys
import logging
from src.post import aur
from src.post import bitwarden
from src.post import custom
from src.post import git_setup
from src.post import git_repos
from src.post import pacman
from src.post import pipewire
from src.post import python
from src.post import rust
from src.post import shell
from src.post import ssh
from src.post import systime
from src.post import xdg
# }}}
# System Time {{{
def set_system_time():
systime.ntp()
systime.time_zone(timezone)
# }}}
# Pacman {{{
def set_pacman():
pacman.explicit_keyring()
pacman.update()
# }}}
# Rust {{{
def set_rust():
rust.toolchain()
# }}}
# AUR {{{
def set_aur():
aur.mkdir(aur_dir)
aur.clone(aur_dir, aur_helper)
aur.mkpkg(aur_dir, cwd)
aur.remove(aur_dir)
# }}}
# Password Manager {{{
def set_bitwarden():
bitwarden.config(bw_mail, bw_lock)
bitwarden.register()
bitwarden.sync()
# }}}
# SSH {{{
def set_ssh():
gh_mail = bitwarden.rbw_get("github", git_mail)
ssh.config(home, ssh_dir)
ssh.service_set(home, ssh_dir)
ssh.service_start()
ssh.key_gen(home, ssh_key, gh_mail)
ssh.key_add()
# }}}
# GIT {{{
def set_git():
gh_token = bitwarden.rbw_get("github", git_token)
gh_mail = bitwarden.rbw_get("github", git_mail)
gh_user = bitwarden.rbw_get("github", git_user)
git_setup.auth_login(gh_token)
git_setup.auth_status()
git_setup.pubkey_add(git_pubkey)
git_setup.known_hosts()
git_setup.ssh_test()
git_setup.config(gh_user, gh_mail)
def set_git_repos():
gh_user = bitwarden.rbw_get("github", git_user)
for repo in repositories:
if repo == "dotfiles":
dst = f"{home}/.config"
git_repos.remove(dst)
else:
dst = f"{home}/.local/git/{repo}"
git_repos.repo_clone(gh_user, repo, dst)
git_repos.repo_chdir(dst)
git_repos.repo_cfg(gh_user, repo)
# }}}
# Shell {{{
def set_shell():
shell.change()
shell.config()
shell.tools()
# }}}
# Audio {{{
def set_pipewire():
pipewire.service()
# }}}
# Customize {{{
def customize():
custom.wallpapers(home)
custom.spotify()
# }}}
# Python {{{
def set_python():
dirs = {
".local/bin",
".local/git/arch",
".local/git/arch-post",
".local/git/arch-tools",
}
for dir in dirs:
python.chdir(home, dir)
python.venv_init()
python.venv_activate()
# python.pip_upgrade()
# python.pip_install()
python.venv_deactivate()
dir = ".local/share/python"
python.chdir(home, dir)
python.venv_init_debugpy()
python.venv_activate()
python.pip_install_debugpy()
python.venv_deactivate()
# }}}
# XDG {{{
def set_xdg():
xdg.move_rust(home)
xdg.remove_dirs(home)
xdg.remove_files(home)
xdg.remove_self(home)
xdg.open()
# }}}
if __name__ == "__main__":
# Check {{{
if os.getuid == 0:
print(":: [-] :: Executed as root :: UID=0")
sys.exit(1)
# }}}
# Argparse {{{
parser = argparse.ArgumentParser(
prog="python3 arch-post.py",
description="Arch post-install setup",
epilog="TODO"
)
args = parser.parse_args()
# }}}
# Logging {{{
logging.basicConfig(level=logging.INFO, filename="logs.log", filemode="w",
format="%(levelname)-7s :: %(module)s - %(funcName)s - %(lineno)d :: %(message)s")
# }}}
# Config {{{
config = configparser.ConfigParser()
config.read("config.ini")
# AUR
aur_helper = config.get("aur", "helper")
# Bitwarden
bw_mail = config.get("bitwarden", "mail")
bw_lock = config.get("bitwarden", "lock")
git_mail = config.get("bitwarden_data", "github_mail")
git_user = config.get("bitwarden_data", "github_user")
git_token = config.get("bitwarden_data", "github_token")
spotify_client_id = config.get("bitwarden_data", "spotify_client_id")
spotify_secret = config.get("bitwarden_data", "spotify_client_secret")
spotify_device_id = config.get("bitwarden_data", "spotify_device_id")
spotify_mail = config.get("bitwarden_data", "spotify_mail")
spotify_user = config.get("bitwarden_data", "spotify_user")
# GitHub
git_pubkey = config.get("github", "pubkey")
# Network
network_ip = config.get("network", "ip")
network_port = config.get("network", "port")
network_toggle = config.get("network", "wifi")
network_key = config.get("network", "wifi_key")
network_ssid = config.get("network", "wifi_ssid")
# Repositories
repositories = config.get("repositories", "repositories").split(", ")
# SSH
ssh_key = config.get("ssh", "key")
# Timezone
timezone = config.get("timezone", "zone")
for section in config.sections():
for key, value in config.items(section):
if not key.strip():
print(":: [-] :: ConfigParser :: Empty key")
raise ValueError(f"Empty key found :: [{section}]")
if not value.strip():
print(":: [-] :: ConfigParser :: Empty value")
raise ValueError(f"Empty value '{key}' in section [{section}]")
# }}}
# Global variables {{{
cwd = os.getcwd()
user = getpass.getuser()
home = f"/home/{user}"
aur_dir = f"/home/{user}/.local/src/{aur_helper}/"
ssh_dir = f"{cwd}/src/ssh"
# }}}
# Run {{{
set_system_time()
set_pacman()
set_rust()
set_aur()
set_bitwarden()
set_ssh()
set_git()
set_git_repos()
set_shell()
# set_pipewire()
customize()
set_python()
set_xdg()
# }}}