Tag Archives: bash

atmel at90usb162 linux hello world howto

hi

here some nice howto for an hello world program with atmel at90usb162.

install some packages:

apt-get install avr-gcc avr-libc dfu-programmer

here is my hello world script which switches an led on an off

#include <avr/io.h>
#define F_CPU 2000000UL
#include <util/delay.h>
#include <avr/wdt.h>

int main(void) {
 MCUSR &= ~(1 << WDRF);
 wdt_disable();

 DDRD |= (1<<6);

 while(1) {
   if ( !(PIND & (1<<6) ) ){
    PORTD &= ~(1<<6);
    _delay_ms(1000);
    PORTD |= (1<<6);
    _delay_ms(1000);

    PORTD &= ~(1<<6);
    _delay_ms(1000);
    PORTD |= (1<<6);
    _delay_ms(1000);

    int i;
    for (i = 0; i < 20; i++) {
     PORTD &= ~(1<<6);
     _delay_ms(50);
     PORTD |= (1<<6);
     _delay_ms(50);
    }
 
   }
   else {
    PORTD &= ~(1<<6);
   }
 }

return 0;
}

due to my laziness i wrote a shell script whitch automates compiling, converting and the flashing process

#!/bin/bash

if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
echo "usage: doavr test.c test.elf test.hex"
exit
fi

if [ -e $2 ]; then
rm $2
fi
if [ -e $3 ]; then
rm $3
fi

avr-gcc -g -Os -mmcu=at90usb162 $1 -o $2
avr-objcopy -j .text -j .data -O ihex $2 $3

sudo dfu-programmer at90usb162 erase
sleep 1
sudo dfu-programmer at90usb162 flash $3
sleep 1
sudo dfu-programmer at90usb162 reset

have fun!

l2tp ipsec linux client bash script

hi

here is my simple approach of a vpn client via bash
The main script i found https://wiki.archlinux.org/index.php/L2TP/IPsec_VPN_client_setup
I’ve adopted it to my needs.

First we configure strongswan:

/etc/ipsec.conf
conn yourcompany
    keyexchange=ikev1
    authby=secret
    type=transport
    left=%defaultroute
    leftprotoport=17/1701
    right=2.2.2.2
    rightprotoport=17/1701
    auto=add
/etc/ipsec.secrets
2.2.2.2 : PSK "yourpsk"

Now we configure xl2tpd

/etc/xl2tpd/xl2tpd.conf
[lac vpn-connection]
lns = 2.2.2.2
ppp debug = yes
pppoptfile = /etc/ppp/options.l2tpd.client
length bit = yes
/etc/ppp/options.l2tpd.client
ipcp-accept-local
ipcp-accept-remote
refuse-eap
require-mschap-v2
noccp
noauth
idle 1800
mtu 1410
mru 1410
defaultroute
debug
lock
connect-delay 5000
name yourusername
password yourpassword

Here is my bash script

