-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
191 lines (162 loc) · 6.79 KB
/
Copy pathinstall.sh
File metadata and controls
191 lines (162 loc) · 6.79 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
#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/common.sh
source "$SCRIPT_DIR/scripts/common.sh"
require_root
detect_target_user
touch "$LOG_FILE"
chmod 0644 "$LOG_FILE"
trap 'die "Installation failed near line $LINENO. See $LOG_FILE."' ERR
printf '%s %s installer\n' "$PROJECT_NAME" "$PROJECT_VERSION"
printf 'Target user: %s\n' "$TARGET_USER"
step "Checking operating system"
[ -r /etc/os-release ] || die "/etc/os-release was not found."
# shellcheck disable=SC1091
source /etc/os-release
[ "${ID:-}" = "debian" ] || die "This release supports Debian only. Detected: ${PRETTY_NAME:-unknown}"
case "${VERSION_ID:-}" in
12|13) log "Supported Debian version detected: ${PRETTY_NAME}" ;;
*) log "WARNING: untested Debian version detected: ${PRETTY_NAME}" ;;
esac
step "Installing packages"
mapfile -t packages < <(sed -e 's/[[:space:]]*#.*$//' -e '/^[[:space:]]*$/d' "$SCRIPT_DIR/dependencies.list")
[ "${#packages[@]}" -gt 0 ] || die "No packages found in dependencies.list."
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y --no-install-recommends "${packages[@]}"
step "Configuring sudo access"
usermod -aG sudo "$TARGET_USER"
sudoers_file="/etc/sudoers.d/writerdeck-${TARGET_USER}"
printf '%s ALL=(ALL:ALL) NOPASSWD: ALL\n' "$TARGET_USER" > "$sudoers_file"
chmod 0440 "$sudoers_file"
visudo -cf "$sudoers_file" >/dev/null
step "Installing writerdeckOS files"
install -d -m 0755 "$CONFIG_DIR"
if [ ! -s "$EDITOR_FILE" ]; then
printf '%s\n' "/usr/bin/wordgrinder" > "$EDITOR_FILE"
fi
chmod 0644 "$EDITOR_FILE"
install -m 0755 "$SCRIPT_DIR/scripts/writerdeck-launch" /usr/local/bin/writerdeck-launch
install -m 0755 "$SCRIPT_DIR/scripts/wdmenu" /usr/local/bin/wdmenu
install -m 0755 "$SCRIPT_DIR/scripts/writerdeck-update" /usr/local/bin/writerdeck-update
install -d -m 0755 /usr/local/lib/writerdeckos
install -m 0644 "$SCRIPT_DIR/scripts/theme.sh" /usr/local/lib/writerdeckos/theme.sh
if [ ! -s "$CONFIG_DIR/theme" ]; then
printf '%s\n' standard > "$CONFIG_DIR/theme"
fi
chmod 0644 "$CONFIG_DIR/theme"
# Generate the tmux colours from the saved theme, preserving a previous choice
# when the installer is run again.
# shellcheck disable=SC1091
. /usr/local/lib/writerdeckos/theme.sh
writerdeck_write_tmux_theme "$(writerdeck_theme_name)"
chmod 0644 "$CONFIG_DIR/tmux-theme.conf"
backup_once /etc/tmux.conf
install -m 0644 "$SCRIPT_DIR/config/tmux.conf" /etc/tmux.conf
install -m 0644 "$SCRIPT_DIR/config/writerdeck-profile.sh" /etc/profile.d/writerdeck.sh
step "Configuring tty1 autologin"
autologin_dir="/etc/systemd/system/getty@tty1.service.d"
install -d -m 0755 "$autologin_dir"
sed "s/@USER@/${TARGET_USER//\//\\/}/g" \
"$SCRIPT_DIR/config/autologin.conf.in" \
> "$autologin_dir/autologin.conf"
chmod 0644 "$autologin_dir/autologin.conf"
systemctl daemon-reload
systemctl enable getty@tty1.service >/dev/null
step "Configuring NetworkManager"
systemctl enable --now NetworkManager.service
step "Configuring console mouse support"
systemctl enable gpm.service >/dev/null
if ! systemctl restart gpm.service; then
log "WARNING: GPM could not start immediately. It remains enabled and may start when a mouse device is available or after reboot."
fi
step "Configuring document and USB locations"
install -d -m 0755 /etc/skel/Documents
install -d -o "$TARGET_USER" -g "$TARGET_USER" -m 0755 "$TARGET_HOME/Documents"
install -d -o "$TARGET_USER" -g "$TARGET_USER" -m 0755 "$TARGET_HOME/.config/autostart"
install -d -o "$TARGET_USER" -g "$TARGET_USER" -m 0700 "$TARGET_HOME/.config/micro"
usb_link="$TARGET_HOME/USBs"
if [ -L "$usb_link" ]; then
:
elif [ -e "$usb_link" ]; then
log "WARNING: $usb_link exists and is not a symlink; leaving it unchanged."
else
ln -s "/media/$TARGET_USER" "$usb_link"
chown -h "$TARGET_USER:$TARGET_USER" "$usb_link"
fi
step "Installing udiskie user autostart"
install -d -o "$TARGET_USER" -g "$TARGET_USER" -m 0755 "$TARGET_HOME/.config/systemd/user"
cat > "$TARGET_HOME/.config/systemd/user/udiskie.service" <<'EOF'
[Unit]
Description=Automount removable media with udiskie
After=graphical-session-pre.target
[Service]
ExecStart=/usr/bin/udiskie --no-notify
Restart=on-failure
RestartSec=3
[Install]
WantedBy=default.target
EOF
chown "$TARGET_USER:$TARGET_USER" "$TARGET_HOME/.config/systemd/user/udiskie.service"
install -d -o "$TARGET_USER" -g "$TARGET_USER" -m 0755 "$TARGET_HOME/.config/systemd/user/default.target.wants"
ln -sfn ../udiskie.service "$TARGET_HOME/.config/systemd/user/default.target.wants/udiskie.service"
chown -h "$TARGET_USER:$TARGET_USER" "$TARGET_HOME/.config/systemd/user/default.target.wants/udiskie.service"
sudo -u "$TARGET_USER" XDG_RUNTIME_DIR="/run/user/$(id -u "$TARGET_USER")" systemctl --user daemon-reload 2>/dev/null || true
step "Configuring console display"
cat > /etc/default/console-setup <<'EOF'
ACTIVE_CONSOLES="/dev/tty[1-6]"
CHARMAP="UTF-8"
CODESET="Lat15"
FONTFACE="Terminus"
FONTSIZE="12x24"
VIDEOMODE=
EOF
setupcon || log "WARNING: setupcon could not apply the console font immediately; it should apply after reboot."
step "Setting hostname"
hostnamectl set-hostname writerdeck
if grep -qE '^[[:space:]]*127\.0\.1\.1[[:space:]]+' /etc/hosts; then
sed -i -E 's/^[[:space:]]*127\.0\.1\.1[[:space:]].*/127.0.1.1\twriterdeck/' /etc/hosts
else
printf '127.0.1.1\twriterdeck\n' >> /etc/hosts
fi
step "Configuring GRUB"
if [ -f /etc/default/grub ]; then
if grep -q '^GRUB_TIMEOUT_STYLE=' /etc/default/grub; then
sed -i 's/^GRUB_TIMEOUT_STYLE=.*/GRUB_TIMEOUT_STYLE=menu/' /etc/default/grub
else
printf '\nGRUB_TIMEOUT_STYLE=menu\n' >> /etc/default/grub
fi
if grep -q '^GRUB_TIMEOUT=' /etc/default/grub; then
sed -i 's/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=1/' /etc/default/grub
else
printf 'GRUB_TIMEOUT=1\n' >> /etc/default/grub
fi
update-grub
else
log "No /etc/default/grub found; skipping GRUB configuration."
fi
step "Verifying required commands"
required=(tmux wordgrinder nvim hx kak udiskie nmtui whiptail setupcon gpm writerdeck-launch writerdeck-update wdmenu)
missing=()
for command_name in "${required[@]}"; do
command -v "$command_name" >/dev/null 2>&1 || missing+=("$command_name")
done
if [ "${#missing[@]}" -gt 0 ]; then
die "Installation finished with missing commands: ${missing[*]}"
fi
step "Installation complete"
cat <<EOF
writerdeckOS CE 3.0 has been installed for '$TARGET_USER'.
Default editor: $(cat "$EDITOR_FILE")
Install log: $LOG_FILE
Restart to enter the writerdeck interface automatically.
Run 'wdmenu' from a shell to change the editor, appearance or network settings.
Run './uninstall.sh' from this project directory to remove writerdeckOS CE.
EOF
if [ -t 0 ]; then
read -r -p "Restart now? [y/N]: " answer
case "$answer" in
[Yy]*) systemctl reboot ;;
esac
fi