-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·257 lines (223 loc) · 7.92 KB
/
install.sh
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
#!/bin/bash
# Linux DAV Todo installation script for Nuitka builds
# This script installs the application built with Nuitka to the system
set -e # Exit on error
# Detect Linux distribution
detect_distribution() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
elif [ -f /etc/debian_version ]; then
echo "debian"
elif [ -f /etc/arch-release ]; then
echo "arch"
elif [ -f /etc/fedora-release ]; then
echo "fedora"
else
echo "unknown"
fi
}
# Get package manager and installation command
get_pkg_manager() {
local distro=$1
case $distro in
"debian"|"ubuntu"|"pop"|"mint")
echo "apt-get install -y"
;;
"arch"|"manjaro"|"endeavouros"|"cachyos")
echo "pacman -S --noconfirm"
;;
"fedora"|"rhel"|"centos")
echo "dnf install -y"
;;
*)
echo "unknown"
;;
esac
}
# Get runtime dependencies based on distribution
get_runtime_packages() {
local distro=$1
case $distro in
"debian"|"ubuntu"|"pop"|"mint")
echo "python3-gi python3-gi-cairo gir1.2-gtk-4.0 python3-keyring"
;;
"arch"|"manjaro"|"endeavouros"|"cachyos")
echo "python-gobject gtk4 python-keyring"
;;
"fedora"|"rhel"|"centos")
echo "python3-gobject gtk4 python3-keyring"
;;
*)
echo "unknown"
;;
esac
}
# Get installation paths based on distribution
get_install_paths() {
local distro=$1
case $distro in
"debian"|"ubuntu"|"pop"|"mint"|"fedora"|"rhel"|"centos")
echo "BIN_DIR=/usr/local/bin"
echo "ICON_DIR=/usr/share/icons/hicolor/scalable/apps"
echo "DESKTOP_DIR=/usr/share/applications"
echo "SYSTEMD_DIR=/etc/systemd/system"
;;
"arch"|"manjaro"|"endeavouros"|"cachyos")
echo "BIN_DIR=/usr/bin"
echo "ICON_DIR=/usr/share/icons/hicolor/scalable/apps"
echo "DESKTOP_DIR=/usr/share/applications"
echo "SYSTEMD_DIR=/usr/lib/systemd/system"
;;
*)
# Default paths
echo "BIN_DIR=/usr/local/bin"
echo "ICON_DIR=/usr/local/share/icons/linux-dav-todo"
echo "DESKTOP_DIR=/usr/local/share/applications"
echo "SYSTEMD_DIR=/etc/systemd/system"
;;
esac
}
# Install runtime dependencies
install_runtime_deps() {
local distro=$(detect_distribution)
local pkg_manager=$(get_pkg_manager "$distro")
local required_packages=$(get_runtime_packages "$distro")
if [ "$pkg_manager" = "unknown" ]; then
echo "Warning: Unsupported distribution. You may need to install these dependencies manually:"
echo "Required packages (Debian-style names):"
echo " python3-gi python3-gi-cairo gir1.2-gtk-4.0 python3-keyring"
return 1
fi
echo "Installing runtime dependencies for $distro..."
# Check if we're root, if not use sudo
if [ "$EUID" -ne 0 ]; then
if ! command -v sudo &> /dev/null; then
echo "Error: This script needs root privileges to install dependencies."
echo "Please run as root or install sudo."
exit 1
fi
SUDO="sudo"
else
SUDO=""
fi
# Update package lists for debian-based systems
if [ "$distro" = "debian" ] || [ "$distro" = "ubuntu" ] || [ "$distro" = "pop" ] || [ "$distro" = "mint" ]; then
$SUDO apt-get update
fi
# Install packages
$SUDO $pkg_manager $required_packages
echo " ✓ Runtime dependencies installed"
}
# Handle SELinux contexts if necessary
handle_selinux() {
if command -v semanage >/dev/null && command -v restorecon >/dev/null; then
echo "SELinux detected, setting up contexts..."
semanage fcontext -a -t bin_t "$BIN_DIR/linux-dav-todo" 2>/dev/null || true
restorecon -v "$BIN_DIR/linux-dav-todo" 2>/dev/null || true
echo " ✓ SELinux contexts applied"
fi
}
# Backup existing configuration
backup_config() {
local backup_dir="backup-$(date +%Y%m%d-%H%M%S)"
if [ -f "$DESKTOP_DIR/linux-dav-todo.desktop" ] || \
[ -f "$SYSTEMD_DIR/linux-dav-todo.service" ] || \
[ -f "$BIN_DIR/linux-dav-todo" ]; then
echo "Creating backup of existing installation..."
mkdir -p "$backup_dir"
[ -f "$DESKTOP_DIR/linux-dav-todo.desktop" ] && cp "$DESKTOP_DIR/linux-dav-todo.desktop" "$backup_dir/"
[ -f "$SYSTEMD_DIR/linux-dav-todo.service" ] && cp "$SYSTEMD_DIR/linux-dav-todo.service" "$backup_dir/"
[ -f "$BIN_DIR/linux-dav-todo" ] && cp "$BIN_DIR/linux-dav-todo" "$backup_dir/"
echo " ✓ Backup created in $backup_dir"
fi
}
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo ./install.sh)"
exit 1
fi
# Check for required files
if [ ! -d "assets" ] || [ ! -f "assets/logo.png" ]; then
echo "Error: assets directory or logo.png not found"
exit 1
fi
if [ ! -f "linux-dav-todo.desktop" ]; then
echo "Error: linux-dav-todo.desktop not found"
exit 1
fi
if [ ! -f "linux-dav-todo.service" ]; then
echo "Error: linux-dav-todo.service not found"
exit 1
fi
# Install runtime dependencies first
install_runtime_deps
# Detect distribution and set paths
DISTRO=$(detect_distribution)
echo "Detected distribution: $DISTRO"
eval "$(get_install_paths "$DISTRO")"
echo "Using installation paths:"
echo " Binary: $BIN_DIR"
echo " Icons: $ICON_DIR"
echo " Desktop: $DESKTOP_DIR"
echo " Systemd: $SYSTEMD_DIR"
# Create backup of existing installation
backup_config
# Create directories if they don't exist
mkdir -p "$BIN_DIR"
mkdir -p "$ICON_DIR"
mkdir -p "$DESKTOP_DIR"
mkdir -p "$SYSTEMD_DIR"
# Copy files
echo "Installing Linux DAV Todo..."
if [ -f "dist/main.bin" ]; then
cp dist/main.bin "$BIN_DIR/linux-dav-todo"
chmod +x "$BIN_DIR/linux-dav-todo"
echo " ✓ Binary installed to $BIN_DIR/linux-dav-todo"
else
echo " ✗ Binary not found. Please build with Nuitka first."
echo " Run: ./build.sh"
exit 1
fi
# Copy icon
cp assets/logo.png "$ICON_DIR/linux-dav-todo.png"
chmod 644 "$ICON_DIR/linux-dav-todo.png"
echo " ✓ Icon installed to $ICON_DIR/linux-dav-todo.png"
# Update desktop file paths based on distribution
if ! sed -i "s|Icon=.*|Icon=$ICON_DIR/linux-dav-todo.png|" linux-dav-todo.desktop; then
echo "Warning: Failed to update icon path in desktop file"
fi
if ! sed -i "s|Exec=.*|Exec=$BIN_DIR/linux-dav-todo|" linux-dav-todo.desktop; then
echo "Warning: Failed to update executable path in desktop file"
fi
# Copy desktop file
cp linux-dav-todo.desktop "$DESKTOP_DIR/linux-dav-todo.desktop"
chmod 644 "$DESKTOP_DIR/linux-dav-todo.desktop"
echo " ✓ Desktop entry installed to $DESKTOP_DIR/linux-dav-todo.desktop"
# Install systemd service
cp linux-dav-todo.service "$SYSTEMD_DIR/"
chmod 644 "$SYSTEMD_DIR/linux-dav-todo.service"
echo " ✓ Systemd service installed to $SYSTEMD_DIR/linux-dav-todo.service"
echo " To enable autostart for a user, run:"
echo " systemctl enable --user linux-dav-todo@\$USER"
# Update icon cache and desktop database based on distribution
if command -v gtk-update-icon-cache >/dev/null; then
gtk-update-icon-cache -f -t /usr/share/icons/hicolor || true
echo " ✓ Icon cache updated"
fi
if command -v update-desktop-database >/dev/null; then
update-desktop-database "$DESKTOP_DIR" || true
echo " ✓ Desktop database updated"
fi
# Handle SELinux if present
handle_selinux
# Reload systemd
systemctl daemon-reload
echo " ✓ Systemd configuration reloaded"
echo ""
echo "Installation complete! You can now:"
echo "1. Launch Linux DAV Todo from your application menu"
echo "2. Run 'linux-dav-todo' from the terminal"
echo "3. Enable autostart with: systemctl enable --user linux-dav-todo@\$USER"
echo ""
echo "Note: A backup of any existing installation was created (if applicable)"