Bash Snippets

From Compilenix Wiki
Jump to: navigation, search

Generic

Convert to mkv via Ffmpeg

Deps:

  • ffmpeg
#!/bin/bash
in=`echo "$1" | cut -d'.' -f1`
inExt=`echo "$1" | cut -d'.' -f2`
inConcated="$in-concated.$inExt"
threads=8
ffmpegFlags="-threads $threads"

#rm -f input.txt
#for f in *.$inExt; do echo "file '$f'" >> input.txt; done

#ffmpeg -f concat -i input.txt -c copy "$inConcated"

ffmpeg -i "$1" $ffmpegFlags -threads $threads -f matroska -vcodec libx264 -acodec ac3 -ab 320k -ar 44100 -quality best -qmin 10 -qmax 30 -y "$in.mkv"
#ffmpeg -i "$inConcated" $ffmpegFlags -vcodec vp8 -acodec libvorbis -ab 192k -ar 44100 -quality best -qmin 10 -qmax 30 -y "$in.webm"

#rm input.txt

Convert to mp4 via Ffmpeg

Deps:

  • ffmpeg
#!/bin/bash
in=`echo "$1" | cut -d'.' -f1`
inExt=`echo "$1" | cut -d'.' -f2`
inConcated="$in-concated.$inExt"
threads=8
ffmpegFlags="-threads $threads"

#rm -f input.txt
#for f in *.$inExt; do echo "file '$f'" >> input.txt; done

#ffmpeg -f concat -i input.txt -c copy "$inConcated"

ffmpeg -i "$1" $ffmpegFlags -metadata title="$in" -f mp4 -vcodec h264 -acodec libvo_aacenc -map 0:0 -map 0:2 -ac 2 -quality best -qmin 1 -qmax 30 -y "$in.mp4"
ffmpeg -i "$1" $ffmpegFlags -f image2 -ss 00:01:00 -vframes 1 -y "$in.png"

#for i in *.mp4; do mv "$i" "${i%.*}.avi"; done
#for i in *; do mkdir "${i%%.*}"; mv "$i" "${i%%.*}"; cd "${i%%.*}"; /convertToMp4Ffmpeg.sh "$i";cd ..; done

#rm input.txt

Distro specifics

Debian (apt/aptitude)

List all currently installable updates[1]

Features:

  • line-by-line list of packages
  • currently installed version
  • availible version
  • colored highlighting
  • short description of the package

Deps:

  • apt-utils
  • dpkg
  • perl
#!/bin/sh
# Refernece: http://unix.stackexchange.com/questions/19470/list-available-updates-but-do-not-install-them#answer-75791

# each function used
function a { apt-get --just-print upgrade 2>&1 | perl -ne 'if (/Inst\s([\w,\-,\d,\.,~,:,\+]+)\s\[([\w,\-,\d,\.,~,:,\+]+)\]\s\(([\w,\-,\d,\.,~,:,\+]+)\)? /i) {print "$1 (\e[1;34m$2\e[0m -> \e[1;32m$3\e[0m)\n"}';}
function c { read input;dpkg -l ${input} | grep " ${input} " | awk '{$1=$2=$3=$4="";print $0}' | sed 's/^ *//';unset input;}

# the actual cmd, which uses the above defined functions
a | while read -r line; do echo -en "$line $(echo $line | awk '{print $1}' | c )\n"; done;

# the whole thing as one-liner
function c { read input;dpkg -l ${input} | grep " ${input} " | awk '{$1=$2=$3=$4="";print $0}' | sed 's/^ *//';unset input;};function a { apt-get --just-print dist-upgrade 2>&1 | perl -ne 'if (/Inst\s([\w,\-,\d,\.,~,:,\+]+)\s\[([\w,\-,\d,\.,~,:,\+]+)\]\s\(([\w,\-,\d,\.,~,:,\+]+)\)? /i) {print "$1 (\e[1;34m$2\e[0m -> \e[1;32m$3\e[0m)\n"}';};a | while read -r line; do echo -en "$line $(echo $line | awk '{print $1}' | c )\n"; done;

# the whole thing, base64 encoded
echo "ZnVuY3Rpb24gYyB7IHJlYWQgaW5wdXQ7ZHBrZyAtbCAke2lucHV0fSB8IGdyZXAgIiAke2lucHV0fSAiIHwgYXdrICd7JDE9JDI9JDM9JDQ9IiI7cHJpbnQgJDB9JyB8IHNlZCAncy9eICovLyc7dW5zZXQgaW5wdXQ7fTtmdW5jdGlvbiBhIHsgYXB0LWdldCAtLWp1c3QtcHJpbnQgZGlzdC11cGdyYWRlIDI+JjEgfCBwZXJsIC1uZSAnaWYgKC9JbnN0XHMoW1x3LFwtLFxkLFwuLH4sOixcK10rKVxzXFsoW1x3LFwtLFxkLFwuLH4sOixcK10rKVxdXHNcKChbXHcsXC0sXGQsXC4sfiw6LFwrXSspXCk/IC9pKSB7cHJpbnQgIiQxIChcZVsxOzM0bSQyXGVbMG0gLT4gXGVbMTszMm0kM1xlWzBtKVxuIn0nO307YSB8IHdoaWxlIHJlYWQgLXIgbGluZTsgZG8gZWNobyAtZW4gIiRsaW5lICQoZWNobyAkbGluZSB8IGF3ayAne3ByaW50ICQxfScgfCBjIClcbiI7IGRvbmU7Cg==" | base64 -d | bash

Example output:

base-files (6.0squeeze8 -> 6.0squeeze10) base system miscellaneous files
libssl-dev (0.9.8o-4squeeze17 -> 0.9.8o-4squeeze18) development libraries, header files and documentation
libssl0.9.8 (0.9.8o-4squeeze17 -> 0.9.8o-4squeeze18) shared libraries
wget (1.12-2.1 -> 1.12-2.1+deb6u1) files from the web
exim4-config (4.72-6+squeeze3 -> 4.72-6+squeeze4) for the Exim MTA (v4)
exim4-base (4.72-6+squeeze3 -> 4.72-6+squeeze4) files for all Exim MTA (v4) packages
exim4-daemon-light (4.72-6+squeeze3 -> 4.72-6+squeeze4) Exim MTA (v4) daemon
exim4 (4.72-6+squeeze3 -> 4.72-6+squeeze4) to ease Exim MTA (v4) installation
libclamav6 (0.97.8+dfsg-1~squeeze1 -> 0.98.1+dfsg-1+deb6u3) utility for Unix - library
clamav-base (0.97.8+dfsg-1~squeeze1 -> 0.98.1+dfsg-1+deb6u3) utility for Unix - base package
clamav-freshclam (0.97.8+dfsg-1~squeeze1 -> 0.98.1+dfsg-1+deb6u3) utility for Unix - virus database update utility
clamav (0.97.8+dfsg-1~squeeze1 -> 0.98.1+dfsg-1+deb6u3) utility for Unix - command-line interface
libdbi-perl (1.612-1 -> 1.612-1+deb6u1) Database Interface (DBI)
librsvg2-2 (2.26.3-1 -> 2.26.3-1+deb6u2) renderer library for SVG files (runtime)
openssl (0.9.8o-4squeeze17 -> 0.9.8o-4squeeze18) Socket Layer (SSL) binary and related cryptographic tools

References