quarta-feira, 28 de maio de 2014

Afterinstall for Ubuntu 14.04 LTS

First! Make sure you have the fastest possible server configured: System Settings -> Software & Updates -> Download from: Other... -> Select Best Server -> Choose Server
Then open a terminal and... (you might want to copy this in several smaller parts, the copy buffer is not large enough)
Then go to System Settings and make sure everything is to your liking. You can change the screen locking timeouts, under Details set the default application for audio and video to SMPlayer and so on.



If you have a laptop and battery concerns (take a look at http://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html):
sudo add-apt-repository ppa:linrunner/tlp &&
sudo apt-get update &&
sudo apt-get install tlp tlp-rdw &&
sudo tlp start



If you have an SSD drive, add
,discard
to the options of your EXT4 partition in /etc/fstab. Also in /etc/fstab, add these lines so that the temporary directories are mounted in RAM:
tmpfs /tmp     tmpfs defaults,noatime,mode=1777,size=10% 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777,size=10% 0 0
You can also finetune swappines:
sudo sh -c "echo 'vm.swappiness=1' >> /etc/sysctl.d/99-sysctl.conf" &&
sudo sh -c "echo 'vm.vfs_cache_pressure=50' >> /etc/sysctl.d/99-sysctl.conf"

C/C++ cleanup script

#!/bin/bash

DIRS="."
SOURCE_FILES=`find -L $DIRS -iname "*\.[ch]pp" -or -iname "*\.[ch]" | grep -v "/\."`
HEADER_FILES=`find -L $DIRS -iname "*\.hpp" -or -iname "*\.h" | grep -v "/\."`


# astyle
if [ "$(astyle -V 2>&1)" != "Artistic Style Version 2.04" ]; then
  echo "Please update astyle to version 2.04:"
  echo
  echo 'mkdir -p $HOME/bin/ &&'
  echo 'cd /tmp &&'
  echo 'wget -c -T 20 -t 20 -O "astyle_2.04_linux.tar.gz" \'
  echo '"http://sourceforge.net/projects/astyle/files/astyle/astyle%202.04/astyle_2.04_linux.tar.gz/download" &&'
  echo 'tar xavf astyle_*_linux.tar.* &&'
  echo 'cd astyle/build/gcc/ &&'
  echo 'make -j5 &&'
  echo 'cp bin/astyle $HOME/bin/ &&'
  echo 'cd ../../.. &&'
  echo 'rm -rfv astyle &&'
  echo 'cd'
  echo
  exit 2
fi
astyle -s2 -A8 -C -S -N -L -w -y -p -d -U -c -E -j -H -k1 -Y $SOURCE_FILES


# Empty lines
echo At least one empty line at and of files
sed -n '1x;1!H;${x;s/$/\n/;p}' -i $SOURCE_FILES
echo At least three empty lines between functions
echo Only one empty line before \#include
echo No empty lines at beginning of blocks
echo No empty lines at end of blocks
echo No empty lines at beginning of files
echo One empty line at end of files
sed -n '1x;1!H;${x;s/\([^\n]\)\n\{2,3\}\([^\n]\)/\1\n\n\n\n\2/g;s/\n\n\n*#include/\n\n#include/g;s/{\(\n *\)*\n/{\n/g;s/\(\n *\)*\n\( *\)}/\n\2}/g;s/^\n*//;s/\n*$//;p}' -i $SOURCE_FILES
echo Only one empty line before \#ifndef in hpps
echo Only one empty line before \#endif in hpps
sed -n '1x;1!H;${x;s/\n\n\n*#ifndef/\n\n#ifndef/g;s/\n\n\n*#endif/\n\n#endif/g;p}' -i $HEADER_FILES


# remove spaces in empty lines
astyle -s2 -A8 -C -S -N -L -w -y -p -d -U -c -j -H -k1 -Y $SOURCE_FILES


# remove garbage
find -L -name "*~" -print -delete
find -L -name "*\.orig" -print -delete
find -L -name "#*#" -print -delete

Multiple Live CDs in USB drive

Create two partitions in the USB drive:
  • First: NTFS or FAT32, depending on what you want, at the end of the drive;
  • Second: FAT32 (because it supports the hidden flag), slightly larger than the sum of your ISOs, at the beginning of the drive.
$ sudo parted /dev/sde
GNU Parted 2.3
Using /dev/sde
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: SanDisk Cruzer Switch (scsi)
Disk /dev/sde: 32,0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 2      1049kB  3147MB  3146MB  primary  fat32        boot, hidden
 1      3147MB  32,0GB  28,9GB  primary  ntfs

Then take a look at:
The idea is to:
  • Install grub with:
    grub-install --force --no-floppy --boot-directory=/mnt/USB/boot /dev/sdx
  • Copy your images over there;
  • Create a grub.conf

I created mine with 3 ISOs:
  • ubuntu-14.04-desktop-amd64.iso
  • systemrescuecd-x86-4.2.0.iso
  • memtest86+-5.01.bin
My grub.conf ended up like this:
set default=0

menuentry "Ubuntu 14.04 64 - Try" {
 set isofile="/ubuntu-14.04-desktop-amd64.iso"
 loopback loop $isofile
 linux (loop)/casper/vmlinuz.efi iso-scan/filename=$isofile noeject noprompt file=/cdrom/preseed/ubuntu.seed boot=casper --
 initrd (loop)/casper/initrd.lz
}

menuentry "Ubuntu 14.04 64 - Install" {
 set isofile="/ubuntu-14.04-desktop-amd64.iso"
 loopback loop $isofile
 linux (loop)/casper/vmlinuz.efi iso-scan/filename=$isofile noeject noprompt file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity --
 initrd (loop)/casper/initrd.lz
}

menuentry "Ubuntu 14.04 64 - Check" {
 set isofile="/ubuntu-14.04-desktop-amd64.iso"
 loopback loop $isofile
 linux (loop)/casper/vmlinuz.efi iso-scan/filename=$isofile noeject noprompt boot=casper integrity-check --
 initrd (loop)/casper/initrd.lz
}


menuentry "SystemRescueCd 64 - Cached" {
 set isofile="/systemrescuecd-x86-4.2.0.iso"
 loopback loop $isofile
 linux (loop)/isolinux/rescue64 isoloop=$isofile docache setkmap=us
 initrd (loop)/isolinux/initram.igz
}

menuentry "SystemRescueCd 32" {
 set isofile="/systemrescuecd-x86-4.2.0.iso"
 loopback loop $isofile
 linux (loop)/isolinux/rescue32 isoloop=$isofile nomodeset
 initrd (loop)/isolinux/initram.igz
}


menuentry "Memtest 86+" {
 linux16 /memtest86+-5.01.bin
}