MeteOnline : Construire Configurer un serveur Météo ...

Script Dietpi

 

install_wview_dietpi.sh

 

#!/bin/bash
 
# installWview.sh
#
# Script to install WView weather station software on new Rapsberry Pi.
#  This script is not meant to be used on an already configured system.
#  This script could overwrite or break an existing confgiuration.
#
#    By NetCodger 3/27/2015
#
 
 
 
# Make sure that we are root
 if [ $(id -u) != 0 ]; then
     echo "Vous avez un droit insuffisant pour exécuter ce script."
     echo
     echo "Re-exécuter le script avec sudo install_wview.sh"
     read -n 1 -p "Appuyez sur n'importe quelle touche pour sortir"
     exit -1
fi
 
 
 
# Are you sure?
echo "Ce script sert à installer WView sur une nouvelle installation Raspberry Pi."
echo "L'installation sur un système déjà configuré pourrait détruire toute modification précédente."
 
read -p "Etes vous sur de vouloir continuer? (y/n)" -n 1 -r
echo    # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    exit 1
fi
 
 
# Update /etc/apt/sources.list to include download location for Wview software, if it does not already exist.
if ! grep -Fxq "deb http://www.wviewweather.com/apt/wheezy wheezy main" /etc/apt/sources.list; then
     echo "deb http://www.wviewweather.com/apt/wheezy wheezy main" >> /etc/apt/sources.list
     echo "deb-src http://www.wviewweather.com/apt/wheezy wheezy main" >> /etc/apt/sources.list
     echo "deb http://archive.raspbian.org/raspbian wheezy main contrib non-free" >> /etc/apt/sources.list
     echo "deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free" >> /etc/apt/sources.list
fi
 
 
# Update installed Raspbian(Debian) software.
wget https://archive.raspbian.org/raspbian.public.key -O - | sudo apt-key add -
apt-get update
apt-get --assume-yes --force-yes upgrade
 
 
# Update Pi firmware.
# rpi-update
 
 
# Prompt user to set timezone as necessary.
dpkg-reconfigure tzdata
 
 
# Install web server and PHP
apt-get --no-install-recommends --assume-yes --force-yes --fix-missing install lighttpd
 
apt-get --no-install-recommends --assume-yes --force-yes --fix-missing install php5 php5-sqlite php5-cgi
 
 
# Configure lighttpd to enable PHP
if ! grep -Fxq '.php" => "/usr/bin/php5-cgi' /etc/lighttpd/conf-enabled/10-cgi-php.conf; then
     echo 'server.modules += ("mod_cgi")' >> /etc/lighttpd/conf-enabled/10-cgi-php.conf
     echo ' cgi.assign = (".php" => "/usr/bin/php5-cgi")' >> /etc/lighttpd/conf-enabled/10-cgi-php.conf
fi
 
lighttpd-enable-mod fastcgi fastcgi-php
 
 
# Install WView weather station software.(But without installing Apache2.)
apt-get --no-install-recommends --assume-yes --force-yes --fix-missing install wview apache2-
 
 
# Create simlinks manually, since WView only does it for Apache2.
cd /var/www/
ln -s /var/lib/wview/img weather
ln -s /var/lib/wviewmgmt wviewmgmt
 
cd /var/lib/wviewmgmt
ln -s system_status.php index.php
 
 
# Adjust fille permissions.
# Make wview config files writable for http user.
chmod 777 /etc/wview
chmod 666 /etc/wview/wview-conf.sdb
chmod 666 /etc/wview/wview-binary
 
# Create a ramdisk for Hi Low data.
# Saves SD card write cycles and
# speeds up Hi Low regeneration.
if ! grep -Fxq "tmpfs           /wviewtmp          tmpfs   defaults,mode=0755,size=30m 0       0" /etc/fstab; then
     mkdir /wviewtmp
     echo "tmpfs           /wviewtmp          tmpfs   defaults,mode=0755,size=30m 0       0" >> /etc/fstab
     mount -a
