Files
tar1090/install.sh

185 lines
4.9 KiB
Bash
Executable File

#!/bin/bash
# avoid changes to this bash script affecting the running script
set -e
srcdir=/run/dump1090-fa
repo="https://github.com/wiedehopf/tar1090"
ipath=/usr/local/share/tar1090
lighttpd=no
nginx=no
command_package="unzip unzip/git git/perl perl/jq jq/7za p7zip-full/"
install=""
while read -d '/' CMD PKG
do
if ! command -v "$CMD" &>/dev/null
then
echo "command $CMD not found, will try to install package $PKG"
install="$PKG $install"
fi
done < <(echo "$command_package")
if [[ -n "$install" ]]
then
echo "Installing required packages: $packages"
apt-get update
if ! apt-get install -y $install
then
echo "Failed to install required packages: $install"
echo "Exiting ..."
exit 1
fi
hash -r
fi
if command -v lighttpd &>/dev/null
then
lighttpd=yes
fi
if command -v nginx &>/dev/null
then
nginx=yes
fi
mkdir -p $ipath
if [[ "$1" == "test" ]]
then
rm -r /tmp/tar1090-test 2>/dev/null || true
mkdir -p /tmp/tar1090-test
cp -r * /tmp/tar1090-test
cd /tmp/tar1090-test
elif git clone --depth 1 $repo $ipath/git 2>/dev/null || cd $ipath/git
then
cd $ipath/git
git checkout -f master
git fetch
git reset --hard origin/master
elif wget --timeout=30 -q -O /tmp/master.zip $repo/archive/master.zip && unzip -q -o master.zip
then
cd /tmp/tar1090-master
else
echo "Unable to download files, exiting! (Maybe try again?)"
exit 1
fi
if [[ -n $1 ]] && [ $1 != "test" ] ; then
srcdir=$1
elif ! [[ -d /run/dump1090-fa ]] ; then
if [[ -d /run/dump1090 ]]; then
srcdir=/run/dump1090
elif [[ -d /run/dump1090-mutability ]]; then
srcdir=/run/dump1090-mutability
elif [[ -d /run/readsb ]]; then
srcdir=/run/readsb
elif [[ -d /run/skyaware978 ]]; then
srcdir=/run/skyaware978
fi
fi
if [ -f /etc/default/tar1090_instances ]; then
instances=$(</etc/default/tar1090_instances)
else
instances="$srcdir tar1090"
fi
if ! diff tar1090.sh /usr/local/share/tar1090/tar1090.sh &>/dev/null; then
changed=yes
while read -r srcdir instance; do
if [[ "$instance" != "tar1090" ]]; then
service="tar1090-$instance"
else
service="tar1090"
fi
systemctl stop $service 2>/dev/null || true
done < <(echo "$instances")
cp tar1090.sh $ipath
fi
# copy over base files
cp default install.sh uninstall.sh 99-tar1090-webroot.conf LICENSE README.md \
95-tar1090-otherport.conf $ipath
while read -r srcdir instance
do
if [[ "$instance" != "tar1090" ]]; then
html_path="$ipath/html-$instance"
service="tar1090-$instance"
else
html_path="$ipath/html"
service="tar1090"
fi
# don't overwrite existing configuration
cp -n default /etc/default/$service
sed -i -e 's/skyview978/skyaware978/' /etc/default/$service
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?$service?g" -e "s?INSTANCE?$instance?g" -e "s?HTMLPATH?$html_path?g" 88-tar1090.conf
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?$service?g" -e "s?INSTANCE?$instance?g" -e "s?HTMLPATH?$html_path?g" nginx.conf
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?$service?g" tar1090.service
# keep some stuff around
if [ -f $html_path/defaults.js ]; then
cp $html_path/config.js /tmp/tar1090_config.js
fi
cp $html_path/colors.css /tmp/tar1090_colors.css/ 2>/dev/null || true
cp -r -T html $html_path
mv /tmp/tar1090_config.js $html_path/config.js 2>/dev/null || true
mv /tmp/tar1090_colors.css $html_path/colors.css 2>/dev/null || true
# bust cache for all css and js files
sed -i -e "s/__cache_version__/$(date +%s)/g" $html_path/index.html
cp nginx.conf $ipath/nginx-$service.conf
if [[ $lighttpd == yes ]] && ! diff 88-tar1090.conf /etc/lighttpd/conf-enabled/88-$service.conf &>/dev/null
then
changed_lighttpd=yes
cp 88-tar1090.conf /etc/lighttpd/conf-available/88-$service.conf
lighty-enable-mod $service >/dev/null || true
fi
if [[ $changed == yes ]] || ! diff tar1090.service /lib/systemd/system/$service.service &>/dev/null
then
cp tar1090.service /lib/systemd/system/$service.service
systemctl enable $service
echo
echo "Restarting $service ..."
systemctl restart $service
fi
if [[ $nginx == yes ]]; then
echo
echo "To configure nginx for tar1090, please add the following line in the server {} section:"
echo
echo "include /usr/local/share/tar1090/nginx-$service.conf;"
fi
# restore sed modified configuration files
mv 88-tar1090.conf.orig 88-tar1090.conf
mv nginx.conf.orig nginx.conf
mv tar1090.service.orig tar1090.service
echo --------------
echo "All done! Webinterface available at http://$(ip route | grep -m1 -o -P 'src \K[0-9,.]*')/$instance"
done < <(echo "$instances")
if [[ $changed_lighttpd == yes ]] && systemctl status lighttpd >/dev/null; then
if grep -q '^server.modules += ( "mod_setenv" )' /etc/lighttpd/conf-available/89-dump1090-fa.conf
then
sed -i -e 's/^server.modules += ( "mod_setenv" )/#server.modules += ( "mod_setenv" )/' $(find /etc/lighttpd/conf-available/* | grep -v dump1090-fa)
fi
echo "Restarting lighttpd ..."
systemctl restart lighttpd
fi