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
}

quarta-feira, 29 de janeiro de 2014

Afterinstall for Ubuntu

Tested on Ubuntu 12.04. Paste this into bash. You can uncomment and change the background image lines.

sudo apt-get install \
build-essential automake autoconf \
subversion subversion-tools git-all gitk \
cmake cmake-curses-gui doxygen doxygen-gui \
valgrind ddd kcachegrind indent ccache kdiff3 \
kdevelop kate kwrite emacs23-nox \
libboost-all-dev freeglut3-dev \
ant manpages-posix-dev \
haskell-platform ghc-mod \
smartmontools gsmartcontrol acpi dconf-tools \
rar p7zip lzop mmv tree htop dstat iotop \
wireshark nmap wavemon links lynx curl \
gparted ntfsprogs byobu mesa-utils \
lm-sensors openssh-server myspell-pt-pt \
texlive-full fig2ps kile audacity flac lame \
gnuplot inkscape dia gimp wine k3b \
flashplugin-installer mplayer2 ffmpeg &&
echo ========== Base ========== &&
mkdir -p ~/bin &&
echo ========== CCache ========== &&
ccache -M 10G &&
sudo rm -rfv /opt/ccache/bin/ &&
sudo mkdir -p /opt/ccache/bin/ &&
cd /opt/ccache/bin/ &&
sudo ln -s /usr/bin/ccache c++ &&
sudo ln -s /usr/bin/ccache cc &&
sudo ln -s /usr/bin/ccache g++ &&
sudo ln -s /usr/bin/ccache gcc &&
echo ========== Ack ========== &&
wget -c -T 20 -t 20 'http://betterthangrep.com/ack-standalone' -O ~/bin/ack &&
chmod 0755 ~/bin/ack &&
echo ========== Astyle ========== &&
wget -c -T 20 -t 20 'http://sourceforge.net/projects/astyle/files/astyle/astyle%202.01/astyle_2.01_linux.tar.gz/download' \
-O /tmp/astyle_2.01_linux.tar.gz &&
cd /tmp/ &&
tar xavf astyle_*_linux.tar.* &&
cd astyle/build/gcc/ &&
make -j5 &&
cp bin/astyle $HOME/bin/ &&
cd ../../.. &&
rm -rfv astyle &&
echo ========== Icons ========== &&
dconf write /desktop/unity/launcher/favorites "['nautilus-home.desktop', 'firefox.desktop', 'byobu.desktop', 'kde4-kdevelop.desktop']" &&
echo ========== Wallpaper ========== &&
#wget -c -T 20 -t 20 http://.../bg.png -O $HOME/bg.png &&
#dconf write /org/gnome/desktop/background/picture-uri "\"file://$HOME/bg.png\"" &&
dconf write /org/gnome/desktop/background/color-shading-type "'solid'" &&
dconf write /org/gnome/desktop/background/picture-options "'zoom'" &&
dconf write /org/gnome/desktop/background/primary-color "'#000000'" &&
dconf write /org/gnome/desktop/background/secondary-color "'#000000'" &&
echo ========== bashrc ========== &&
echo 'alias emacs="emacs -nw"' >> ~/.bash_aliases &&
echo 'alias mv="mv -iv "' >> ~/.bash_aliases &&
echo 'alias cp="cp -ivr "' >> ~/.bash_aliases &&
echo 'alias rm="rm -v "' >> ~/.bash_aliases &&
echo 'alias ls="ls --color "' >> ~/.bash_aliases &&
echo >> ~/.bashrc &&
echo 'export EDITOR="emacs -nw"' >> ~/.bashrc &&
echo 'export PATH=/opt/ccache/bin:$HOME/.cabal/bin:$HOME/bin:$PATH' >> ~/.bashrc &&
source ~/.bashrc &&
echo ========== SUCCESS ========== &&
cd