Cut videos in Linux with avidemux

avidemux is a program that offers a GUI to cut videos on Linux. To install it, you need to either have the readymade .deb for your distro of Ubuntu, or compile it from source yourself. This post tells you how to compile and install avidemux for Ubuntu 16.10 (and other versions)

You need to first compile and install avidemux:

Download it from here, extract it.

tar xf avidemux_2.6.12.tar.gz
cd avidemux_2.6.12

Install all dependencies:

sudo apt-get install gcc g++ make cmake pkg-config libpng12-dev fakeroot yasm libsqlite3-dev  build-essential qttools5-dev-tools qtbase5-dev libaften-dev libmp3lame-dev libx264-dev  libfaad-dev libfaac-dev libqt4-dev

Compile and install:

bash bootStrap.bash --deb

Now install the compiled debs:

sudo dpkg -i debs/*deb

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Prepare a new vps

My preparation script can be run by:

wget http://git.droidzone.in/droidzone/prepare-vps/raw/master/preparevps && bash preparevps

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

git pull error: fatal: protocol error: bad line length character: Fail

Solution to fix:
“fatal: protocol error: bad line length character: Fail”

The error:

# git pull
fatal: protocol error: bad line length character: Fail

Solution:
Change the login shell of user git from /bin/sh to /bin/bash

[email protected]:~# chsh -s /bin/bash git

Now retrying:

# git pull
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 20 (delta 11), reused 0 (delta 0)
Unpacking objects: 100% (20/20), done.
From gitmaster.droidzone.in:droidzone/bash-advanced-scripts
   84fa4aa..cccfa41  master     -> origin/master
Updating 84fa4aa..cccfa41
Fast-forward
 batchtorrent.pl   |  237 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gitlabrestart     |    4 +++
 loadtorrents.pl   |  134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 readfile.pl       |  140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 rotten2torrent.pl |  269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 784 insertions(+)
 create mode 100755 batchtorrent.pl
 create mode 100755 gitlabrestart
 create mode 100755 loadtorrents.pl
 create mode 100755 readfile.pl
 create mode 100755 rotten2torrent.pl

Edit: This is not the proper fix.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Automatically updating Maxmind geolite2 database

Create a bash script:
#cat updatedb

#!/bin/bash

echo Updating Maxmind databases:
cd /var/www/virtual/joel.co.in/testprojects/htdocs
wget -r http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
mv geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz ./GeoLite2-City.mmdb.gz

Add a cron file:
#cat geolitecron

# top of crontab
[email protected]

0 23 * * * /var/www/virtual/joel.co.in/testprojects/htdocs/updatedb

# end of crontab

Add it to cron:

crontab geolitecron

That’s it..


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Use tor for any command on Linux

The following details a procedure to use tor for any commands used on the command line in Linux. The test env here is a Debian server.

Install tor:

# apt-get install tor

You should create a hashed control password for tor:

#tor --hash-password 'mypassword'
Apr 22 21:00:14.198 [notice] Tor v0.2.4.27 (git-412e3f7dc9c6c01a) running on Linux with Libevent 2.0.19-stable and OpenSSL 1.0.1e.
Apr 22 21:00:14.198 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Apr 22 21:00:14.206 [warn] You are running Tor as root. You don't need to, and you probably shouldn't.
16:A08B4CD129C38494608095E8CB6E3CF6FD61987221130F81E49F28783D

Now setup tor options in the control file at /etc/tor/torrc so that it contains the following:

ControlPort 9051
CookieAuthentication 0
HashedControlPassword 16:A08B4CD129C38494608095E8CB6E3CF6FD61987221130F81E49F28783D

Now, Restart the tor service:

service tor restart

Test the current ip:
# curl ifconfig.me 2>/dev/null
196.152.33.228

Now test the torrized ip:

# torify curl ifconfig.me 2>/dev/null
162.247.72.212

To get a new ip, do this:

echo -e 'AUTHENTICATE "mypassword"\r\nsignal NEWNYM\r\nQUIT' | nc 127.0.0.1 9051

Here, you’re providing the password which you created earlier.

Test the new ip:

# torify curl ifconfig.me 2>/dev/null
77.109.141.138

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Rename all pdf files in a directory with their titles

There are two ways to do this:
Method 1:

#!/usr/bin/python
# pyPdf available at http://pybrary.net/pyPdf/
from pyPdf import PdfFileWriter, PdfFileReader
import os

for fileName in os.listdir('.'):
        try:
                if fileName.lower()[-3:] != "pdf": continue
                input1 = PdfFileReader(file(fileName, "rb"))
                print input1.getDocumentInfo().title
                os.rename(fileName, input1.getDocumentInfo().title + ".pdf")
        except:
                print ''

Method 2:

#!/bin/bash
for file in ./*
do
    a=$(pdftk $file dump_data_utf8 | grep -A 1 'InfoKey: Title' | sed '/InfoKey: Title/d' | sed 's/InfoValue: //')
    if [ "$a" != "" ]
        then
                echo $a".pdf"
                b="$a"".pdf"
                mv $file "$b"
        fi
done

Method 3:
This reads the first heading that comes after the word Chapter, and uses it to rename the files.

#!/bin/bash
for file in ./*
do

    a=$(pdftotext -layout "$file" - | grep 'Chapter' -A1 -m1 | sed -e 's/^[ \t]*//' | tr '\n' ' ' | sed -e "s/[[:space:]]\+/ /g" | sed 's/\s*$//g' )
#| sed 's/\s*$//g')
    if [ "$a" != "" ]
    then
        b=$a".pdf"
        echo $file " ==> " $a " --> " $b
        mv "$file" "$b"
    fi
