-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.lua
executable file
·222 lines (206 loc) · 10 KB
/
setup.lua
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
#!/usr/bin/env lua
local utils = require("scripts.utils")
local assert, log = utils.assert, utils.log
local GLib, Gio ---@type GLib, Gio
--- Wrap this in a function to avoid dependency on lgi when generating docs
local function _init()
local has_lgi, lgi = pcall(require, "lgi")
if not has_lgi then
io.stderr:write("lgi not found, aborting setup\n")
return
end
GLib, Gio = lgi.GLib, lgi.Gio
end
---@class SetupInfo
local M = {
---@type table<string, string>
aliases = {
ubuntu = "debian",
},
---@type table<string, string[]|{_extra: string[], _repo: string[]}>
commands = {
debian = { "apt", "install", "--" },
arch = {
--- Used for aur packages
_extra = { "yay", "-S", "--" },
_repo = { "pacman", "-S", "--" },
},
},
---@class PackageInfo
---@field description string
---@field url? string
---@class ExtPackageList
---@field _extra? PackageList
---@field _repo PackageList
---@alias PackageList {[string]: string|PackageInfo} Package name to description (why it's needed)
---@type table<string, PackageList|ExtPackageList>
---TODO: Add descriptions
packages = {
debian = { ---@type PackageList
["awesome"] = { description = "AwesomeWM", url = "https://awesomewm.org/" },
["fonts-roboto"] = { description = "The primary font", url = "https://fonts.google.com/specimen/Roboto" },
["rofi"] = {
description = "Window switcher and application launcher",
url = "https://github.com/davatorium/rofi",
},
["picom"] = { description = "Compositor", url = "https://github.com/yshui/picom" },
["i3lock"] = { description = "Screen locker - `lock` script", url = "https://i3wm.org/i3lock/" },
["xclip"] = { description = "Copy to clipboard", url = "https://github.com/astrand/xclip" },
["qt5-style-plugins"] = {
description = "Use GTK theme in Qt applications",
url = "https://github.com/qt/qtstyleplugins",
},
["brightnessctl"] = {
description = "adjusting screen brightness with keyboard shortcuts",
url = "https://github.com/Hummer12007/brightnessctl",
},
["flameshot"] = { description = "Screenshot tool", url = "https://flameshot.org" },
["pasystray"] = { description = "Audio - System Tray", url = "https://github.com/christophgysin/pasystray" },
["network-manager-gnome"] = { description = "Network - System Tray", url = "https://apps.gnome.org" },
["policykit-1-gnome"] = { description = "Polkit", url = "https://wiki.gnome.org/Projects/PolicyKit" },
["blueman"] = { description = "Bluetooth - System Tray", url = "https://github.com/blueman-project/blueman" },
["diodon"] = { description = "Persistent cliboard manager", url = "https://github.com/diodon-dev/diodon" },
["udiskie"] = {
description = "Automatically mount removable media - System Tray",
url = "https://github.com/coldfix/udiskie",
},
["xss-lock"] = {
description = "Auto-lock on suspend/idle",
url = "https://bitbucket.org/raymonad/xss-lock/src/master/",
},
["ibus"] = { description = "Changing input method - System Tray", url = "https://github.com/ibus/ibus" },
["numlockx"] = { description = "Enable Numlock on startup", url = "https://github.com/rg3/numlockx" },
["playerctl"] = { description = "Control media players", url = "https://github.com/altdesktop/playerctl" },
["libinput-tools"] = {
description = "Needed for libinput-gestures (touchpad gestures)",
url = "https://wayland.freedesktop.org/libinput/doc/latest/",
},
["x11-xserver-utils"] = {
description = "xrandr - needed for autorandr, xset - disable DPMS",
url = "https://www.x.org/wiki/",
},
["redshift"] = {
description = "Automatically adjust screen temperature",
url = "https://github.com/jonls/redshift",
},
["pulseaudio-utils"] = {
description = "Adjust volume with keyboard shortcuts",
url = "https://www.freedesktop.org/wiki/Software/PulseAudio/",
},
},
arch = {
_extra = { ---@type PackageList
["rofi-git"] = {
description = "Window switcher and application launcher - Git Version has some fixes",
url = "https://github.com/davatorium/rofi",
},
["qt5-styleplugins"] = {
description = "Use GTK theme in Qt applications",
url = "https://github.com/qt/qtstyleplugins",
},
["diodon"] = { description = "Persistent cliboard manager", url = "https://github.com/diodon-dev/diodon" },
},
_repo = { ---@type PackageList
["awesome"] = { description = "AwesomeWM", url = "https://awesomewm.org/" },
["ttf-roboto"] = { description = "The primary font", url = "https://fonts.google.com/specimen/Roboto" },
["picom"] = { description = "Compositor", url = "https://github.com/yshui/picom" },
["i3lock"] = { description = "Screen locker - `lock` script", url = "https://i3wm.org/i3lock/" },
["xclip"] = { description = "Copy to clipboard", url = "https://github.com/astrand/xclip" },
["brightnessctl"] = {
description = "adjusting screen brightness with keyboard shortcuts",
url = "https://github.com/Hummer12007/brightnessctl",
},
["flameshot"] = { description = "Screenshot tool", url = "https://flameshot.org" },
["pasystray"] = { description = "Audio system tray", url = "https://github.com/christophgysin/pasystray" },
["network-manager-applet"] = { description = "Network - System Tray", url = "https://apps.gnome.org" },
["polkit-gnome"] = { description = "Polkit", url = "https://wiki.gnome.org/Projects/PolicyKit" },
["blueman"] = { description = "Bluetooth - System Tray", url = "https://github.com/blueman-project/blueman" },
["udiskie"] = {
description = "Automatically mount removable media - System Tray",
url = "https://github.com/coldfix/udiskie",
},
["xss-lock"] = {
description = "Auto-lock on suspend/idle",
url = "https://bitbucket.org/raymonad/xss-lock/src/master/",
},
["ibus"] = { description = "Changing input method - System Tray", url = "https://github.com/ibus/ibus" },
["numlockx"] = { description = "Enable Numlock on startup", url = "https://github.com/rg3/numlockx" },
["playerctl"] = { description = "Control media players", url = "https://github.com/altdesktop/playerctl" },
["libinput"] = {
description = "Needed for libinput-gestures (touchpad gestures)",
url = "https://wayland.freedesktop.org/libinput/doc/latest/",
},
["xorg-xrandr"] = {
description = "xrandr - needed for autorandr, xset - disable DPMS",
url = "https://www.x.org/wiki/",
},
["redshift"] = {
description = "Automatically adjust screen temperature",
url = "https://github.com/jonls/redshift",
},
["libpulse"] = {
description = "Adjust volume with keyboard shortcuts",
url = "https://www.freedesktop.org/wiki/Software/PulseAudio/",
},
["pacutils"] = { description = "Get update count", url = "https://github.com/andrewgregory/pacutils" },
},
},
},
}
local function _get_install_cmd(id)
local commands = assert(M.commands[id], ("BUG: Missing commands for OS: "):format(id))
local packages = assert(M.packages[id], ("BUG: Missing packages for OS: "):format(id))
-- Simple table
if not commands._repo then return utils.table_concat(commands, utils.table_keys(packages)) end
-- Has repo commands, e.g. Arch pacman
if not commands._extra then
local repo_packages = packages._repo
assert(type(repo_packages) == "table", "BUG: repo packages are not a table!")
return utils.table_concat(commands._repo, utils.table_keys(repo_packages))
end
-- Has extra commands, e.g. Arch AUR. Extra command is expected to be able to install repo packages
local repo_packages, extra_packages = packages._repo, packages._extra
assert(type(repo_packages) == "table", "BUG: repo packages are not a table!")
assert(type(extra_packages) == "table", "BUG: extra packages are not a table!")
repo_packages, extra_packages = utils.table_keys(repo_packages), utils.table_keys(extra_packages)
local repo_command, extra_command = commands._repo, commands._extra
--- If extra command is found in PATH, use it
if GLib.find_program_in_path(extra_command[1]) then
return utils.table_concat(extra_command, extra_packages, repo_packages)
end
-- Fallback to repo command
log.warn(("%s not found in PATH, falling back to %s"):format(extra_command[1], repo_command[1]))
return utils.table_concat(repo_command, repo_packages)
end
---@param id string ID of the OS
function M.install_packages(id)
while M.aliases[id] do
id = M.aliases[id]
end
assert(M.commands[id], ("Unsupported OS: %s. Use --no-install to skip installing packages"):format(id))
local cmd = assert(_get_install_cmd(id), "BUG: Failed to construct command")
utils.spawn_check("install packages", cmd)
end
function M.main()
_init()
local script_dir = debug.getinfo(1).source:match("@?(.*/)") or "."
local dir = Gio.File.new_for_path(script_dir)
if not dir:query_exists() then log.abort("Current directory does not exist") end
if GLib.chdir(assert(dir:get_path())) ~= 0 then log.abort("Failed to change directory") end
do --- Install packages
local id = assert(GLib.get_os_info("ID_LIKE") or GLib.get_os_info("ID"), "Could not determine OS ID")
if arg[1] ~= "--no-install" then M.install_packages(id) end
end
utils.spawn_check("update submodules", { "git", "submodule", "update", "--init", "--recursive" })
local AR_LAUNCHER_DIR = dir:get_child("./deps/autorandr/contrib/autorandr_launcher")
utils.spawn_check(
("compile autorandr_launcher (%s)"):format(dir:get_relative_path(AR_LAUNCHER_DIR)),
{ "make", "-s" },
{ cwd = assert(AR_LAUNCHER_DIR:get_path()) }
)
print("Setup completed successfully!")
end
if debug.getinfo(4) == nil then
M.main() -- If called directly from the command line, run main
end
return M