fi
 
 
# Create persistent data store. Needed due to ramdisk.
mv /var/lib/wview/archive /var/lib/wview/archive-persistent
mv /var/lib/wview/img /var/lib/wview/img-persistent
 
 
# Link database files so that WView can find them.
if [ ! -d /var/lib/wview/archive ]; then
     mkdir /var/lib/wview/archive
      
     cat > /var/lib/wview/archive/README-IMPORTANT << 'EOT1'
      Due to the use of a ramdisk for the /wviewtmp directory
      this directory should contain the following soft links.
      
      ln -s /var/lib/wview/archive-persistent/wview-archive.sdb /var/lib/wview/archive/wview-archive.sdb
      ln -s /var/lib/wview/archive-persistent/wview-archive.sql /var/lib/wview/archive/wview-archive.sql
      ln -s /var/lib/wview/archive-persistent/wview-history.sdb /var/lib/wview/archive/wview-history.sdb
      ln -s /var/lib/wview/archive-persistent/wview-noaa.sdb /var/lib/wview/archive/wview-noaa.sdb
      ln -s /wviewtmp/wview-hilow.sdb /var/lib/wview/archive/wview-hilow.sdb
 
EOT1
 
     ln -s /var/lib/wview/archive-persistent/wview-archive.sdb /var/lib/wview/archive/wview-archive.sdb
     ln -s /var/lib/wview/archive-persistent/wview-archive.sql /var/lib/wview/archive/wview-archive.sql
     ln -s /var/lib/wview/archive-persistent/wview-history.sdb /var/lib/wview/archive/wview-history.sdb
     ln -s /var/lib/wview/archive-persistent/wview-noaa.sdb /var/lib/wview/archive/wview-noaa.sdb
     ln -s /wviewtmp/wview-hilow.sdb /var/lib/wview/archive/wview-hilow.sdb
      
     ln -s /wviewtmp/img /var/lib/wview/img
fi
 
 
 
# Create a service script that copies wview-hilow.sdb on startup or shutdown.
cat > /etc/init.d/tmpfsToPersistent << 'EOT2'
#! /bin/bash
# /etc/init.d/tmpfsToPersistent
 
### BEGIN INIT INFO
# Provides:          tmpfsToPersistent
# Required-Start:    $local_fs $network $time $syslog ntp
# Required-Stop:     $local_fs $network $time $syslog ntp
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Script to save data at shutdown.
# Description:       Copies wview database from persistent to tmpfs at start and vice versa at shutdown.
### END INIT INFO
 
 
case "$1" in
  start)
    echo "Starting copy /var/lib/wview/archive-persistent/wview-hilow.sdb to /wviewtmp/wview-hilow.sdb a tmpfs location."
    if mount | grep "tmpfs on /wviewtmp" > /dev/null; then
       cp -a /var/lib/wview/archive-persistent/wview-hilow.sdb /wviewtmp/
       cp -ar /var/lib/wview/img-persistent/ /wviewtmp/img/
    else
       echo "/wview not mounted on tmpfs"
    fi
    ;;
  stop)
    echo "Stopping copying /wviewtmp/wview-hilow.sdb to persistent storage"
    cp -a /wviewtmp/wview-hilow.sdb /var/lib/wview/archive-persistent/
    cp -ar /wviewtmp/img/* /var/lib/wview/img-persistent/
    ;;
  *)
    echo "Usage: /etc/init.d/tmpfsToPersistent {start|stop}"
    exit 1
    ;;
esac
 
exit 0  
 
EOT2
 
chmod 755 /etc/init.d/tmpfsToPersistent
 
update-rc.d tmpfsToPersistent defaults 10 50
 
 
# Setup automatic WView service start/stop
sed -i 's#$local_fs $network $time $syslog#$local_fs $network $time $syslog tmpfsToPersistent#' /etc/init.d/wview
 
update-rc.d wview defaults 90 10
 
# Reboot and begin configuration of WView.
echo
echo "----------------------------------"
echo "Redémarrez Raspberry Pi et commencez à utiliser Wview?"
echo "Voir le manuel WView sur wviewconfig."
echo
# echo "Choose NO if you plan to run the RestoreWview script to import prior data."
echo
read -p "Appuyez sur y pour redémarrer et quitter" -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
    reboot
fi

 

.

Infos

Script utilisé pour installer Dietpi sur le Raspberry