Git

git hooks post-merge example

#!/bin/bash

# check for modified files
for FILE in $(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD); do
  case "${FILE}" in
    *.json)
      # Repository configuration changed: update configuration
      ~/my_repository/scripts/json_update.sh
      ;;
    cronjobs/crontab)
      # Crontab changed: update user cronjobs
      ~/my_repository/scripts/crontab_update.sh
      ;;
  esac
done

# show repository info
git config -l

# show diff for one file
git diff

# commit only one file
git commit -m 'my comment' path/to/file

# create Git repository
git init

# add all files
git add .

# commit
git commit -m "initial project version"

# list tag
git tag -l

checkout
# checkout over SSH
git clone git@github.com:foo/bar.git

# pull single file
git checkout filename

# pull single file from remote
git checkout origin/master -- path/to/file

# checkout to checkout to specific folder
git clone https://github.com/panticz/installit.git /path/to/folder

# checkout tag
git checkout 1.0.2

# git pull single file
git checkout origin/master -- file_name

# rollback to revision
git checkout 96fe40ded8277725d244aac83c42256ad554cc3b .

# switch branch
git checkout branch_name
git checkout master

# checkout branch
git clone --branch --single-branch []

# test
git reset file/to/overwrite

# search for string
git grep "string/regexp" $(git rev-list --all)

# grep
git grep foo HEAD

# remove last commit
git reset HEAD~1

# reset to latest revision
git reset --hard

git cherry-pick commit1

branch
# diff between branches
git diff master

# show branches
git branch

# push local Git branch to remote master branch
git push origin local_branch_1:master

# delete local branch
git branch -d local_branch_name

# delete remote branch
git push origin :remote_branch_name

# ignore
./.gitignore

# git global setup
git config --global user.name "first_name last_name"
git config --global user.email "user@example.com"

# create a new repository
git clone git@example.com:repository_group/repository_name.git
cd repository_name
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

# Add existing folder or Git repository
cd existing_folder
git init
git remote add origin git@example.com:repository_group/repository_name.git
git add .
git commit
git push -u origin master

Debian: Compile and install multiple PHP CLI versions

# install dependencies
apt-get install -y build-essential
 
# download and compile PHP
for VERSION in 5.3.29 5.4.38 5.5.22 5.6.6; do
    wget -q "http://de1.php.net/get/php-${VERSION}.tar.bz2/from/this/mirror" -O- | tar xj -C /tmp
    cd /tmp/php-${VERSION}
    ./configure --prefix=/opt/php/${VERSION%.*} --disable-all --disable-cgi
    make install -j5
done
 
# add to PATH
for i in /opt/php/*; do
    ln -s $i/bin/php /usr/local/bin/php${i##*/}
done
 
# create backup
cd /opt/php
tar -cjf /tmp/opt.php.$(date -I).tar.bz2 *
 
# test backup
tar -tvf /tmp/opt.php.$(date -I).tar.bz2

Create a restricted user for SSH tunneling

wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/scripts/master/create_ssh_tunnel_user.sh -O - | bash -

#!/bin/bash

# create new restricted user
useradd tunnel --gid nogroup --create-home --skel /dev/null --shell /bin/rbash

# set random encrypted password to enable login
echo "tunnel:$(openssl rand -base64 32)" | chpasswd

# create authorized_keys
mkdir /home/tunnel/.ssh
chmod 700 /home/tunnel/.ssh
touch /home/tunnel/.ssh/authorized_keys
chmod 600 /home/tunnel/.ssh/authorized_keys

# remove path to programs
echo 'PATH=' > /home/tunnel/.profile
chmod 400 /home/tunnel/.profile

# restrict permissions
chmod 500 /home/tunnel
chown tunnel:nogroup /home/tunnel -R

Add your public key(s)
cat /tmp/authorized_keys > /home/tunnel/.ssh/authorized_keys
sed -i 's|ssh-rsa|command="/bin/false",no-pty,no-X11-forwarding ssh-rsa|g' /home/tunnel/.ssh/authorized_keys

# parameter
command="/bin/false",no-agent-forwarding,no-pty,no-user-rc,no-X11-forwarding,permitopen="127.0.0.1:80"
no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding

Links
http://www.gnu.org/software/bash/manual/html_node/The-Restricted-Shell.html

Update LXC container templates filesystem

wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/lxc/master/scripts/lxc-update-templates.sh -O - | bash -

#!/bin/bash

# ensure that this script is run as root
if [ $(id -u) -ne 0 ]; then
  sudo $0
  exit
fi

# set language to english
LANG=en_US.UTF-8

