User Tools

Site Tools


public:scripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
public:scripts [2014/08/06 09:09] – [Arduino ISP] Roland Hansmannpublic:scripts [2018/02/06 11:10] (current) – [accounts.sh] Roland Hansmann
Line 1: Line 1:
-====== Coding ======+====== Scripts ======
 <note warning> <note warning>
 **<fs larger>These scripts come with no warranty. Use at your own risk</fs>** **<fs larger>These scripts come with no warranty. Use at your own risk</fs>**
Line 46: Line 46:
                 <?$handler = fopen($target_path,"r");                 <?$handler = fopen($target_path,"r");
                 $file = fread($handler,filesize($target_path));                 $file = fread($handler,filesize($target_path));
-                preg_match_all('/(<A HREF=\")(.*)(\" ADD_DATE)/Ui',$file,&$urls);+                preg_match_all('/(<A HREF=\")(.*)(\" ADD_DATE)/Ui',$file,$urls);
                 $urls = $urls[2];                 $urls = $urls[2];
                 $rowclass = 0;                 $rowclass = 0;
Line 192: Line 192:
  
 ===== BaSH ===== ===== BaSH =====
 +==== update_dokuwiki.sh ====
 +This script updates dokuwiki from tgz file on your document root. The updating file must be named dokuwiki*.tgz
 +<file bash update_dokuwiki.sh>
 +#!/bin/bash
 +set -e
 +
 +# Set your install dir
 +INSTALLDIR=/var/www
 +
 +[[ `whoami` != "root" ]] && { echo "Must be root"; exit 2; }
 +[[ `pwd` != "$INSTALLDIR" ]] && { echo "You must be in $INSTALLDIR instead in `pwd`"; exit 2; }
 +
 +DOKUFILE=`ls $INSTALLDIR/dokuwiki*.tgz  |awk -F/ '{print $NF}'`
 +[[ -z $DOKUFILE ]] && { echo "No TAR file found matching dokuwiki*.tgz"; exit 2; }
 +
 +cd $INSTALLDIR
 +
 +echo "Removing old backup dokuwiki.old"
 +rm -rf dokuwiki.old
 +
 +echo "Backup current Dokuwiki to dokuwiki.old"
 +mv dokuwiki dokuwiki.old
 +
 +echo "Extracting new TAR"
 +tar -xzf $DOKUFILE
 +
 +echo "Rename extracted directory to dokuwiki if not yet"
 +mv `find . -type d -name "dokuwiki-*"` dokuwiki
 +
 +echo "Remove .dist files in the new installation"
 +find dokuwiki -name *.dist -exec rm -rf {} \;
 +
 +echo "Get local configs and acl.auth.php from previous installation"
 +find dokuwiki.old/conf -name "*local*" -exec cp -p {} dokuwiki/conf \;
 +cp -p dokuwiki.old/conf/acl.auth.php dokuwiki/conf
 +
 +echo "Get custom smileys from previous installation"
 +for i in `awk '{print $NF}' dokuwiki.old/conf/smileys.local.conf`; do
 +        printf " $i"
 +        cp dokuwiki.old/lib/images/smileys/$i dokuwiki/lib/images/smileys
 +done
 +echo ""
 +
 +echo "Rsync data from previous installation"
 +rsync -a --delete dokuwiki.old/data dokuwiki
 +
 +echo "Clear update messages"
 +echo "" > dokuwiki/data/cache/messages.txt
 +
 +echo "Copy active template from previous installation"
 +TPL=`grep template dokuwiki.old/conf/local.php |cut -f4 -d\'`
 +cp -pr dokuwiki.old/lib/tpl/$TPL dokuwiki/lib/tpl
 +
 +echo "Copy custom installed plugins"
 +for i in `ls dokuwiki.old/lib/plugins/`; do
 +        if [[ ! `ls dokuwiki/lib/plugins/$i 2>/dev/null` ]]; then
 +                printf " $i"
 +                cp -pr dokuwiki.old/lib/plugins/$i dokuwiki/lib/plugins
 +        fi
 +done
 +echo ""
 +
 +echo "Fixing permissions"
 +chown -R www-data dokuwiki/data dokuwiki/lib/plugins
 +chown www-data dokuwiki/conf dokuwiki/conf/local.php dokuwiki/conf/acl.auth.php
 +
 +/etc/init.d/apache2 reload
 +</file>
 ==== ipcheck.sh ==== ==== ipcheck.sh ====
 This script is executed every 30 minutes by cron from root. It checks if the public IP has changed and sends an email with the notification to dislist the new IP from Spamhaus Blacklist. This script is executed every 30 minutes by cron from root. It checks if the public IP has changed and sends an email with the notification to dislist the new IP from Spamhaus Blacklist.
