Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
174 lines (142 loc) · 6.74 KB
/
Copy pathinstall.sh
File metadata and controls
174 lines (142 loc) · 6.74 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
#!/bin/bash
# DeskClock one-click installer
# Usage: curl -sSL https://raw.githubusercontent.com/frogswiper/deskclock/master/install.sh | bash
set -e
REPO="https://github.com/frogswiper/deskclock.git"
APP_DIR="$HOME/deskclock"
USER="$(whoami)"
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
info() { echo -e "${CYAN}==>${NC} $*"; }
ok() { echo -e "${GREEN} ✓${NC} $*"; }
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
die() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
echo ""
echo " DeskClock Installer"
echo " ==================="
echo ""
# ── Checks ────────────────────────────────────────────────────────────────────
[ "$(id -u)" -eq 0 ] && die "Run as your normal user, not root. The script will use sudo when needed."
command -v sudo >/dev/null || die "sudo is required"
command -v git >/dev/null || { info "Installing git..."; sudo apt-get install -y git; }
# ── Prompts ───────────────────────────────────────────────────────────────────
read -rp " City for weather [Oslo]: " INPUT_CITY
CITY="${INPUT_CITY:-Oslo}"
read -rp " Timezone [Europe/Oslo]: " INPUT_TZ
TIMEZONE="${INPUT_TZ:-Europe/Oslo}"
read -rp " OpenWeatherMap API key (leave blank to configure later): " API_KEY
read -rp " Units — metric (°C) or imperial (°F) [metric]: " INPUT_UNITS
UNITS="${INPUT_UNITS:-metric}"
[[ "$UNITS" != "metric" && "$UNITS" != "imperial" ]] && UNITS="metric"
echo ""
# ── System packages ───────────────────────────────────────────────────────────
info "Installing system packages..."
sudo apt-get update -qq
sudo apt-get install -y \
python3-pip \
fonts-ubuntu \
iw \
hostapd \
dnsmasq
ok "System packages installed"
# ── Python packages ───────────────────────────────────────────────────────────
info "Installing Python packages..."
pip3 install --quiet --break-system-packages pygame requests 2>/dev/null \
|| pip3 install --quiet pygame requests
ok "pygame and requests installed"
# ── Clone / update repo ───────────────────────────────────────────────────────
if [ -d "$APP_DIR/.git" ]; then
info "Updating existing repo at $APP_DIR..."
git -C "$APP_DIR" pull --ff-only
ok "Repo updated"
else
info "Cloning DeskClock to $APP_DIR..."
git clone "$REPO" "$APP_DIR"
ok "Repo cloned"
fi
chmod +x "$APP_DIR/hotspot.sh"
# ── Initial config ────────────────────────────────────────────────────────────
if [ ! -f "$APP_DIR/config.json" ]; then
info "Writing initial config.json..."
cat > "$APP_DIR/config.json" <<EOF
{
"city": "$CITY",
"timezone": "$TIMEZONE",
"api_key": "$API_KEY",
"units": "$UNITS",
"brightness": 100,
"clock_24h": false,
"night_mode": true,
"night_start": 23,
"night_end": 7,
"night_brightness": 15,
"theme": "dark",
"hotspot_ssid": "DeskClock",
"hotspot_password": "",
"hotspot_iface": "auto"
}
EOF
ok "config.json created"
else
warn "config.json already exists — skipping (edit manually if needed)"
fi
# Set timezone
if [ -n "$TIMEZONE" ]; then
info "Setting timezone to $TIMEZONE..."
sudo timedatectl set-timezone "$TIMEZONE" 2>/dev/null && ok "Timezone set" || warn "Could not set timezone (set manually with: sudo timedatectl set-timezone $TIMEZONE)"
fi
# ── Sudoers ───────────────────────────────────────────────────────────────────
info "Configuring passwordless sudo for WiFi/timezone/hotspot..."
SUDOERS_FILE="/etc/sudoers.d/deskclock"
sudo tee "$SUDOERS_FILE" > /dev/null <<EOF
$USER ALL=(ALL) NOPASSWD: /usr/sbin/wpa_cli, /usr/bin/timedatectl, $APP_DIR/hotspot.sh
EOF
sudo chmod 440 "$SUDOERS_FILE"
sudo visudo -c -f "$SUDOERS_FILE" > /dev/null
ok "Sudoers configured"
# ── Groups ────────────────────────────────────────────────────────────────────
info "Adding $USER to video and input groups (framebuffer/touchscreen access)..."
sudo usermod -aG video,input "$USER"
ok "Groups updated (takes effect on next login)"
# ── TTY1 autologin ────────────────────────────────────────────────────────────
info "Configuring TTY1 autologin..."
GETTY_DIR="/etc/systemd/system/getty@tty1.service.d"
sudo mkdir -p "$GETTY_DIR"
sudo tee "$GETTY_DIR/autologin.conf" > /dev/null <<EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
EOF
sudo systemctl daemon-reload
ok "TTY1 autologin configured"
# ── ~/.profile autostart ──────────────────────────────────────────────────────
PROFILE_BLOCK='
# DeskClock autostart
if [ "$(tty)" = "/dev/tty1" ]; then
export SDL_VIDEODRIVER=kmsdrm
export SDL_AUDIODRIVER=dummy
cd ~/deskclock
exec python3 main.py
fi'
if grep -q "SDL_VIDEODRIVER=kmsdrm" "$HOME/.profile" 2>/dev/null; then
warn "~/.profile already contains DeskClock autostart — skipping"
else
info "Adding autostart to ~/.profile..."
echo "$PROFILE_BLOCK" >> "$HOME/.profile"
ok "~/.profile updated"
fi
# ── Done ──────────────────────────────────────────────────────────────────────
echo ""
echo -e "${GREEN} Installation complete!${NC}"
echo ""
if [ -z "$API_KEY" ]; then
echo -e " ${YELLOW}Next step:${NC} Set your OpenWeatherMap API key in $APP_DIR/config.json"
echo " (or via the Settings screen after first boot)"
echo ""
fi
echo " Reboot to start DeskClock automatically on the display:"
echo " sudo reboot"
echo ""
echo " Or test without rebooting:"
echo " export SDL_VIDEODRIVER=kmsdrm SDL_AUDIODRIVER=dummy"
echo " cd $APP_DIR && python3 main.py"
echo ""