-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdnsmasq_install.sh
executable file
·105 lines (92 loc) · 3.26 KB
/
dnsmasq_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
#!/bin/sh
#Version 0.42
# With ntpd support
. /etc/rc.subr
. /etc/util.subr
. /etc/configxml.subr
exerr () { echo -e "$*" >&2 ; exit 1; }
#
STAT=$(procstat -f $$ | grep -E "/"$(basename $0)"$")
FULL_PATH=$(echo $STAT | sed -r s/'^([^\/]+)\/'/'\/'/1 2>/dev/null)
START_FOLDER=$(dirname $FULL_PATH | sed 's|/dnsmasq_install.sh||')
# Store the script's current location in a file
echo $START_FOLDER > /tmp/dnsmasqinstaller
#Store user's inputs
# This first checks to see that the user has supplied an argument
if [ ! -z $1 ]; then
# The first argument will be the path that the user wants to be the root folder.
# If this directory does not exist, it is created
DMAS_ROOT=$1
# This checks if the supplied argument is a directory. If it is not
# then we will try to create it
if [ ! -d $DMAS_ROOT ]; then
echo "Attempting to create a new destination directory....."
mkdir -p $DMAS_ROOT || exerr "ERROR: Could not create directory!"
fi
else
# We are here because the user did not specify an alternate location. Thus, we should use the
# current directory as the root.
DMAS_ROOT=$START_FOLDER
fi
# create working folder
mkdir -p $START_FOLDER/temporary || exerr "ERROR: Could not create install directory!"
echo $DMAS_ROOT > /tmp/dnsmasq.tmp
cd $START_FOLDER/temporary || exerr "ERROR: Could not access install directory!"
# Fetch the master branch as a zip file
echo "Retrieving the most recent version of dnsmasq"
fetch https://github.com/alexey1234/nas4free-dnsmasq/archive/master.zip || exerr "ERROR: Could not write to install directory!"
# Extract the files we want, stripping the leading directory, and exclude
# the git nonsense
echo "Unpacking the tarball..."
tar -xvf master.zip --exclude='.git*' --strip-components 1
# Get rid of the tarball
rm master.zip
# Obtain binary from FreeBSD package
echo "Fetch package from FreeBSD..."
pkg fetch -y -o tmp dnsmasq
cd tmp/All
tar -xzf dnsmasq*.txz
cd ../..
rm -f sbin/dmsmasq_64
rm -f sbin/dmsmasq_86
cp tmp/All/usr/local/sbin/dnsmasq sbin/dnsmasq
rm -fr tmp
# Check, if use fresh install or upgrade
_rootfolder=`configxml_get "//dnsmasq/rootfolder"`
if [ ! -z $_rootfolder ]; then
# Update current config
DMAS_ROOT=$_rootfolder
/etc/rc.d/dnsmasq onestop
rm -f /usr/local/sbin/dnsmasq
rm -f /etc/rc.d/dnsmasq
cp -f -R $START_FOLDER/temporary/* $DMAS_ROOT/
ln -s $DMAS_ROOT/sbin/dnsmasq /usr/local/sbin/dnsmasq
ln -s $DMAS_ROOT/sbin/dnsmasq.d /etc/rc.d/dnsmasq
else
echo "Look like fresh install"
cp -f -R $START_FOLDER/temporary/* $DMAS_ROOT/
#create webroot files
mkdir -p /usr/local/www/ext
ln -s $DMAS_ROOT/dnsmasq /usr/local/www/ext/dnsmasq
cd /usr/local/www
# For each of the php files in the extensions folder
for file in /usr/local/www/ext/dnsmasq/*.php
do
# Check if the link is already there
if [ -e "${file##*/}" ]; then
rm "${file##*/}"
fi
# Create link
ln -s "$file" "${file##*/}"
done
fi
chmod 755 $DMAS_ROOT/sbin/*
echo "Congratulations! dnsmasq was updated/installed . Navigate to config web page and push Save "
# Clean after work
cd $START_FOLDER
# Get rid of staged updates
rm -Rf temporary/*
rmdir temporary
rm /tmp/dnsmasqinstaller
currentdate=`date -j +"%h %d %H:%M:%S"`
echo "$currentdate installer[0001]: install or upgrade action successfull" >> /var/log/dnsmasq.log