Line 756: Line 824:
 TIMESTOP=`date +%s` TIMESTOP=`date +%s`
 printf "\n++++++++++++++++++++++++++ Duration `expr $TIMESTOP - $TIMESTART`sec +++++++++++++++++++++++++++" >>$TMPFILE printf "\n++++++++++++++++++++++++++ Duration `expr $TIMESTOP - $TIMESTART`sec +++++++++++++++++++++++++++" >>$TMPFILE
 +f_sendmail
 +</file>
 +==== gdrive_sync.sh ====
 +<file bash gdrive_sync.sh>
 +#!/bin/bash
 +#
 +# SYNCRONISATION SCRIPT TO GOOGLE DRIVE
 +#
 +# Usage: gdrive_sync.sh [-n]
 +#
 +# Fri Aug 22 14:21:56 CEST 2014
 +
 +### Config
 +RSYNCPARAMS="-aHvh --delete"
 +TMPFILE="/tmp/gdrive_sync.sh.tmp"               # Complete path with filename for mail content
 +EMAIL="hanr"            # Address where content or alert shoult be sent, semicolon sep.
 +FROM="gdrive-sync"
 +GDFSTOOL=/usr/local/bin/gdfstool
 +CREDFILE=/var/cache/gdfs/credcache
 +SRCFS="/mybook"                         
 +SOURCE="$SRCFS/backup"
 +MNTPT="/mnt"
 +DEST="$MNTPT/backup/`hostname`"
 +TIMESTART=`date +%s`
 +DRYRUN=
 +
 +### Functions
 +f_sendmail() {
 +        if [ "$DRYRUN" ]; then
 +                cat $TMPFILE
 +        else
 +                cat $TMPFILE |mailx -a "From:$FROM" -s "GDrive Syncronization" $EMAIL  # Send mail with content of file
 +        fi
 +        exit 0
 +}
 +f_checkfs() {
 +        if [[ -z `mount |grep "$1 "` ]]; then
 +                echo "!!! Skipped GDrive Syncronization!! $1 not mounted" >>$TMPFILE
 +                f_sendmail
 +        fi
 +}
 +### SCRIPT
 +[ "`whoami`" != "root" ] && { echo "Must run as root"; exit 2; }
 +
 +echo "++++++++++++++++++++++ GDrive sync start at `date +"%H:%M:%S"` +++++++++++++++++++++++" >$TMPFILE
 +
 +if [ "$1" == "-n" ]; then
 +        RSYNCPARAMS="$RSYNCPARAMS -n"; DRYRUN=1
 +        echo "RUNNING IN DRY MODE"
 +fi
 +
 +
 +
 +# Check if relevent FS are mounted and dirs exist
 +[ -x $GDFSTOOL ] || { echo "$GDFSTOOL not found or executable"; exit 2; }
 +[ -r $CREDFILE ] || { echo "$CREDFILE not found or readable"; exit 2; }
 +$GDFSTOOL mount $CREDFILE $MNTPT
 +f_checkfs $MNTPT
 +f_checkfs $SRCFS
 +
 +[ -d $DEST ] || mkdir -p $DEST
 +
 +# Do the sync
 +rsync $RSYNCPARAMS $SOURCE $DEST >> $TMPFILE
 +printf "\n\n++++++++++++++++++++++ GDrive sync end at `date +"%H:%M:%S"` +++++++++++++++++++++++" >>$TMPFILE
 +TIMESTOP=`date +%s`
 +printf "\n++++++++++++++++++++++++++ Duration `expr $TIMESTOP - $TIMESTART`sec +++++++++++++++++++++++++++" >>$TMPFILE
 +
 +umount $MNTPT
 f_sendmail f_sendmail
 </file> </file>
