-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·45 lines (37 loc) · 1.41 KB
/
install.sh
File metadata and controls
executable file
·45 lines (37 loc) · 1.41 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
#!/bin/sh
# 1. Detect the actual user login (because sudo changes $USER to root)
if [ "$SUDO_USER" ]; then
REAL_USER="$SUDO_USER"
# Get user home directory reliably
USER_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6)
else
echo "This script should be run with sudo."
exit 1
fi
# Move hBlock scripts and reference files to user directories.
CWD=$(pwd)
cp "$CWD/hblock" "$USER_HOME/.local/bin/"
cp "$CWD/block-keywords" "$USER_HOME/.local/bin/"
cp "$CWD/hblock-direct" "$USER_HOME/.local/bin/"
# Try to create hBlock directory.
# Don't worry if it already exists.
sudo mkdir -p /etc/hBlock
# Move hBlock scripts and reference files to root directories.
# sudo cp $CWD/hblock /usr/local/bin/
sudo cp "$CWD/block-keywords" /etc/hBlock/
# Make all hBlock scripts executable.
chmod +x "$USER_HOME/.local/bin/hblock"
# sudo chmod +x /usr/local/bin/hblock
chmod +x "$USER_HOME/.local/bin/hblock-direct"
# Try to fix python path.
# Don't worry if it's already linked.
sudo ln -sf /usr/bin/python3 /usr/bin/python
# Run initial setup routine.
"$USER_HOME/.local/bin/hblock" setup
# Add refresh script to crontab to prevent manual editing of hosts.
if ! sudo crontab -u root -l 2>/dev/null | grep -q 'hblock-direct'; then
(sudo crontab -u root -l 2>/dev/null; echo "* * * * * /usr/local/bin/hblock-direct") | sudo crontab -u root -
echo "Crontab updated."
else
echo "Crontab already contains hblock-direct."
fi