Repository navigation
Expand file tree
/
Copy pathinstall.lua
More file actions
executable file
·177 lines (148 loc) · 6.11 KB
/
Copy pathinstall.lua
File metadata and controls
executable file
·177 lines (148 loc) · 6.11 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
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
#!/usr/bin/env lua5.4
--[[
install.lua
Installer for Linux (pacman, apt, dnf), macOS (Homebrew), and Windows (winget).
Needs lua (5.4 / lua / luajit) and git. sudo only on apt/dnf/pacman.
Run: lua install.lua
]]
-- Allow require("utilities.installation.X") regardless of cwd.
local function script_dir()
local source = debug.getinfo(1, "S").source:sub(2)
local dir = source:match("(.*/)") or source:match("(.*\\)") or "./"
return dir
end
local SCRIPT_DIR = script_dir():gsub("[/\\]$", "")
package.path = SCRIPT_DIR .. "/?.lua;" .. SCRIPT_DIR .. "/?/init.lua;" .. package.path
local cli = require("utilities.installation.cli")
local util = require("utilities.installation.util")
local installer = require("utilities.installation.installer")
local greeter = require("utilities.installation.greeter")
local done = require("utilities.installation.done")
SCRIPT_DIR = util.make_absolute(SCRIPT_DIR)
-- --- Config -----------------------------------------------------------
local HOME = util.home()
local LOG_FILE = SCRIPT_DIR .. "/fails.log"
local DEFAULT_INSTALL_DIR = util.nvim_config_dir()
local PREVIOUS_DIR = util.path_join(HOME, ".config", "previous-deepworkplan-vim")
if util.is_windows() then
PREVIOUS_DIR = util.path_join(util.data_home(), "previous-deepworkplan-vim")
end
local FONT_SOURCE = SCRIPT_DIR .. "/utilities/installation/iosevka_nerd_font.ttf"
local FAIL_COUNT = 0
-- Lua 5.1/LuaJIT returns a raw status number from os.execute (always
-- truthy, even 0). Lua 5.2+ returns a boolean. Normalize both.
local function exec_ok(cmd)
local a = os.execute(cmd)
if type(a) == "number" then
return a == 0
end
return a == true
end
local function dir_exists(path)
return util.dir_exists(path)
end
local function log_fail(msg)
-- If SCRIPT_DIR is gone mid-run, log to the system temp directory.
local fallback_log = (os.getenv("TEMP") and (os.getenv("TEMP") .. "/deepworkplan-vim-fails.log")) or "/tmp/deepworkplan-vim-fails.log"
local target_log = dir_exists(SCRIPT_DIR) and LOG_FILE or fallback_log
local f = io.open(target_log, "a")
if f then
f:write(string.format("[%s] %s\n", os.date("%Y-%m-%d %H:%M:%S"), msg))
f:close()
end
FAIL_COUNT = FAIL_COUNT + 1
end
local function expand_path(path)
local home = HOME
if path:sub(1, 1) == "~" then
return home .. path:sub(2)
end
return path
end
-- Ask for sudo while the terminal is still in cooked mode, before any
-- stty raw prompts. Later sudo calls reuse the cached credentials.
-- Root (containers) and DWP_VIM_SKIP_PACKAGES=1 (deps baked into an
-- image) both skip this gate.
local skip_value = os.getenv("DWP_VIM_SKIP_PACKAGES") or ""
local skip_packages = skip_value ~= "" and skip_value ~= "0"
local manager, manager_err = util.get_package_manager()
if manager == nil then
io.stderr:write((manager_err or "No package manager") .. "\n")
end
if not skip_packages and manager and util.needs_sudo(manager) and not util.is_root() then
io.write("Administrator privileges are required to install system packages.\n")
if not exec_ok("sudo -v") then
io.stderr:write("Could not validate sudo credentials. Aborting.\n")
os.exit(1)
end
end
local INSTALL_DIR = DEFAULT_INSTALL_DIR
local use_custom_dir = cli.confirm("Use a custom config directory? (default is " .. DEFAULT_INSTALL_DIR .. ")", false)
if use_custom_dir then
local custom_path = cli.text("Enter the path of your custom directory")
if custom_path == nil or custom_path == "" then
io.write("No path given, using the default: " .. DEFAULT_INSTALL_DIR .. "\n")
else
INSTALL_DIR = expand_path(custom_path)
end
end
if not util.is_absolute(INSTALL_DIR) then
io.stderr:write("Resolved install path is not absolute: " .. INSTALL_DIR .. "\n")
os.exit(1)
end
local greeted_ok = greeter.greeter()
if not greeted_ok then
-- (The banner used to hold the screen for 5 s here — dead time on
-- every install and re-run; audit I-14. The setup output that
-- follows keeps it on screen long enough to read.)
log_fail("Something went wrong while greeting")
end
-- Never move/delete the directory we are running from. A relative
-- SCRIPT_DIR (./) used to miss this and rm -rf the cwd; brew/pip/pnpm
-- then failed with getcwd ENOENT.
local RESOLVED_INSTALL_DIR = util.realpath(INSTALL_DIR)
local CWD = util.make_absolute(util.pwd())
if RESOLVED_INSTALL_DIR == SCRIPT_DIR
or util.path_is_under(CWD, RESOLVED_INSTALL_DIR)
or util.path_is_under(SCRIPT_DIR, RESOLVED_INSTALL_DIR) then
io.write("Install directory (" .. INSTALL_DIR .. ") is the directory DeepWorkPlan Vim is running from — nothing to back up, skipping.\n")
else
local ok = util.replace_old(INSTALL_DIR, PREVIOUS_DIR)
if not ok then
log_fail("Something went wrong replacing old nvim config")
end
end
if skip_packages then
io.write("DWP_VIM_SKIP_PACKAGES is set: system packages are assumed present (container image, CI). Installing pckr and the font only.\n")
if not installer.install_pckr(SCRIPT_DIR) then
log_fail("Could not clone pckr.nvim")
end
elseif manager == nil then
log_fail(manager_err or "Could not detect a package manager")
else
io.write("Detected package manager: " .. manager .. "\n")
local extra_options = {}
for _, pkg in ipairs(installer.EXTRA_PACKAGES) do
table.insert(extra_options, { label = pkg.name, value = pkg.name, desc = pkg.desc, checked = true })
end
local chosen_extras = cli.multi_select("Optional extra packages:", extra_options)
if installer.installDependencies(manager, chosen_extras, SCRIPT_DIR) then
done.installation_success()
else
log_fail("installDependencies failed for manager: " .. manager)
end
end
-- (No install marker is written here: the appname-composed marker that
-- install.sh maintains after the headless bootstrap is the real one.)
if installer.install_font(FONT_SOURCE) then
io.write("Font installed.\n")
else
log_fail("Could not install the Iosevka Nerd Font")
end
if FAIL_COUNT > 0 then
io.write("It seems there were some failures (" .. FAIL_COUNT .. "), please submit an issue at:\n\n")
io.write("\thttps://github.com/DailybotHQ/deepworkplan-vim/issues/new\n")
io.write("Details logged in: " .. LOG_FILE .. "\n")
os.exit(1)
end
os.exit(0)