Permalink
Browse files

add a few more scripts

  • Loading branch information...
1 parent 05d306a commit 3b707a6630aa3662f16eb27d220394f409a340a0 @poliva committed Sep 13, 2012
View
@@ -1,4 +1,6 @@
random-scripts
==============
-scripts I use from time to time
+This is a collection of random scripts I use from time to time.
+
+License is WTFPL: Do What The Fuck You Want Public License, unless specified in the script itself.
View
@@ -0,0 +1,2 @@
+#!/bin/bash
+java -jar /home/pau/bin/apktool.jar $*
View
@@ -0,0 +1,2 @@
+#!/bin/bash
+java -jar /home/pau/bin/droiddraw.jar
View
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+if [ "$1" == "-u" ]; then
+ echo "umounting /home/pau/android"
+ fusermount -u /home/pau/android
+ adb kill-server 2>/dev/null
+ exit 0
+fi
+
+if [ "$1" == "-a" ]; then
+ echo "mounting /home/pau/android via adbfs"
+ adbfs /home/pau/android/ -o modules=subdir -o subdir=/mnt/sdcard/
+ exit $?
+fi
+
+#needs aptitude install mtpfs
+echo "mounting /home/pau/android via mtpfs"
+mount.mtpfs /home/pau/android/
+exit $?
View
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+FILE=$1
+
+if [ ! -e "${FILE}" ]; then
+ echo "USAGE: $0 <file.apk>"
+ exit 1
+fi
+
+if [ ! -d "/tmp/signapk" ]; then
+
+ mkdir -p /tmp/signapk
+ openssl genrsa -out /tmp/signapk/key.pem 1024
+ openssl req -new -key /tmp/signapk/key.pem -out /tmp/signapk/request.pem
+ openssl x509 -req -days 9999 -in /tmp/signapk/request.pem -signkey /tmp/signapk/key.pem -out /tmp/signapk/certificate.pem
+ openssl pkcs8 -topk8 -outform DER -in /tmp/signapk/key.pem -inform PEM -out /tmp/signapk/key.pk8 -nocrypt
+
+fi
+
+FNAME=`echo ${FILE} |sed -e "s/.apk$//g"`
+java -jar /home/pau/bin/signapk.jar /tmp/signapk/certificate.pem /tmp/signapk/key.pk8 ${FNAME}.apk ${FNAME}-signed.apk
@@ -0,0 +1,194 @@
+#!/bin/bash
+#
+# Generic Load balancer for multiple WAN links - version 1.1 (04 Feb 2011)
+# (c) 2011 Pau Oliva Fora - http://pof.eslack.org
+#
+# Licensed under GPLv3 - for full terms see:
+# http://www.gnu.org/licenses/gpl-3.0.html
+#
+#
+# Specify each WAN link in a separate column, example:
+#
+# In this example we have 3 wan links (vlanXXX interfaces) attached to a single
+# physical interface because we use a vlan-enabled switch between the balancer
+# machine and the ADSL routers we want to balance. The weight parameter should
+# be kept to a low integer, in this case the ADSL line connected to vlan101 and
+# vlan102 is 4Mbps and the ADSL line connected to vlan100 is 8Mbps (twice fast)
+# so the WEIGHT value in vlan100 is 2 because it is two times faster.
+#
+# WANIFACE=" vlan101 vlan100 vlan102"
+# GATEWAYS=" 192.168.1.1 192.168.0.1 192.168.2.1"
+# NETWORKS=" 192.168.1.0/24 192.168.0.0/24 192.168.2.0/24"
+# WEIGHTS=" 1 2 1"
+#
+# quick formula to calculate the weight: (LINKSPEED/MINSPEED)*NUM_LINKS
+#
+# If you don't want to use vlans, you should then use a separate physical
+# interface for each link. IP aliasing on the same interface is not supported.
+#
+
+WANIFACE=" usb0 usb1 "
+GATEWAYS=" 192.168.43.129 192.168.42.129 "
+NETWORKS=" 192.168.43.0/24 192.168.42.0/24 "
+WEIGHTS=" 2 1 "
+
+# enable link failover watchdog? set to "yes" or "no".
+WATCHDOG="yes"
+
+# space separated list of public IPs to ping in watchdog mode
+# set this to some public ip addresses pingable and always on.
+TESTIPS="8.8.8.8 192.0.32.10"
+
+# set to 1 when testing, set to 0 when happy with the results
+VERBOSE=1
+
+# CONFIGURATION ENDS HERE
+# do not modify below this line unless you know what you're doing :)
+
+function getvalue() {
+ index=$1
+ VAR=$2
+
+ n=1
+ for f in ${VAR} ; do
+ if [ "${n}" == "${index}" ]; then
+ echo "$f"
+ break
+ fi
+ n=$(($n + 1))
+ done
+}
+
+echo "[] Load balancer for multiple WAN interfaces - v1.1"
+echo "[] (c) 2011 Pau Oliva Fora <pof> @eslack.org"
+echo
+
+case $1 in
+ start) PARAM="add" ;;
+ stop) PARAM="del" ;;
+ *) echo "Usage: $0 [start|stop]" ; echo ; exit 1 ;;
+esac
+
+if [ $(whoami) != "root" ]; then
+ echo "You must be root to run this!" ; echo ; exit 1
+fi
+
+routecmd="ip route replace default scope global"
+
+i=1
+for iface in $WANIFACE ; do
+
+ IP=`ifconfig $iface |grep "inet addr" |cut -f 2 -d ":" |awk '{print $1}'`
+ NET=$(getvalue $i "$NETWORKS")
+ GW=$(getvalue $i "$GATEWAYS")
+ WT=$(getvalue $i "$WEIGHTS")
+
+ echo "[] Interface: ${iface}"
+ if [ $VERBOSE -eq 1 ]; then
+ echo " IP: ${IP}"
+ echo " NET: ${NET}"
+ echo " GW: ${GW}"
+ echo " Weight: ${WT}"
+ echo
+ fi
+ set -x
+ ip route ${PARAM} ${NET} dev ${iface} src ${IP} table ${i}
+ ip route ${PARAM} default via ${GW} table ${i}
+ ip rule ${PARAM} from ${IP} table ${i}
+ set +x
+ echo
+ routecmd="${routecmd} nexthop via ${GW} dev ${iface} weight ${WT}"
+ i=$(($i + 1))
+done
+
+echo "[] Balanced routing:"
+
+set -x
+${routecmd}
+set +x
+echo
+
+if [ $PARAM == "del" ] || [ $WATCHDOG != "yes" ]; then
+ exit 0
+fi
+
+echo "[] Watchdog started"
+# 0 == all links ok, 1 == some link down
+STATE=0
+
+while : ; do
+
+ if [ $VERBOSE -eq 1 ]; then
+ echo "[`date '+%H:%M:%S'`] Sleeping, state=$STATE"
+ fi
+ sleep 30s
+
+ IFINDEX=1
+ DOWN=""
+ DOWNCOUNT=0
+ for iface in $WANIFACE ; do
+
+ FAIL=0
+ COUNT=0
+ IP=`ifconfig $iface |grep "inet addr" |cut -f 2 -d ":" |awk '{print $1}'`
+ for TESTIP in $TESTIPS ; do
+ COUNT=$(($COUNT + 1))
+ ping -W 3 -I $IP -c 1 $TESTIP > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ FAIL=$(($FAIL + 1))
+ fi
+ done
+ if [ $FAIL -eq $COUNT ]; then
+ echo "[`date '+%H:%M:%S'` WARN] $iface is down!"
+ if [ $STATE -ne 1 ]; then
+ echo "Switching state $STATE -> 1"
+ STATE=1
+ fi
+ DOWN="${DOWN} $IFINDEX"
+ DOWNCOUNT=$(($DOWNCOUNT + 1))
+ fi
+ IFINDEX=$(($IFINDEX + 1))
+ done
+
+ if [ $DOWNCOUNT -eq 0 ]; then
+ if [ $STATE -eq 1 ]; then
+ echo
+ echo "[`date '+%H:%M:%S'`] All links up and running :)"
+ if [ $VERBOSE -eq 1 ]; then
+ set -x
+ ${routecmd}
+ set +x
+ echo
+ else
+ ${routecmd} 2>/dev/null
+ fi
+ STATE=0
+ echo "Switching state 1 -> 0"
+ fi
+ # if no interface is down, go to the next cycle
+ continue
+ fi
+
+ cmd="ip route replace default scope global"
+
+ IFINDEX=1
+ for iface in $WANIFACE ; do
+ for lnkdwn in $DOWN ; do
+ if [ $lnkdwn -ne $IFINDEX ]; then
+ GW=$(getvalue $IFINDEX "$GATEWAYS")
+ WT=$(getvalue $IFINDEX "$WEIGHTS")
+ cmd="${cmd} nexthop via ${GW} dev ${iface} weight ${WT}"
+ fi
+ done
+ IFINDEX=$(($IFINDEX + 1))
+ done
+
+ if [ $VERBOSE -eq 1 ]; then
+ set -x
+ ${cmd}
+ set +x
+ echo
+ else
+ ${cmd} 2>/dev/null
+ fi
+done
View
@@ -0,0 +1,10 @@
+#!/bin/bash
+# credentials are in /etc/davfs2/secrets
+# instructions (from http://benjaminkerensa.com/2011/10/27/how-to-mount-box-net-securely-on-ubuntu-11-10 )
+#
+# sudo apt-get install davfs2
+# sudo echo "https://www.box.net/dav username password" >> /etc/davfs2/secrets
+# Access Box.net via Nautilus using WebDAV:
+# Just use Connect to Server to dav://www.box.net/dav and make sure to select Secure WebDAV.
+
+sudo mount -t davfs -o uid=pau -o gid=pau https://www.box.com/dav /media/box/
View
@@ -0,0 +1,34 @@
+#!/bin/bash
+#
+# find optimal bs size for 'dd' command.
+# taken from http://serverfault.com/questions/147935/how-to-determine-the-best-byte-size-for-the-dd-command
+#
+
+if [ -z "$1" ]; then
+ echo "Usage: $0 <device>"
+ echo "Example: $0 /dev/sdc"
+ exit 1
+fi
+
+echo "!!! WARNING WARNING WARNING WARNING WARNING !!!"
+echo "This will completely WIPE the contents of $1"
+echo -n "Type 'yes' to continue: "
+read answer
+
+if [ "$answer" != "yes" ]; then
+ echo ""
+ exit 1
+fi
+
+echo "creating a temp file to work with"
+dd if=/dev/zero of=/var/tmp/infile count=1175000
+
+for bs in 1k 2k 4k 8k 16k 32k 64k 128k 256k 512k 1M 2M 4M 8M
+
+do
+ echo
+ echo
+ echo "Testing block size = $bs"
+ time sudo dd if=/var/tmp/infile of=$1 bs=$bs
+done
+rm /var/tmp/infile
View
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Joshua V. Dillon
+# jvdillon (a) gmail (.) com
+#
+# Restart unity even from a TTY (control-alt-F1).
+
+export DISPLAY=:0.0;
+export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -nu $USER gnome-screensav)/environ|cut -d= -f2-)
+unity --replace &
+
View
@@ -0,0 +1,14 @@
+#!/bin/bash
+# Restart unity2D even from a TTY (control-alt-F1).
+
+export DISPLAY=:0.0;
+export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -nu $USER gnome-screensav)/environ|cut -d= -f2-)
+
+#unity_2d="unity-2d-places unity-2d-launcher unity-2d-panel unity-2d-spread"
+unity_2d="unity-2d-launcher unity-2d-panel"
+
+killall $unity_2d
+metacity --replace &
+for f in $unity_2d; do
+ "$f" &
+done
View
@@ -0,0 +1,5 @@
+#!/bin/bash
+gsettings set org.gnome.desktop.lockdown disable-lock-screen 'false'
+gnome-screensaver-command -l
+sleep 1s
+gsettings set org.gnome.desktop.lockdown disable-lock-screen 'true'
View
@@ -0,0 +1,4 @@
+#!/bin/bash
+sudo iw dev wlan0 interface add wmon0 type monitor
+sudo ifconfig wmon0 up
+sudo dumpcap -i wmon0 -w /tmp/wlan0.pcap
View
@@ -0,0 +1,11 @@
+#!/bin/bash
+REALMAC=xx:xx:xx:xx:xx:xx
+
+sudo ifconfig wlan0 down
+if [ "$1" == "-r" ]; then
+ sudo macchanger -m $REALMAC wlan0
+else
+ sudo macchanger -e wlan0
+fi
+sudo dhclient3 wlan0
+ifconfig wlan0
View
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+case $1 in
+
+suspend)
+ echo "NM suspend"
+ #dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.sleep
+ sudo dbus-send --system --print-reply --reply-timeout=600 --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Sleep boolean:true
+
+;;
+
+resume)
+ echo "NM resume"
+ #dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.wake
+ sudo dbus-send --system --print-reply --reply-timeout=600 --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Sleep boolean:false
+
+;;
+
+*)
+ echo "Usage: $0 [suspend|resume]"
+;;
+
+esac
View
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+#reboot router
+echo "Rebooting router...."
+(sleep 2; echo admin; sleep 2; echo PASSWORD; sleep 2; echo "reboot"; sleep 2; echo "exit"; sleep 2; echo "logout") | telnet vodafone
+
+# wait for reboot
+echo "Waiting for the router to reboot..."
+sleep 90s
+
+# remove bogus iptables rule
+echo "Removing bogus iptables rule..."
+(sleep 2; echo admin; sleep 2; echo ktdna0ET; sleep 2; echo "sh"; sleep 2; echo "iptables -t nat -D PREROUTING_IN 1"; sleep 2; echo "exit"; sleep 2; echo "logout") | telnet vodafone
+
+if [ $? == 0 ]; then echo "Done!" ; fi
Oops, something went wrong.

0 comments on commit 3b707a6

Please sign in to comment.