Commit 41d903e4 authored by yids's avatar yids
Browse files

initial commit

parents
File added
#!/bin/bash
# HBL Handy Bash Lib
# Some handy functions to use in scripts
printf "HBL init \n"
#
# display usage for script
# make sure that in the main script USAGE is exported
#
usage()
{
printf "$USAGE"
exit 1
}
#
# check number of arguments
# make sure that in the main script NUMARGS is exported
#
check_num_args()
{
if [[ $1 -ne $NUMARGS ]] ;
then
printf "This script takes $NUMARGS arguments. \n"
usage
return 1;
fi
}
#
# checks if commands exist
# usage: check_dependencies command1 ... commandN
#
check_dependencies()
{
for dep in $@
do
command -v $dep >/dev/null && continue || { printf "%s depends on %s, but %s is not found. \n" "$0" "$dep" "$dep"; exit 1; }
done
}
#
# check if script is running as root
#
check_root()
{
if [[ $(id -u) != 0 ]];
then
printf "This script needs to run as root! \n"
exit 1
fi
}
#
# execute a command
# usage: execute {COMMAND} [DISCRIPTION]
#
execute ()
{
if [[ ! -z $2 ]];
then
printf "description: $2\n"
fi
if [[ $3 -eq "1" ]];
then
printf "EXECUTE: $1\n"
else
$1
fi
if [[ $? -eq 1 ]];
then
printf "Command $1 failed, quiting...\n"
exit 0
fi
}
#!/bin/bash
# Some handy functions to use in scripts
check_num_args()
{
if [[ $# -ne $NUMARGS ]] ;
then
printf "Not enough arguments. \n"
return 1;
fi
}
#
# checks if commands exist
# usage: check_dependencies command1 ... commandN
#
check_dependencies()
{
for dep in $@
do
command -v $dep >/dev/null && continue || { printf "%s depends on %s, but %s is not found. \n" "$0" "$dep" "$dep"; exit 1; }
done
}
#
# execute a command
# usage: execute {-c COMMAND} [OPTION]...
# -d print a discription of the command
# -t do a dry run of the command (dont execute only print)
# -f quit if command does not exit with 0 (ie. if it fails)
#
execute()
{
while getopts ":d::c::t:f" opt;
do
case $opt in
d)
printf "command: %s, discription: %s \n" "$CMD" "$OPTARG"
DISC=$OPTARG
;;
c)
CMD=$OPTARG
;;
t)
printf "dry run of %s, description %s \n" "$CMD" "$DISC"
DRYRUN=1
;;
f)
printf "this is a command that must succeed\n"
FATAL=1
esac
done
shift $((OPTIND-1))
}
execute "ls" -d "checking contents" -t -f
#!/bin/bash
NUMARGS=1
SRCROOT="../"
DIR=$PWD
OVPNDIR="/etc/openvpn"
CONFIG="client.ovpn"
source "$SRCROOT/HBL"
check_root
check_num_args $#
check_dependencies openvpn
cd
openvpn --config /etc/openvpn/client.ovpn --daemon
cd $DIR
#!/bin/sh
#
echo in out
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -o $1 -j MASQUERADE
#openvpn
/sbin/iptables -A FORWARD -i $1 -o $2 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i $2 -o $1 -j ACCEPT
rappers @ 3fbf14dd
Subproject commit 3fbf14ddb4b3ebc258ed9aaf75cd6afd708c5b20
#!/bin/bash
NUMARGS=0
usage()
{
printf "Usage: \n"
}
if [[ $# -ne $NUMARGS ]] ;
then
printf "Not enough arguments. \n"
usage
fi
wrss @ c922ebe7
Subproject commit c922ebe75eb442f9fb4505309ec57c8fa0cfae9c
#!/bin/bash
export NUMARGS=3
export USAGE="usage: ./xen-pci -a(ttach)/-d(etach) [BDF] [Dom you want to attach device to]\n"
SRCROOT="/home/yids/src/mine"
source "$SRCROOT/HBL"
check_root
check_num_args $#
modprobe xen-pciback
BDF=$2
DOM=$3
if [[ $1 = "-a" ]];
then
printf "attaching $BDF to $DOM... \n"
execute "xl pci-assignable-add $BDF"
execute "xl pci-attach $DOM $BDF"
fi
if [[ $1 = "-d" ]];
then
if [[ $BDF = "ALL" ]];
then
BDFS=$(xl pci-list $DOM | grep 0 | awk {'print $2'} )
printf "$BDFS\n" | while read line;
do
printf "detaching and removing $line \n"
execute "xl pci-detach $DOM $line"
execute "xl pci-assignable-remove -r $line"
done
exit 1
fi
printf "dettaching $BDF from $DOM... \n"
execute "xl pci-detach $DOM $BDF"
execute "xl pci-assignable-remove -r $BDF"
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment