LXC: create Debian Jessie container

<?php
$URL="https://raw.githubusercontent.com/panticz/lxc/master/create.jessie.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -s";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

(re)create container
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/lxc/master/create.jessie.sh -O - | bash -s -- -f

Allow root SSH login with password
CONTAINER=jessie
sudo lxc-attach -n ${CONTAINER} -- sed -i 's|PermitRootLogin without-password|PermitRootLogin yes|' /etc/ssh/sshd_config
sudo lxc-attach -n ${CONTAINER} -- service ssh restart

Fix DNS
echo nameserver 8.8.8.8 | sudo tee /var/lib/lxc/${CONTAINER}/rootfs/etc/resolv.conf

Default login credentials
user: root
pass: root

FixMe
"Failed to mount cgroup at /sys/fs/cgroup/systemd: Permission denied"
https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1346734

Failed to open /dev/autofs: No such file or directory
Failed to initialize automounter: No such file or directory
[FAILED] Failed to set up automount Arbitrary Executable File Formats File System Automount Point.
See 'systemctl status proc-sys-fs-binfmt_misc.automount' for details.
Unit proc-sys-fs-binfmt_misc.automount entered failed state.

Socket service systemd-udevd.service not loaded, refusing.
[FAILED] Failed to listen on udev Kernel Socket.
See 'systemctl status systemd-udevd-kernel.socket' for details.
Socket service systemd-udevd.service not loaded, refusing.
[FAILED] Failed to listen on udev Control Socket.
See 'systemctl status systemd-udevd-control.socket' for details.

Bugs
https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1347020
https://wiki.debian.org/LXC#Incompatibility_with_systemd

Fix DNS
echo nameserver 8.8.8.8 > /var/lib/lxc/${CONTAINER}/rootfs/etc/resolv.conf

# test
http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_jessie/sid_installation

LXC: create Debian Wheezy container

<?php
$URL="https://raw.githubusercontent.com/panticz/lxc/master/create.wheezy.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

(re)create container
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/lxc/master/create.wheezy.sh -O - | bash -s -- -f

Default login credentials
user: root
pass: root

Fix DNS
echo nameserver 8.8.8.8 > /var/lib/lxc/${CONTAINER}/rootfs/etc/resolv.conf

LXC: create Debian Squeeze container

<?php
$URL="https://raw.githubusercontent.com/panticz/lxc/master/create.squeeze.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

(re)create container
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/lxc/master/create.squeeze.sh -O - | bash -s -- -f

Default login credentials
user: root
pass: root

Fix DNS
echo nameserver 8.8.8.8 > /var/lib/lxc/${CONTAINER}/rootfs/etc/resolv.conf

Ubuntu: Ericsson H5321gw / F5521gw mini PCI-e WWAN / UMTS card

Ericsson H5321gw (Thinkpad T530)
# lsusb | grep Ericsson
Bus 003 Device 004: ID 0bdb:1926 Ericsson Business Mobile Networks BV

# fix kernel driver
echo "/etc/modprobe.d/avoid-mbib.conf" > options cdc_ncm prefer_mbim=N

cat < /etc/udev/rules.d/99-mbm.rules
ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1926",
ENV{ID_USB_INTERFACE_NUM}=="09", ENV{MBM_CAPABILITY}="gps_nmea"
ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1926",
ENV{ID_USB_INTERFACE_NUM}=="03", ENV{MBM_CAPABILITY}="gps_ctrl"
EOF

# force USB modem to only connect via EDGE and not 3G?

Git

git hooks post-merge example
<?php
$URL="https://raw.githubusercontent.com/panticz/scripts/master/git/post-merge";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

# show repository info
git describe
git config -l

# show commit info
git show

# 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
# pull all files from remote
git checkout origin/dev -- .

# sync changes from other branch
git rebase master
git rebase brach1

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

# create tag
git tag -a v1.4 -m 'version 1.4'
git push --tags
git push origin

# remove tag
git tag -d tag123
git push origin :refs/tags/tag123

# checkout tag
git clone --branch bar-1.0.4 git@git.example.com:foo/ansible.git /tmp/bar-1.0.4

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

# checkout commit
git checkout commit_hash

Branch
# reset branch
git reset --hard origin/master
git reset --hard origin/branch123
git reset --hard

# rollback to revision
git checkout 96fe40ded8277725d244aac83c42256ad554cc3b .

# create branch
git checkout -b branch_name

# switch branch
git checkout branch_name
git checkout master

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

# diff all files betwen braches
git diff dev..stage

# diff singe file between branches
git diff dev..stage file1

# diff branches and show file name only
git diff --name-only dev..stage

# diff differnet fiels in different branches
git diff branch1:file branch2:file

# 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

# reset to commit-id
git reset --hard
git push origin HEAD --force

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

# delete directory / file from git repository without removing from disk
git rm --cached -r DIR1

# ignore
./.gitignore

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

# 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

# search for string in commit
git grep foo $(git rev-list --all)

# check out single file
git archive --remote=git@git.example.com:foo/bar.git HEAD:path1/file_or_dir target_file_name | tar --extract

# set proxy
http://cms-sw.github.io/tutorial-proxy.html
git config --global http.proxy $http_proxy
git config --global https.proxy $https_proxy

# undo changes on file
git checkout -- file

# inclue a commit
git cherry-pick commit1

http.sslVerify
http.sslCAInfo
http.sslCAPath
http.sslCert
http.sslKey
http.sslCertPasswordProtected

# pass GIT settings over SSH
https://cweiske.de/tagebuch/carry-git-settings.htm
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example -F /dev/null" git clone example
git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"

Submodule
https://chrisjean.com/git-submodules-adding-using-removing-and-updating/
git rm --cached roles/icinga-client
git submodule add git@git.example.com:foo/ansible-roles/icinga-client.git roles/icinga-client

# update submodule
git submodule update --recursive --remote

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

<?php
$URL="https://raw.githubusercontent.com/panticz/scripts/master/create_ssh_tunnel_user.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

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

<?php
$URL="https://raw.githubusercontent.com/panticz/lxc/master/scripts/lxc-update-templates.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

# 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

<?php
$URL="https://raw.githubusercontent.com/panticz/installit/master/install.google-musicmanager.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

$ 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