Line 770: Line 907:
 #                                 added rescanning if SSID input is blank #                                 added rescanning if SSID input is blank
 # Thu Sep 18 10:30:15 CEST 2008 / added function to scan available interface # Thu Sep 18 10:30:15 CEST 2008 / added function to scan available interface
-#   and wpa_supplicant binary check+                                and wpa_supplicant binary check
 # Wed Aug 19 11:37:54 CEST 2009 / more optimized # Wed Aug 19 11:37:54 CEST 2009 / more optimized
 +# Mon Oct  3 14:53:59 CEST 2016 / dialog'ed
 # #
 # #
 IFACE=$1 IFACE=$1
 +umask 0002 # secure tmp files
 +pkill wpa_supplicant # kill existing wpa processes
 +
 +DIALOGBIN=`which dialog`
 +if [[ -z $DIALOGBIN ]] ; then
 +        DIALOG=
 +else
 +        #DIALOGBIN="$DIALOGBIN --backtitle \"Wireless connection wizard\""
 +        DIALOG=1
 +        TMP=/tmp/tmp.$$
 +        trap "rm -rf $TMP" INT TERM EXIT
 +fi
  
 # Check if Parameter is a valid Interface to use. If not, the Script proposes # Check if Parameter is a valid Interface to use. If not, the Script proposes
Line 780: Line 930:
 ifconfig $IFACE > /dev/null ifconfig $IFACE > /dev/null
 if [ "$?" -eq "1" ] ; then if [ "$?" -eq "1" ] ; then
- FINDIFACE=`iwconfig |grep IEEE |awk '{print $1}'+        FINDIFACE=`iwconfig |grep IEEE |awk '{print $1}'
- clear +        if [[ $DIALOG ]]; then 
- echo "Interface $1 not found..." +                $DIALOGBIN --title "Interface $1 not found" --msgbox "But found $FINDIFACE. \nContinuing with this interface" 8 50 
- echo "...but found $FINDIFACE. Press [ENTER] to continue with this Interface." +        else 
- read +                clear 
- IFACE=$FINDIFACE+                echo "Interface $1 not found..." 
 +                echo "...but found $FINDIFACE. Press [ENTER] to continue with this Interface." 
 +                read 
 +        fi 
 +        IFACE=$FINDIFACE
 fi fi
  
 # Output a Usage if no Parameter is given # Output a Usage if no Parameter is given
 if [ "$1" == "" ] ; then if [ "$1" == "" ] ; then
- echo "Usage: $0 interface" +        echo "Usage: $0 interface" 
- exit 1+        exit 1
 fi fi
 clear clear
 +ifconfig $IFACE up
  
-echo "Scanning for Access Points..." +if [[ $DIALOG ]]; then 
-echo "" +        $DIALOGBIN --infobox "Scanning for Access Points on $IFACE ..." 3 50 
-iwlist $IFACE scanning |grep ESSID +        SSIDLIST=`iwlist $IFACE scanning |grep ESSID |cut -f2 -d\" |grep -v "\\x00"`  
-echo "" +        SSIDLISTSIZE=`echo $SSIDLIST |wc -w` 
-echo "Enter ESSID you want to connect or leave blank to rescan and press [ENTER]:" +        $DIALOGBIN  --title "Enter ESSID you want to connect or leave blank to rescan" --inputbox "$SSIDLIST" `expr 10 + $SSIDLISTSIZE` 80 2>$TMP 
-read SSID+        SSID=`cat $TMP` 
 +else 
 +        echo "Scanning for Access Points in $IFACE ..." 
 +        echo "" 
 +        iwlist $IFACE scanning |grep ESSID 
 +        echo "" 
 +        echo "Enter ESSID you want to connect or leave blank to rescan and press [ENTER]:" 
 +        read SSID 
 +fi
  
 # If the Input is empty, the Script loops over the scan and asks each time to enter # If the Input is empty, the Script loops over the scan and asks each time to enter
 # a SSID to continue with the connection # a SSID to continue with the connection
