-
Notifications
You must be signed in to change notification settings - Fork 1
/
scripLinux.sh
executable file
·73 lines (59 loc) · 1.79 KB
/
scripLinux.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
#!/bin/bash
# Function to detect package manager and install dependencies
install_dependencies() {
if command -v apt-get &> /dev/null ; then
INSTALL_CMD="sudo apt-get install -y"
elif command -v pacman &> /dev/null ; then
INSTALL_CMD="sudo pacman -S -y"
elif command -v dnf &> /dev/null ; then
INSTALL_CMD="sudo dnf install -y"
else
echo "Unsupported package manager. Exiting."
exit 1
fi
echo "Installing dependencies..."
$INSTALL_CMD dnsmasq libnss3-tools golang
}
# Install dependencies
install_dependencies
# Build the Go application
echo "Building the Go application..."
if [ ! -f "go.mod" ] || [ ! -f "go.sum" ]; then
go mod init test
if [ $? -ne 0 ]; then
echo "Error initializing the project. Exiting."
exit 1
fi
go mod tidy
if [ $? -ne 0 ]; then
echo "Error fetching dependencies. Exiting."
exit 1
fi
fi
go build -o DNSonChain main.go
if [ $? -ne 0 ]; then
echo "Error building the application. Exiting."
exit 1
fi
echo "Installation and build complete."
# Configure dnsmasq
echo "Configuring dnsmasq..."
echo "server=/chain/127.0.0.1#5354" | sudo tee /etc/dnsmasq.d/chain.conf
# Update /etc/resolv.conf
echo "Updating /etc/resolv.conf..."
echo "nameserver 127.0.0.1" | sudo tee -a /etc/resolv.conf
# Update NetworkManager.conf
echo "Updating NetworkManager.conf..."
sudo sed -i '/^\[main\]$/a dns=dnsmasq' /etc/NetworkManager/NetworkManager.conf
# Restart dnsmasq and NetworkManager
echo "Restarting dnsmasq..."
sudo systemctl restart dnsmasq
# Ask the user if they want to run the app
read -p "Do you want to run the app? (y/n) " answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
echo "Running the app..."
sudo ./DNSonChain
else
echo "Exiting."
exit 0
fi