-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·95 lines (89 loc) · 3.43 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
#!/bin/sh
#
exerr () { echo -e "$*" >&2 ; exit 1; }
. /etc/rc.subr
. /etc/configxml.subr
. /etc/util.subr
MYPATH=$1
name='minidlna'
minidlna_uid=${minidlna_uid-"dlna"}
STARTDIR=`pwd`
REVISION=`cat /etc/prd.revision`
INSTALLED=`/usr/local/bin/xml sel -t -i "count(//minidlna) > 0" -o "1" -b /conf/config.xml`
# This first checks to see that the user has supplied an argument
if [ "${INSTALLED}""${INSTALLED}" != "${INSTALLED}" ]; then
MINIDLNA_HOME=`configxml_get "//${name}/homefolder"`
else
if [ ! -z ${MYPATH} ]; 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
MINIDLNA_HOME=${MYPATH}
# This checks if the supplied argument is a directory. If it is not
# then we will try to create it
if [ ! -d ${MINIDLNA_HOME} ]; then
echo "Attempting to create a new destination directory....."
mkdir -p ${MINIDLNA_HOME} || 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.
MINIDLNA_HOME=${STARTDIR}
echo "${STARTDIR}"
fi
fi
# Make and move into the install staging folder
mkdir -p ${STARTDIR}/install_stage || exerr "ERROR: Could not create staging directory!"
cd ${STARTDIR}/install_stage || exerr "ERROR: Could not access staging directory!"
# Fetch the master branch as a zip file
echo "Retrieving the most recent stable version of "${name}
fetch https://github.com/alexey1234/minidlna-nas4free/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 -xf master.zip --exclude='.git*' --strip-components 1
echo "Done!"
rm master.zip
# Copy downloaded version to the install destination
rsync -r ${STARTDIR}/install_stage/* ${MINIDLNA_HOME}/
echo "Installing..."
# Create the symlinks/schema. We can't use thebrig_start since
# there is nothing for the brig in the config XML
mkdir -p /usr/local/www/ext/minidlna
cp -f ${MINIDLNA_HOME}/ext/minidlna/menu.inc /usr/local/www/ext/minidlna/menu.inc
if [ ! -h "/etc/rc.d/minidlna" ]; then
ln -s ${MINIDLNA_HOME}/ext/minidlna.sh /etc/rc.d/minidlna
fi
if [ ! -h "/usr/local/www/ext/minidlna/function.php" ]; then
ln -s ${MINIDLNA_HOME}/ext/minidlna/function.php /usr/local/www/ext/minidlna/function.php
fi
if [ ! -h "/usr/local/www/status_scan.png" ]; then
ln -s ${MINIDLNA_HOME}/ext/minidlna/status_scan.png /usr/local/www/status_scan.png
fi
cd /usr/local/www
# For each of the php files in the extensions folder
for file in ${MINIDLNA_HOME}/ext/minidlna/exten*.php
do
# Create link
if [ ! -h ${file##*/} ]; then
ln -s "$file" "${file##*/}"
fi
done
for file in ${MINIDLNA_HOME}/ext/minidlna/*cron*.php
do
# Create link
if [ ! -h ${file##*/} ]; then
ln -s "$file" "${file##*/}"
fi
done
# Store the install destination into the /tmp/minidlna.install in case updates
if [ "${INSTALLED}""${INSTALLED}" == "${INSTALLED}" ]; then
echo ${MINIDLNA_HOME} > /tmp/minidlna.install
mkdir ${MINIDLNA_HOME}/db{{
echo "Congratulations! Extension was installed. Navigate to rudimentary config tab and push Save."
else
echo "Congratulations! Extension was upgraded."
fi
chown ${minidlna_uid}:${minidlna_uid} ${MINIDLNA_HOME}/db
chmod 755 ${MINIDLNA_HOME}/db
# Get rid of staged updates & cleanup
rm -rf $STARTDIR/install_stage