# update APT rootfs (Debian and Ubuntu)
for DIST in $(find /var/cache/lxc/*/* -maxdepth 0 -type d); do
  echo "Updating ${DIST} ..."
  chroot "${DIST}" apt-get update -qq
  chroot "${DIST}" apt-get dist-upgrade -qq -y
  chroot "${DIST}" apt-get autoremove -qq -y
  chroot "${DIST}" apt-get clean
done

# fix dns
echo "nameserver 8.8.8.8" > /var/cache/lxc/debian/rootfs-wheezy-amd64/etc/resolv.conf

Cronjob
echo "0 13 * * * root /usr/bin/wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/lxc/master/scripts/lxc-update-templates.sh -O - | bash -" > /etc/cron.d/lxc_update_template
service cron restart

# fix squeeze repository
sed -i 's|cdn.debian.net|ftp.debian.org|g' /var/cache/lxc/debian/rootfs-squeeze-amd64/etc/apt/sources.list

Install Google Music Manager

wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/installit/master/install.google-musicmanager.sh -O - | bash -

#!/bin/bash

# get URL
if [ "$(uname -m)" == "x86_64" ]; then
  # 64 bit
  URL=https://dl.google.com/linux/direct/google-musicmanager-beta_current_amd64.deb
else
  # 32 bit
  URL=https://dl.google.com/linux/direct/google-musicmanager-beta_current_i386.deb
fi

# download
wget ${URL} -P /tmp

# install
sudo dpkg -i /tmp/google-musicmanager-beta_current_*.deb

$ cat /etc/apt/sources.list.d/google-musicmanager.list
deb http://dl.google.com/linux/musicmanager/deb/ stable main

Links
https://play.google.com/music/listen?u=0#/manager

Docker container under XEN VM

# enable wheezy backports repository
cat <<EOF> /etc/apt/sources.list.d/wheezy-backports.list
deb http://ftp.de.debian.org/debian wheezy-backports main
deb-src http://ftp.de.debian.org/debian wheezy-backports main
EOF
 
# install newest kernel
apt-get update
apt-get install -y -t wheezy-backports linux-image-amd64
 
# reboot your server
reboot
 
# view kernel version
uname -a
# Linux wheezy 3.16.0-0.bpo.4-amd64 #1 SMP Debian 3.16.7-ckt2-1~bpo70+1 (2014-12-08) x86_64 GNU/Linux
 
# install xen
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/installit/master

Check bash version

rm /tmp/out.log
for HOST in $(cat host.list); do
    VERSION=$(ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 ${HOST} 'dpkg-query -W -f="\${Version}" "*bash*"')
    [ !

IO performance benchmark script

Install
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/scripts/master/fio.sh -O - | bash -

#!/bin/bash

OUT=/tmp/fio.out

# install fio
sudo apt-get install -y fio

# clear
[ -f ${OUT} ] && rm ${OUT}

# run fio benchmark
for SIZE in 4 8 16; do
    for BS in 4 16 64; do
        for JOBS in 128 254 512; do
            for TIME in 60 120 240; do
                RESULT=$(fio --rw=readwrite --name=test --direct=1 --group_reporting --time_based --size=${SIZE}M --bs=${BS}k --numjobs=${JOBS} --runtime=${TIME} | grep iops | cut -d "=" -f4 | cut -d "," -f1)
                echo "${SIZE}M,${BS}K,${JOBS}x,${TIME}s,$(echo ${RESULT} | tr ' ', ',')" | tee -a ${OUT}
            done
        done
    done
done

Install Vega vulnerability scanner under Ubuntu / Debian

Install
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/installit/master/install.vega.sh -O - | bash -

#!/bin/bash

# install Java JDK
wget -q https://raw.githubusercontent.com/panticz/installit/master/install.java-jdk.sh -O - | bash -

sudo apt-get install libwebkitgtk-1.0

# download link
if [ "$(uname -m)" == "x86_64" ]; then
  # 64 bit
  URL=http://support.subgraph.com/downloads/VegaBuild-linux.gtk.x86_64.zip
else
  # 32 bit
  URL=http://support.subgraph.com/downloads/VegaBuild-linux.gtk.x86.zip
fi

# download new eclipse release
wget -q ${URL} -P /tmp

# extract
sudo unzip /tmp/VegaBuild-linux.gtk.*.zip -d /usr/share/

sudo ln -s /usr/share/vega/Vega /usr/local/bin/vega

cat <<EOF> /usr/share/applications/vega.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Vega
Comment=Vega Vulnerability Scanner
Exec=vega
Icon=/usr/share/vega/icon.xpm
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true
EOF

Workarround
sudo mkdir -p /usr/share/vega/workspace/
sudo chmod 777 /usr/share/vega/workspace/

Download
https://subgraph.com/vega/download/

Configuration
diff /usr/share/vega/Vega.ini.2015-01-12 /usr/share/vega/Vega.ini
2,5c2,5

 -Xms1024m
> -XX:PermSize=512m
> -XX:MaxPermSize=1024m
> -Xmx4096m

PHP mail test from localhost

<?php 
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
 
    $from = "foo@example.com";
    $to = "bar@example.com";
    $subject = "PHP Mail Test script";
    $message = "This is a test to check the PHP Mail functionality";
 
    $state = mail($to, $subject, $message);
 
    echo "state: $state";
?>
 
# Link
http://php.net/manual/de/function.mail.php
Syndicate content