-while [ "$SSID" == "" ]; do +while [[ -z $SSID ]]; do 
- clear +        clear 
- echo "Rescanning for Access Points..." +        if [[ $DIALOG ]]; then 
- iwlist $IFACE scanning |grep ESSID +                $DIALOGBIN --infobox "Rescanning for Access Points on $IFACE ..." 3 50 
- echo "Enter ESSID you want to connect or leave blank to rescan and press [ENTER]:" +                SSIDLIST=`iwlist $IFACE scanning |grep ESSID |cut -f2 -d\" |grep -v "\\x00"
- echo "" +                SSIDLISTSIZE=`echo $SSIDLIST |wc -w` 
- read SSID+                $DIALOGBIN --title "Enter ESSID you want to connect or leave blank to rescan--inputbox "$SSIDLIST" `expr 10 + $SSIDLISTSIZE` 80 2>$TMP 
 +                SSID=`cat $TMP` 
 +        else 
 +                echo "Rescanning for Access Points..." 
 +                iwlist $IFACE scanning |grep ESSID 
 +                echo "Enter ESSID you want to connect or leave blank to rescan and press [ENTER]:" 
 +                echo "" 
 +                read SSID 
 +        fi
 done done
  
Line 817: Line 988:
 sleep 1 sleep 1
  
-Show details +Encryption select 
-clear +if [[ $DIALOG ]]; then 
-echo "You are connecting to $SSID" +        $DIALOGBIN --title "Encryption" --radiolist "Please select Security for $SSID:" 10 60 2 1 None off 2 WPA on 2>$TMP 
-echo "Details:" +        ENCRYPT=`cat $TMP` 
-iwlist $IFACE scanning essid $SSID |egrep "ESSID|Quality|Encryption|IE:"+else 
 +        clear 
 +        echo "You are connecting to $SSID" 
 + 
 +        echo "Please select Security: " 
 +        echo "1None" 
 +        echo "2: WPA" 
 +        read ENCRYPT 
 +fi
  
-echo "Please select Security: " 
-echo "1: None" 
-echo "2: WPA" 
-read ENCRYPT 
 case "$ENCRYPT" in case "$ENCRYPT" in
- 1) +        1) 
- ;; +                ;; 
- 2) +        2) 
- # Check if wpa_supplicant is installed and quit if not +                # Check if wpa_supplicant is installed and quit if not 
- which wpa_supplicant +                if [[ ! `which wpa_supplicant` ]]; then 
- if [ $? == "1" ]; then +                        if [[ $DIALOG ]]; then 
- echo "wpa_supplicant was not found on this system" +                                $DIALOGBIN --infobox "wpa_supplicant was not found on this system. Aborted" 3 60 
- exit 1 +                        else 
- fi +                                echo "wpa_supplicant was not found on this system. Aborted
- echo "Enter Passpharse: " +                        fi 
- read -s PASS+                        exit 1 
 +                fi 
 +                if [[ $DIALOG ]]; then 
 +                        $DIALOGBIN --passwordbox "Enter Passphrase" 10 60 2>$TMP  
 +                        PASS=`cat $TMP` 
 +                else 
 +                        echo "Enter Passpharse: " 
 +                        read -s PASS 
 +                fi
  
- # Store the entered Passphrase as WPA Key and start wpa_supplicant +                # Store the entered Passphrase as WPA Key and start wpa_supplicant 
- # process in the background +                # process in the background 
- wpa_passphrase $SSID $PASS > /etc/wpa_supplicant/wpa_supplicant.conf +                wpa_passphrase $SSID $PASS > /etc/wpa_supplicant/wpa_supplicant.conf 
- wpa_supplicant -Dwext -i$IFACE -c/etc/wpa_supplicant/wpa_supplicant.conf & +                chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf 
- ;; +                wpa_supplicant -B -Dwext -i$IFACE -c/etc/wpa_supplicant/wpa_supplicant.conf & 
- *) +                ;; 
- echo "Wrong selection, aborting!" +        *) 
- exit 1 +                if [[ $DIALOG ]]; then 
- ;;+                        $DIALOGBIN --infobox "Wrong selection. Aborted!" 3 60 
 +                else 
 +                        echo "Wrong selection. Aborted!" 
 +                fi 
 +                exit 1 
 +                ;;
 esac esac
  
 # Renew the IP and quit smoothly # Renew the IP and quit smoothly
-dhclient $IFACE +if [[ $DIALOG ]]; then 
-exit 0+        $DIALOGBIN --infobox "Obtaining IP Address\n\n If this process takes longer than 15s,\n you may enter a wrong key or no DHCP server present" 6 60 
 +        dhclient -q -1 $IFACE 
 +else 
 +        dhclient -v -1 $IFACE 
 +fi 
 </file> </file>
  
Line 1087: Line 1280:
  
 # decrypt file and exit immediately if passphrase is wrong # decrypt file and exit immediately if passphrase is wrong
-gpg -d $ACCOUNTFILE.gpg > $ACCOUNTFILE || exit 2 +$GPGBIN -d $ACCOUNTFILE.gpg > $ACCOUNTFILE || exit 2
- +
-# remove old encrypted file +
-rm -f $ACCOUNTFILE.gpg+
  
 # edit # edit
-vi $ACCOUNTFILE+$VIBIN $ACCOUNTFILE
  
-# encrypt new file+# encrypt new file and overwrite existing one
 echo "Encrypting ..." echo "Encrypting ..."
-gpg -e -r $USER $ACCOUNTFILE+$GPGBIN --yes -e -r $USER $ACCOUNTFILE
  
 # remove unencrypted file # remove unencrypted file
Line 1392: Line 1582:
 ifconfig $MON down ifconfig $MON down
 </file> </file>
 +==== spacewalk-package-installed ====
 +This script shows which servers have installed a specific package
 +<file bash spacewalk-package-installed>
 +#!/bin/bash
 +PACKAGE=$1
 +VERSION=$2
 +RELEASE=$3
  
 +[[ $@ -ne 3 ]] && { echo "Usage: $0 packagename version release"; exit 2; }
 +
 +for id in `/usr/bin/spacewalk-report system-packages-installed \
 +           --where-package_name=$PACKAGE \
 +           --where-package_version=$VERSION \
 +           --where-package_release=$RELEASE \
 +           |cut -f1 -d, |grep -v ^system_id`
 +        do
 +           /usr/bin/spacewalk-report inventory \
 +           --where-server_id=$id \
 +           |cut -f3 -d, |tail -1
 +done
 +</file>
 ===== C ===== ===== C =====
  
Line 1419: Line 1629:
 } }
 </file> </file>
-===== Arduino ===== 
-==== FTDI USB Serial ==== 
-By using CP2102 or PL2303 chip 
-  - Connect TX to RX and RX to TX 
-  - Keep Programmer ''AVRISP mkII'' 
-  - Select board ''Arduino Pro or Pro Mini (5V, 16Mhz) w/ atmega368'' 
-  - Press reset on Pro Mini just between end of compilation and start of upload 
- 
-{{schematics.jpg|}} 
-==== Arduino ISP ==== 
-By using another Atmel 
-  * Select primary board  
-  * Select ''AVRISP mkII'' as Programmer 
-  *Upload ''Arduino ISP'' sketch to primary board 
-  * Use the following pinout 
- 
-^Function^Master (Nano, Pro Mini)^Slave (Nano, Pro Mini)^Slave (Attiny85 Pins)^ 
-|Reset|10|RST|1| 
-|MOSI|11|11|5| 
-|MISO|12|12|6| 
-|SCK|13|13|7| 
-|VCC|VCC|VCC|8| 
-|GND|GND|GND|4| 
- 
-  * Select secondary board  
-  * Select ''Arduino ISP'' as Programmer 
-  * Upload sketch 
-==== ISPASP ==== 
-Download [[http://www.fischl.de/usbasp/|Driver]] for Windows 
  
-{{usbasp_pinbelegung.png|}} 
 ====== Patches ====== ====== Patches ======
 ===== Roundcube ===== ===== Roundcube =====
public/scripts.1407316151.txt.gz · Last modified: 2014/08/06 09:09 by Roland Hansmann