-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_pc.py
More file actions
151 lines (121 loc) · 3.85 KB
/
Copy pathsetup_pc.py
File metadata and controls
151 lines (121 loc) · 3.85 KB
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
import os
import subprocess
HOME_DIR = os.environ.get("HOME")
CURR_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.dirname(CURR_DIR)
def run(command):
try:
print(command)
subprocess.call(command, shell=True)
except OSError as e:
print(f"{command} {e}")
def apt_install():
print("Install apt packages:")
APT_PACKAGES = [
"bat",
"black",
"btop",
"calibre",
"curl",
"epiphany-browser",
"eza",
"fabric",
"fzf",
"geany",
"geany-plugins",
"git",
"git-delta",
"gnucash",
"htop",
"inkscape",
"kitty",
"locate",
"ncal",
"ncdu",
"fastfetch",
"python3-pip",
"python3-pylsp",
"python3-venv",
"qalculate-gtk",
"rsync",
"silversearcher-ag",
"tree",
"ufw",
"vim",
"vlc",
"zip",
"zsh",
]
run(f"apt install {' '.join(APT_PACKAGES)}")
def setup_etc_hosts():
print("Setup /etc/hosts:")
run(f"cp {CURR_DIR}/files/hosts /etc/hosts")
run("chmod u=rw,g=r,o=r /etc/hosts")
def install_zsh_syntax_highlighting():
print("Install zsh syntax highlighting:")
run(
"git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /tmp/zsh-syntax-highlighting"
)
run("mv /tmp/zsh-syntax-highlighting /usr/local/share/zsh-syntax-highlighting")
def enable_firewall():
print("Enable Firewall:")
run("ufw enable")
def setup_dot_ssh():
print("Setup .ssh:")
home_dot_ssh = f"{HOME_DIR}/.ssh"
work_dot_ssh_path = f"{HOME_DIR}/Desktop/work/dot.ssh"
if os.path.isdir(home_dot_ssh):
print(f"{home_dot_ssh} already exists")
if not os.path.isdir(work_dot_ssh_path):
print(f"{work_dot_ssh_path} does not exist")
if not os.path.isdir(home_dot_ssh) and os.path.isdir(work_dot_ssh_path):
run(f"mkdir {home_dot_ssh}")
run(f"cp -r {work_dot_ssh_path}/* {home_dot_ssh}")
run(f"chmod g-rx,o-rx {HOME_DIR}/.ssh/github/id_rsa")
run(f"chmod g-rx,o-rx {HOME_DIR}/.ssh/id_rsa")
def add_home_configs():
print("Add configuration files to home directory:")
for filename in [".gitconfig", ".zshrc", "fabfile.py"]:
link_path = f"{HOME_DIR}/{filename}"
run(f"rm {link_path}")
run(f"ln -s {CURR_DIR}/files/{filename} {link_path}")
run(f"rm {HOME_DIR}/.zsh_history")
run(f"cp {CURR_DIR}/files/.zsh_history {HOME_DIR}/.zsh_history")
def add_kitty_config():
print("Add configuration files for kitty:")
run(f"mkdir -p {HOME_DIR}/.config/kitty")
for filename in ["kitty", "ahernp-kitty", "current-theme", "ahernp-session"]:
run(
f"ln -s {CURR_DIR}/files/kitty/{filename}.conf {HOME_DIR}/.config/kitty/{filename}.conf"
)
def add_helix_config():
print("Add configuration files for helix:")
run(f"mkdir -p {HOME_DIR}/.config/helix/themes")
for filename in ["config", "languages", "themes/ahernp"]:
run(
f"ln -s {CURR_DIR}/files/helix/{filename}.toml {HOME_DIR}/.config/helix/{filename}.toml"
)
def add_vim_config():
print("Add configuration file for vim:")
run(f"ln -s {CURR_DIR}/files/.vimrc {HOME_DIR}/.vimrc")
def change_shell_to_zsh():
print("Change shell to zsh:")
run("chsh -s /usr/bin/zsh")
def main():
is_root = os.geteuid() == 0
if is_root:
apt_install()
setup_etc_hosts()
install_zsh_syntax_highlighting()
enable_firewall()
else:
setup_dot_ssh()
add_helix_config()
add_kitty_config()
add_vim_config()
proceed = input("Check ~/.ssh has been set up. Proceed (y/n): ")
if proceed == "y":
add_home_configs()
change_shell_to_zsh()
if __name__ == "__main__":
main()