#!/bin/bash
if [ $# != 1 ] ; then
    echo "Usage: (sudo) sh $0 {start|stop}" 
    exit 1;
fi

VPN_ADDR=2.2.2.2

function getIP(){
    /sbin/ifconfig $1 | grep "inet "| awk '{print $2}'
}

function getGateWay(){
    /sbin/route -n | grep -m 1 "^0\.0\.0\.0" | awk '{print $2}'
}

function getVPNGateWay(){
    /sbin/route -n | grep -m 1 "$VPN_ADDR" | awk '{print $2}'
}

function saveInterface() {
    echo $(/sbin/route -n | grep -m 1 "^0\.0\.0\.0" | awk '{print $8}') > /tmp/interface.txt
}

function getInterface(){
    cat /tmp/interface.txt
}

GW_ADDR=$(getGateWay)  

function start(){
    saveInterface
    ipsec up youconnectioname
    sleep 2    #delay to ensure that IPsec is started before overlaying L2TP

    systemctl start xl2tpd
    sleep 2
    /bin/echo "c vpn-connection" > /var/run/xl2tpd/l2tp-control     
    sleep 2    #delay again to make that the PPP connection is up.

    route add $VPN_ADDR gw $GW_ADDR $(getInterface)
    route add default gw $(getIP ppp0)
    route delete default gw $GW_ADDR
}

function stop(){
    ipsec down yourconnectioname
    /bin/echo "d vpn-connection" > /var/run/xl2tpd/l2tp-control
    systemctl stop xl2tpd
    
    VPN_GW=$(getVPNGateWay)
    route delete $VPN_ADDR gw $VPN_GW $(getInterface)
    route add default gw $VPN_GW
}
$1
exit 0

systemd iptables firewall script archlinux

Hi

Here some short howto config systemd to run sysvinit firewall script:

1st copy your existing iptables script to

cp myfw /root/bin/myfw
chmod 750 /root/bin/myfw

Now lets create the systemd service as following:

vim /etc/systemd/system/myfw.service
[Unit]
Description=myfw
After=network.target

[Service]
RemainAfterExit=yes
ExecStart=/root/bin/myfw start
ExecStop=/root/bin/myfw stop
User=root

[Install]
WantedBy=multi-user.target

Enable the script for autostart at boot

systemctl enable myfw.service

Start the firewall

systemctl start myfw.service

Have fun!

awstats static html apache ubuntu howto

hi

here some nice howto to get awstats with static html output working under ubuntu

apt-get install awstats libgeo-ipfree-perl libnet-ip-perl

disable the ubuntu cronjob ( comment out everything)

vim /etc/cron.d/awstats

now we setup our /etc/awstats/awstats.domain.tld.conf (cp awstats.conf awstats.domain.tld.conf)

LogFile="/var/log/apache2/domain.tld-access.log"
LogFormat=1
SiteDomain="domain.tld"
DNSLookup=0
LoadPlugin="graphgooglechartapi"
LoadPlugin="geoipfree"

I’ve disabled DNSLookup due to performance issues

create a shell script witch executes awstats

#!/bin/bash

DOMS="domain.tld domain1.tld domain2.tld domain3.tld"

for DOM in $DOMS
do
/usr/lib/cgi-bin/awstats.pl -config=$DOM -update -LogFile="/usr/share/awstats/tools/logresolvemerge.pl /var/log/apache2/"$DOM"-access.log.1 /var/log/apache2/"$DOM"-access.log |"
/usr/share/awstats/tools/awstats_buildstaticpages.pl -update -config=$DOM -dir=/srv/www/vhosts/host1/$DOM/htdocs/awstats -awstatsprog=/usr/lib/cgi-bin/awstats.pl
done

Have fun!

simple shell script to generate ssl certs

hi there
This one is for commercial SSL certs

#!/bin/bash
if [ $1 ]; then
    if [ -d $1 ]; then
        echo "dir $1 exists exiting"
        exit
    else
        mkdir $1
    fi
    openssl genrsa -out $1/$1.key 2048
    openssl req -new -key $1/$1.key -out $1/$1.csr
else
    echo "usage generate.sh domain.tld"
fi

This one for self signed certs

#!/bin/bash
if [ $1 ]; then
    if [ -d $1 ]; then
        echo "dir $1 exists exiting"
        exit
    else
        mkdir $1
    fi
    openssl genrsa -out $1/$1.key 2048
    openssl req -new -key $1/$1.key -out $1/$1.csr
    openssl x509 -req -days 1024 -in $1/$1.csr -signkey $1/$1.key -out $1/$1.crt
else
    echo "usage generate.sh domain.tld"
fi

Here is a script to show the SSL Info out of an Cert

#!/bin/bash
if [ $1 ]; then
    if [ -d $1 ]; then
        openssl x509 -in $1/$1.crt -noout -text
        openssl req -text -in $1/$1.csr
    fi
else
    echo "usage showsslinfo.sh domain.tld"
fi

have fun!