-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain
More file actions
executable file
·314 lines (299 loc) · 9.42 KB
/
main
File metadata and controls
executable file
·314 lines (299 loc) · 9.42 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
#main
#set -e # Debug line
## Helpers any POSIX compliant command
. ./util_f
parse_args "$@"
setup_cleanup
# Show help if requested
if exec_args "HELP"; then
show_help
exit 0
fi
# Load constants
if file_ex "./..."; then
. ./...
fi
## Magic reset line
#rm -rf "${rel}${p_lib}"
if exec_args "RESET"; then
postop "Resetting: removing ${rel}${p_lib}"
rm -rf "${rel}${p_lib}"
fi
# Setup lib directory
dir_excreate "${rel}${p_lib}"
dir_excreate "${rel}${zl_d}/a" # Create ISO dir
dir_excreate "${rel}${zl_d}/d" # Create ISO dir
dir_excreate "${rel}${zl_d}/c" # Create Disks dir
# Awlays give these back to sudo user
chown_all "$SUDO_USER" "${rel}${zl_d}/d" && dir_own "${rel}${zl_d}/d" "$SUDO_USER"
chown_all "$SUDO_USER" "${rel}${zl_d}/c" && dir_own "${rel}${zl_d}/c" "$SUDO_USER"
# Create settings if not exist
if ! file_ex "${rel}${p_lib}/${c_file}.${c_ext}"; then
preop "Creating ${rel}${p_lib}/${c_file}.${c_ext}"
cat > "${rel}${p_lib}/${c_file}.${c_ext}" << 'EOF'
#FORMAT= # 1 Start enabled / 0 Start disabled
COLORS=1 # 0 Disables colors of all output
TIMING=1 # 0 Disables timing output of rcw
DEBUGS=1 # 0 Disables info outputs from program
TEELOG=1 # 0 Disables complete log file
LOGMEM=0 # 1 Enables keeping previous log
LOGCLR=0 # 1 Enables non standard ascii in log
CATART=1 # 0 Disables cli art sadface
EOF
else
preop "Settings already exists. Skipping..."
fi
# Load settings > Linked to functionalities
if file_ex "${rel}${p_lib}/${c_file}.${c_ext}"; then
. "${rel}${p_lib}/${c_file}.${c_ext}"
fi
# Create if not exists rcw
if ! file_ex "${rel}${p_lib}/${rcw_file}"; then
preop "Creating ${rel}${p_lib}/${rcw_file}"
cat > "${rel}${p_lib}/${rcw_file}" << 'EOF'
#!/bin/bash
#rcw
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
NC='\033[0m'
info() {
[ "${DEBUGS:-1}" = "1" ] && echo -e "${BLUE}[INFO]${NC} $*"
}
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
reop() { echo -e "${GREEN}[OKAY]${NC} $*"; }
die() {
echo -e "${RED}[ERROR]${NC} $*";
exec 1>&- 2>&-
wait
exit 1
}
# Color-only functions (no tags) for inline use
c_green() { echo -e "${GREEN}$*${NC}"; }
c_red() { echo -e "${RED}$*${NC}"; }
c_cyan() { echo -e "${CYAN}$*${NC}"; }
time_c() { echo -e "${CYAN}$*${NC}"; }
get_usec() {
date +%s%6N
}
fmt_dur() {
local usec=$1
local sec=$((usec / 1000000))
local us=$((usec % 1000000))
local ms=$((us / 1000))
local us_only=$((us % 1000))
if [ $sec -gt 0 ]; then
printf "%d.%03ds" $sec $((us / 1000))
elif [ $ms -gt 0 ]; then
printf "%d.%03dms" $ms $us_only
else
printf "%dμs" $us
fi
}
rcw() {
local cmd="$*"
[ "${DEBUGS}" = "1" ] && echo -e "${BLUE}[INFO]${NC} Running: $cmd"
local t_start
t_start=$(get_usec)
eval "$cmd"
local rc=$?
local t_end
t_end=$(get_usec)
local dur=$((t_end - t_start))
local check="✓"
local cross="✗"
local clock="【┘】"
if [ "$TIMING" = "1" ]; then
local t_str
t_str=$(fmt_dur $dur)
if [ "$COLORS" = "1" ]; then
echo -e "$(c_cyan "[TIME]") ${t_str} ${clock}"
else
echo -e "[TIME] ${t_str} ${clock}"
fi
fi
if [ $rc -eq 0 ]; then
if [ "$COLORS" = "1" ]; then
echo -e "$(c_green "[SUCCESS]") Exit: ${rc} ${check}"
else
echo -e "[SUCCESS] Exit: ${rc} ${check}"
fi
else
if [ "$COLORS" = "1" ]; then
echo -e "$(c_red "[ERROR]") Exit: ${rc} ${cross}"
else
echo -e "[ERROR] Exit: ${rc} ${cross}"
fi
fi
return $rc
}
init_log() {
if [ "$TEELOG" = "1" ]; then
local log_file="${1:-./vase.log}"
if [ "$LOGCLR" = "1" ]; then
# Keep colors in log
if [ "$LOGMEM" = "0" ]; then
true > "$log_file"
fi
exec > >(tee -a "$log_file") 2>&1
else
# Strip colors from log
if [ "$LOGMEM" = "0" ]; then
true > "$log_file"
exec > >(tee -a >(sed 's/\x1b\[[0-9;]*m//g' > "$log_file")) 2>&1
else
exec > >(tee -a >(sed 's/\x1b\[[0-9;]*m//g' >> "$log_file")) 2>&1
fi
fi
info "Logging to: $log_file"
fi
}
EOF
else
preop "Rcw already exists. Skipping..."
fi
if file_ex "${rel}${vase_d}/${cli_a}" && [ "${CATART:-1}" = "1" ]; then
nlp
cat "${rel}${vase_d}/${cli_a}"
nlp
fi
# Make exec
file_mex "${rel}${p_lib}/${rcw_file}"
# Check wrapper
if file_ex "${rel}${p_lib}/${rcw_file}"; then
# Source wrapper
. "${rel}${p_lib}/${rcw_file}"
info "Loaded ${rcw_file} from ${rel}${p_lib}"
fi
if cmd_exists "tree"; then
info "Output dir strucs to .directory file..."
tree_dir "$s_dir" # Outputs tree to .dir file conditional
fi
if exec_args "UPDATE"; then
git submodule update --init --recursive
check_updates && exit
fi
if exec_args "BRANCH"; then
branch_name="$(get_branch_name)"
if [ -z "$branch_name" ]; then
die "No branch name specified. Usage: -b <branch>"
fi
# Check if branch exists
if ! git rev-parse --verify "$branch_name" >/dev/null 2>&1; then
die "Branch '$branch_name' does not exist"
fi
# Switch to branch
preop "Switching to branch: $branch_name"
git checkout "$branch_name" || die "Failed to switch to branch $branch_name"
postop "Switched to branch: $(git branch --show-current)"
exit
fi
if exec_args "EDIT_CONF"; then
preop "Editing config file"
$EDITOR ... && exit
fi
if exec_args "EDIT_KLARTIX_CONF"; then
preop "Editing Klartix config file"
$EDITOR "./vase_os/klar_tix_lvm/klartix.conf" && exit
fi
if exec_args "POST"; then
post_type="$(get_post_type)"
preop "Running post-install script: post_${post_type}..."
"./${vase_d}/klar_tix_lvm/post_plasma" && exit
fi
if exec_args "POST_EDIT"; then
preop "Opening post-install script in $EDITOR: "
$EDITOR "./${vase_d}/klar_tix_lvm/post_plasma" && exit
fi
if exec_args "PKG_MAN"; then
preop "Launching PACTOPAC package manager..."
gui_som "$SUDO_USER"
python3 "./${pp_d}/main.py" && exit
fi
if im_groot; then
if exec_args "KLARTIX"; then
preop "Launching Klartix Artix Linux installer..."
"./${vase_d}/klar_tix_lvm/klartix_lvm" && exit
fi
if exec_args "KDE_EDIT"; then
preop "Opening Klartix Plasma installer in $EDITOR..."
$EDITOR "./${vase_d}/klar_tix_lvm/klartix_plasma" && exit
fi
if exec_args "DESKTOP"; then
preop "Launching Klartix Plasma desktop installer..."
"./${vase_d}/klar_tix_lvm/klartix_plasma" && exit
fi
# Use reop for regular operation green output
if im_sudo; then
obanner "PERMS CHECK"
info "Running as elevated user..."
info "Session type: $(gui_what)"
gui_som "$SUDO_USER" #export XDG for sudo user
cbanner "PERMS CHECK"
obanner "ENVIR CHECK"
"./${vase_p_deps}"
rcw "echo \"${vm_d}/: \$(du -sh \"./${zl_d}/${vm_d}/\" | cut -f1) (\$(find \"./${zl_d}/${vm_d}/\" -type f | wc -l))\""
rcw "echo \"c/: \$(du -sh \"./${zl_d}/c/\" | cut -f1) (\$(find \"./${zl_d}/c/\" -type f | wc -l))\""
cbanner "ENVIR CHECK"
if exec_args "START"; then
obanner "FILES CHECK"
if ! file_ex "./${zl_d}/${vm_d}/${iso_n}.${iso_ext}"; then
info "Looking for ./${zl_d}/${vm_d}/${iso_n}.${iso_ext}"
warn "ISO: $iso_n Not found in dir ${vm_d}. Change ... config. Or get an ISO"
else
info "Found $iso_n in proper location."
fi
cbanner "FILES CHECK"
. "./${vase_p_env}"
preop "Starting VM Menu..."
"./${zl_d}/vm_start" && exit
fi
if exec_args "QUICK"; then
. "./${vase_p_env}"
quick_arg="$(get_quick_cmd)"
if ! file_ex "./${zl_d}/${vm_d}/${iso_n}.${iso_ext}"; then
info "Looking for ./${zl_d}/${vm_d}/${iso_n}.${iso_ext}"
warn "ISO: $iso_n Not found in dir ${vm_d}. Build using -i or change ... config. Or get an ISO"
else
info "Found $iso_n in proper location dir: ${vm_d}"
fi
if [ -z "$quick_arg" ]; then
"./${zl_d}/vm_start" "__default__"
else
"./${zl_d}/vm_start" "$quick_arg"
fi
exit $?
fi
if exec_args "GRUB"; then
grub_args="$(get_grub_cmd)"
# Extract first arg after -g flag
grub_flag=$(echo "$grub_args" | awk '{print $2}')
# Get remaining args
grub_rest=$(echo "$grub_args" | cut -d' ' -f3-)
if [ -z "$grub_flag" ]; then
"./${gl_d}/grome_lum" -h && exit
else
"./${gl_d}/grome_lum" "$grub_flag" $grub_rest && exit
fi
fi
if dir_own "${rel}${p_lib}" "root"; then
## Give back to user
info "Changing ownership from root to $SUDO_USER"
chown_all "$SUDO_USER" "${rel}${p_lib}"
# Verify we actually gave back
dir_own "${rel}${p_lib}" "$SUDO_USER" || die "Failed to switch ownership"
else
info "Skipping... file already owned by $SUDO_USER"
fi
else
reop "Running as root. Skipping..."
fi
else
if am_iuser; then
die "Running as regular user." # Or warn and do smthn else
fi
fi