done

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Change default login shell for a user

Suppose you need to do some work as the defaullt web user. For me, thats vu2009. So you need to enable ssh login for the user.

Checking /etc/passwd, I see that shell is disabled by having the default shell for the user as /bin/false.

So enable a bash shell by running:

sudo chsh -s /bin/bash vu2009

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Colored adb shell, adb over wifi and more

First install bash as your shell on Android (Refer my older posts here).
Then, download adb putty from here (Link: https://github.com/sztupy/adbputty/downloads)
Download this nifty app from Play store and install it.
Run the app on the phone.
Now, run the following adb command:

adb connect 192.168.2.54:5555

where 192.168.2.54 is the phone’s ip as set by the wifi modem or router (It’s always best to assign IP instead of relying on DHCP)
Now run:

adb shell

If you would like to use adb putty (It provides support for bash colors, ls colors etc):
In adb putty set the following:

Hostname/IP: transport-192.168.2.54:5555
Port: 5037
Connection type: adb

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Cross compile Bash for Android (Updated for Bash 4.4) with download links

Latest instructions for bash 4.4 and arm64 device architecture:
Step 1: Get and prepare the environment and toolchain:

mkdir ~/aarch64-toolchain/
wget http://releases.linaro.org/components/toolchain/binaries/latest-6/aarch64-linux-gnu/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz
tar xf gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz
export PATH=$PATH:~/aarch64-toolchain/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin

Next get the bash source and build:

mkdir bashsrc
cd bashsrc
wget http://ftp.gnu.org/gnu/bash/bash-4.4.tar.gz

Get latest from http://ftp.gnu.org/gnu/bash/?C=M;O=D

tar xf bash-4.4.tar.gz
cd bash-4.4
mkdir /root/bashstatic
./configure --prefix=/root/bashstatic --host=aarch64-linux-gnu --enable-static-link --without-bash-malloc --enable-largefile --enable-alias --enable-history
export CFLAGS="-static"
make

We can also modify the line (add -static to the end) to read:
CFLAGS = -g -O2 -Wno-parentheses -Wno-format-security -static

Test the file to see whether it is ARM x64:

~/aarch64-toolchain/bash/bash-4.4 $file bash
bash: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=3e2a4fc358a13f74714907c7b454a9024675dbff, not stripped
[/bash]

Download “bash 4.4 for arm64” bash.zip – Downloaded 17 times – 4 MB

Older post:
Step 1: Downloading and installing the toolchain

This is the difficult step. Once this is done, usually compiling is a no-brainer.

The following steps use the latest Codesourcery compiler and worked for bash 4.3 on Debian squeeze host.

To get the latest Codesourcery toolchain, Visit the Codesourcery home at http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/ and under “ARM Processors”, click on “Download the GNU/Linux release”, enter your user details. The download link will be mailed to your email address in a couple of seconds.

Clicking on the link in the email will take you to a page with a list of releases and a link to the one you chose. For me, it was https://sourcery.mentor.com/GNUToolchain/release2795. Clicking on it will give you the following options: IA32 GNU/Linux Installer, IA32 Windows Installer and advanced options. Click on IA32 GNU/Linux Installer to download the bin file.

Now, you need to install certain dependencies for the toolchain, and the toolchain itself:

apt-get install ia32-libs ia32-libs-gtk
wget https://sourcery.mentor.com/GNUToolchain/kbattach150/getlibs-all.deb
sudo dpkg -i getlibs-all.deb
getlibs -p xulrunner-1.9.2
wget https://sourcery.mentor.com/GNUToolchain/package12815/public/arm-none-linux-gnueabi/arm-2014.05-29-arm-none-linux-gnueabi.bin
/bin/sh arm-2014.05-29-arm-none-linux-gnueabi.bin -console

Step 2: Setup the environment

Now you need to setup your environment to have certain environmental variables for cross compiling and pointing to the toolchain path. You dont want to use your system compiler to compile these files do you (those files cant be run on your phone/tablet)?

export CROSS_COMPILE="/root/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/arm-none-linux-gnueabi-gcc"
export PATH=/root/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin:$PATH

Step 3: Getting and preparing the source code
Now you will need to download the latest bash source code, extract it.

cd ~/
mkdir bashsrc
cd bashsrc
wget http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz
tar -xvvf bash-4.3.tar.gz

Step 4: Compiling
You will now compile and then ‘make’ the binaries.

mkdir /root/bashstatic
cd bash-4.3
./configure --prefix=/root/bashstatic --host=arm-none-linux-gnueabi --enable-static-link --without-bash-malloc --enable-largefile --enable-alias --enable-history

You will need to enable a “-static” flag to compile a static bash.
First see where the line CFLAGS comes in:
grep -in ‘CFLAGS’ Makefile
emacs Makefile

Edit Makefile so that CFLAGS reads like this:

CFLAGS = -g -O2 -static[/code]

Now you can make and install the binaries.
make install

Test with `file /root/bashstatic/bin/bash`[/bash]

Attached:
bash:

Download “bash” bash.4.3.0(1)-release_arm-none-linux-gnueabi.zip – Downloaded 306 times – 1 MB


busybox:

Download “busybox” busybox.1.23.0.zip – Downloaded 160 times – 1 MB


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

How to change the login shell for Linux user

Use chsh command to change the user login shell. This determines the name of the user’s initial login command. A normal user may only change the login shell for her own account, the super user may change the login shell for any account.

Display list of shell

cat  /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/screen
/bin/tcsh
/usr/bin/tcsh

Change the user login shell to /bin/ksh for user www-data:

chsh -s /bin/bash www-data

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.