-
-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·349 lines (295 loc) · 11 KB
/
setup.sh
File metadata and controls
executable file
·349 lines (295 loc) · 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
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/bin/bash
## SDDM Astronaut Theme Installer
## Based on original by Keyitdev https://github.com/Keyitdev/sddm-astronaut-theme
## Copyright (C) 2022-2025 Keyitdev
# Script works in Arch, Fedora, Ubuntu. Didn't tried in Void and openSUSE
set -euo pipefail
readonly THEME_REPO="https://github.com/Keyitdev/sddm-astronaut-theme.git"
readonly THEME_NAME="sddm-astronaut-theme"
readonly THEMES_DIR="/usr/share/sddm/themes"
readonly PATH_TO_GIT_CLONE="$HOME/$THEME_NAME"
readonly METADATA="$THEMES_DIR/$THEME_NAME/metadata.desktop"
readonly DATE=$(date +%s)
readonly -a THEMES=(
"astronaut" "black_hole" "cyberpunk" "hyprland_kath" "jake_the_dog"
"japanese_aesthetic" "pixel_sakura" "pixel_sakura_static"
"post-apocalyptic_hacker" "purple_leaves"
)
# Logging with gum fallback
info() {
if command -v gum &>/dev/null; then
gum style --foreground 10 "✅ $*"
else
echo -e "\e[32m✅ $*\e[0m"
fi
}
warn() {
if command -v gum &>/dev/null; then
gum style --foreground 11 "⚠ $*"
else
echo -e "\e[33m⚠ $*\e[0m"
fi
}
error() {
if command -v gum &>/dev/null; then
gum style --foreground 9 "❌ $*" >&2
else
echo -e "\e[31m❌ $*\e[0m" >&2
fi
}
# UI functions
confirm() {
if command -v gum &>/dev/null; then
gum confirm "$1"
else
echo -n "$1 (y/n): "; read -r r; [[ "$r" =~ ^[Yy]$ ]]
fi
}
choose() {
if command -v gum &>/dev/null; then
gum choose --cursor.foreground 12 --header="" --header.foreground 12 "$@"
else
select opt in "$@"; do [[ -n "$opt" ]] && { echo "$opt"; break; }; done
fi
}
spin() {
local title="$1"; shift
if command -v gum &>/dev/null; then
gum spin --spinner="dot" --title="$title" -- "$@"
else
echo "$title"; "$@"
fi
}
# Install gum if missing
install_gum() {
local mgr=$(for m in pacman xbps-install dnf zypper apt; do command -v $m &>/dev/null && { echo $m; break; }; done)
case $mgr in
pacman) sudo pacman -S gum ;;
dnf) sudo dnf install -y gum ;;
zypper) sudo zypper install -y gum ;;
xbps-install) sudo xbps-install -y gum ;;
# refrence https://github.com/basecamp/omakub/issues/222
apt)
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install -y gum ;;
*) error "Cannot install gum automatically"; return 1 ;;
esac
}
# Check and install gum
check_gum() {
if ! command -v gum &>/dev/null; then
warn "Gum was not found - provides better UI experience"
if confirm "Install gum?"; then
install_gum && { info "Restarting with gum..."; main; } || warn "Using fallback UI"
fi
fi
}
# Install dependencies
install_deps() {
local mgr=$(for m in pacman xbps-install dnf zypper apt; do command -v $m &>/dev/null && { echo $m; break; }; done)
info "Package manager: $mgr"
case $mgr in
pacman) sudo pacman --needed -S sddm qt6-svg qt6-virtualkeyboard qt6-multimedia-ffmpeg ;;
xbps-install) sudo xbps-install -y sddm qt6-svg qt6-virtualkeyboard qt6-multimedia ;;
dnf) sudo dnf install -y sddm qt6-qtsvg qt6-qtvirtualkeyboard qt6-qtmultimedia ;;
zypper) sudo zypper install -y sddm libQt6Svg6 qt6-virtualkeyboard qt6-multimedia ;;
apt) sudo apt update && sudo apt install -y sddm qt6-svg-dev qml6-module-qtquick-virtualkeyboard qt6-multimedia-dev ;;
*) error "Unsupported package manager"; return 1 ;;
esac
info "Dependencies installed"
}
# Clone repository
clone_repo() {
[[ -d "$PATH_TO_GIT_CLONE" ]] && mv "$PATH_TO_GIT_CLONE" "${PATH_TO_GIT_CLONE}_$DATE"
spin "Cloning repository..." git clone -b master --depth 1 "$THEME_REPO" "$PATH_TO_GIT_CLONE"
info "Repository cloned to $PATH_TO_GIT_CLONE"
}
# Install theme
install_theme() {
local src="$HOME/$THEME_NAME"
local dst="$THEMES_DIR/$THEME_NAME"
[[ ! -d "$src" ]] && { error "Clone repository first"; return 1;}
# Backup and copy
[[ -d "$dst" ]] && sudo mv "$dst" "${dst}_$DATE"
sudo mkdir -p "$dst"
spin "Installing theme files..." sudo cp -r "$src"/* "$dst"/
# Install fonts
[[ -d "$dst/Fonts" ]] && spin "Installing fonts..." sudo cp -r "$dst/Fonts"/* /usr/share/fonts/
# Configure SDDM
echo "[Theme]
Current=$THEME_NAME" | sudo tee /etc/sddm.conf >/dev/null
sudo mkdir -p /etc/sddm.conf.d
echo "[General]
InputMethod=qtvirtualkeyboard" | sudo tee /etc/sddm.conf.d/virtualkbd.conf >/dev/null
info "Theme installed"
}
# Select theme variant
select_theme() {
[[ ! -f "$METADATA" ]] && { error "Install theme first"; return 1; }
local theme=$(choose "${THEMES[@]}" || echo "astronaut")
sudo sed -i "s|^ConfigFile=.*|ConfigFile=Themes/${theme}.conf|" "$METADATA"
info "Selected theme: $theme"
}
_disable_dm_systemd() {
sudo systemctl disable display-manager.service 2>/dev/null || true
}
_disable_dm_openrc() {
for dm in gdm lightdm lxdm emptty greetd; do
sudo rc-update del "$dm" default 2>/dev/null || true
done
}
_disable_dm_runit() {
local runsvdir
runsvdir=$(_runit_runsvdir)
for dm in gdm lightdm lxdm emptty greetd; do
sudo rm -f "$runsvdir/$dm" 2>/dev/null || true
done
}
_disable_dm_dinit() {
for dm in gdm lightdm lxdm emptty greetd; do
sudo rm -f "/etc/dinit.d/boot.d/$dm" 2>/dev/null || true
sudo dinitctl disable "$dm" 2>/dev/null || true
done
}
_runit_runsvdir() {
if [ -d /run/runit/service ]; then echo "/run/runit/service"
elif [ -d /etc/runit/runsvdir/default ]; then echo "/etc/runit/runsvdir/default"
else
error "Cannot find runit service directory"
return 1
fi
}
detect_init() {
# Pass 1: PID 1 comm (most reliable - no external deps)
local pid1_comm
pid1_comm=$(cat /proc/1/comm 2>/dev/null || true)
case "$pid1_comm" in
systemd) echo "systemd"; return ;;
dinit) echo "dinit"; return ;;
runit) echo "runit"; return ;;
openrc-init|openrc) echo "openrc"; return ;;
esac
# Pass 2: characteristic binaries / directories
command -v dinitctl &>/dev/null && { echo "dinit"; return; }
command -v rc-service &>/dev/null && { echo "openrc"; return; }
{ command -v sv &>/dev/null && [ -d /etc/sv ]; } && { echo "runit"; return; }
command -v systemctl &>/dev/null && { echo "systemd"; return; }
echo "unknown"
}
# Enable SDDM
enable_sddm() {
local init
init=$(detect_init)
info "Detected init system: $init"
case "$init" in
systemd)
_disable_dm_systemd
sudo systemctl enable --now sddm.service
;;
openrc)
_disable_dm_openrc
sudo rc-update add sddm default
# Start immediately if we are in a live session
sudo rc-service sddm start 2>/dev/null || true
;;
runit)
local runsvdir
runsvdir=$(_runit_runsvdir)
if [ ! -d /etc/sv/sddm ]; then
error "/etc/sv/sddm not found - is sddm-runit (or equivalent) installed?"
return 1
fi
_disable_dm_runit
sudo ln -sf /etc/sv/sddm "$runsvdir/sddm"
info "sddm symlinked into $runsvdir"
;;
dinit)
if [ ! -f /etc/dinit.d/sddm ]; then
error "/etc/dinit.d/sddm not found - is sddm-dinit (or equivalent) installed?"
return 1
fi
_disable_dm_dinit
# boot.d symlink makes the service start automatically at boot
sudo mkdir -p /etc/dinit.d/boot.d
sudo ln -sf /etc/dinit.d/sddm /etc/dinit.d/boot.d/sddm
# Also enable & start in the running session
if command -v dinitctl &>/dev/null; then
sudo dinitctl enable sddm 2>/dev/null || true
sudo dinitctl start sddm 2>/dev/null || true
fi
;;
# ── Unknown / manual fallback ─────────────────────
*)
warn "Could not detect init system automatically."
warn "Please enable sddm manually:"
echo ""
echo " systemd - sudo systemctl enable --now sddm"
echo " openrc - sudo rc-update add sddm default"
echo " runit - sudo ln -s /etc/sv/sddm /run/runit/service/"
echo " dinit - sudo ln -s /etc/dinit.d/sddm /etc/dinit.d/boot.d/sddm"
return 1
;;
esac
info "SDDM enabled"
warn "Reboot required"
}
preview_theme(){
local log_file="/tmp/${THEME_NAME}_$DATE.txt"
sddm-greeter-qt6 --test-mode --theme /usr/share/sddm/themes/sddm-astronaut-theme/ > $log_file 2>&1 &
greeter_pid=$!
# wait for ten seconds
for i in {1..10}; do
if ! kill -0 "$greeter_pid" 2>/dev/null; then
break
fi
sleep 1
done
if kill -0 "$greeter_pid" 2>/dev/null; then
kill "$greeter_pid"
fi
local theme="$(sed -n 's|^ConfigFile=Themes/\(.*\)\.conf|\1|p' $METADATA)"
info "Preview closed ($theme theme found)."
info "Log file: $log_file"
}
# Main menu
main() {
[[ $EUID -eq 0 ]] && { error "Don't run as root"; exit 1; }
command -v git &>/dev/null || { error "git required"; exit 1; }
check_gum
clear
while true; do
if command -v gum &>/dev/null; then
gum style --bold --padding "0 2" --border double --border-foreground 12 "🚀 SDDM Astronaut Theme Installer"
else
echo -e "\e[36m🚀 SDDM Astronaut Theme Installer\e[0m"
fi
local choice=$(choose \
"🚀 Complete Installation (recommended)" \
"📦 Install Dependencies" \
"📥 Clone Repository" \
"📂 Install Theme" \
"🔧 Enable SDDM Service" \
"🎨 Select Theme Variant" \
"✨ Preview the set theme" \
"❌ Exit")
case "$choice" in
"🚀 Complete Installation (recommended)") install_deps && clone_repo && install_theme && select_theme && enable_sddm && info "Everything done!" && exit 0;;
"📦 Install Dependencies") install_deps ;;
"📥 Clone Repository") clone_repo ;;
"📂 Install Theme") install_theme ;;
"🔧 Enable SDDM Service") enable_sddm ;;
"🎨 Select Theme Variant") select_theme ;;
"✨ Preview the set theme") preview_theme;;
"❌ Exit") info "Goodbye!"; exit 0 ;;
esac
echo; if command -v gum &>/dev/null; then
gum input --placeholder="Press Enter to continue..."
else
echo -n "Press Enter to continue..."; read -r
fi
done
}
# trap 'echo; info "Cancelled"; exit 130' INT TERM
main "$@"