Linux tips

Just a small collection of linux/gnu tips. Primarily terminal commands for stuff you do on a regurely basis, but not often enough to really remember it.

Figuring out what is in Ubuntu installation tasks

Ubuntu Packages

When installing linux packages it is difficult to know which packages in installed with what tasks. For instance: What packages "Ubuntu Basic Server" contain?

if you run the command:
tasksel --list-tasks

you will find that the "Basic Ubuntu Server" task is named "server".

If you run

tasksel --task-packages server

you will get a list of the packages in this task.

Check Linux version

lsb_release -a

Enable bash auto-completion

In order to enable the autocompletion, edit /etc/bash.bashrc

Uncomment the following section:

# enable bash completion in interactive shells
#if [ -f /etc/bash_completion ]; then
#. /etc/bash_completion
#fi  

 

Remember that all users must have executable rights to this file, otherwise it will only work for root. Also, the filepaths may be different for differnt distros.

 

Delete user

the -r switch removes the home directory, which would otherwise have to be removed manually

userdel -r username

Get a annoying Brother 7070dw printer working.

The problem is that brother does not officially support postscript on the cheaper printers. Also, their own drivers are not very good and requires loads of headaches. Luckily postscript is supported somewhat.

When installing the printer, setup as normal Brother printer, but select "Brother 7045N" in combination with the driver "Generic PCL 6/PCL XL Printer - CUPS+Gutenprint v5.2.10-pre2". This works ok.

Removing sound jitter from Intel Z97/H97 and ALC1150 audio chipsets in Ubuntu 14.04

If the sound is stuttering, it is because this specific chipset has not gotten setup definition in ubuntu 14.04. The workaround is to create a modprobe.d file with the required settings.

echo "options snd-hda-intel vid=8086 pid=8ca0 snoop=0" | sudo tee /etc/modprobe.d/fix-sound-intel97.conf 

 

Get bluetooth working in Ubuntu LTS 14.04

Pair using normal means, In bluetooth manager, set as A2DP audio sink

thereafter add following to /etc/pulse/default.pa

 

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

 

This makes bluetooth available to the pulse audio manager. Restart with pulseaudio -k followed by pulseaudio -D Now go to "Configuration" in Volume Control (Pulse Audio Manager) and change the profile from your newly found bluetooth headset to "A2DP"

Backing up a website using lftp

Somethimes you need to backup a website. This site was, for instance, compromised through a fault in Joomla a few years ago. It took me ages to get it up as I did not have a backup.

There a loads of tools that can do this. Most notorious are wget and lftp. wget is very good at fetching websites. It is, however primarily made for websites, and that means that some of the switches that should make your life easier unfortunately only works in the webworld. Therefore, i generally prefer lftp, as it pretty much handles all protocols.

Sites can easily be backed up from bash using:
lftp ftp://${remotehost} -u ${user},${password} -e "mirror --verbose ${remotedir} ${localbackupdir}

Create user, add homedir, grant access and add to sudoers

 as root do:

useradd username -m (-m switch creates homedir)

passwd username

sudo adduser username sudo

Use Rsync to backup directories

normal rsync for backup looks like this:
rsync -c -r -t -p -o -g -v -l -s --progress --delete /mnt/Stuff/ /mnt/Stuff2

switches are:
-c skip based on checksum, not mod-time & size
-r recurse into directories
-t preserve modification times
-p preserve permissions
-o preserve owner (super-user only)
-g preserve group
-v increase verbosity
-l copy symlinks as symlinks
-s (protected-args) do not interprent special chars like $ and ~ in shell, but let rsync do it on remote host

--progress show progress during transfer
--delete delete files that are in dest dir but not in source dir

Note that the trailing / in paths means copy files IN this directory.
If it had not been there, the directory would be included.
This would result in copying to /mnt/Stuff2/Stuff

Trailing slashes are ignored in destination folder.

 

 

Java

To install java jdk using apt-get:

sudo apt-get install openjdk-7-jdk

If Oracle JDK is needed:

sudo apt-get install oracle-java7-installer

Manage default java version:

sudo update-alternatives --config java

Can also be done for javac:

sudo update-alternatives --config javac

Setting JAVA_HOME environment variable.

  1. Get path to java: sudo update-alternatives --config javac
  2. Edit /etc/environment: sudo nano /etc/environment
  3. Add Line: JAVA_HOME="YOUR_PATH"
  4. Save and afterwards reload environment variables using: source /etc/environment
  5. Test by running: echo $JAVA_HOME

Mono Developer

to install mono along with mono developer from repositories, use:

sudo apt-get install mono-mcs libgtk2.0-cil libgtksourceview2-2.0-cil monodevelop monodoc-base mono-tools-gui mono-complete

 

Ubuntu 14.04 on macbook air '11 (2013)

When installing, it becomes clear that the WiFi does not function perfectly. Mine could list the networks, but not connect to them. This is a but that had been corected for my NIC (Broadwell BCM43224 808.11a/b/g/n rev 0.1) ... check you have the same NIC before trying (write lspci -nn |grep 0280 .. if your pci.id is 14e4:4353 you have the same NIC)

This was corrected by connecting to a nonencrypted wifi over my phone and running

apt-get update

apt-get install linux-headers-generic

apt-get install --reinstall bcmwl-kernel-source

modprobe wl

... kind of a chicken or egg thing.. could not get the new config for the nic because there was no connection to the nic...

Android tips

When ever installing android sdk on debian/ubuntu based systems, additional libraries must be added, as some parts of the 64bit package is actually using i386 calls. (adb for instance), All functions should work just adding the i386 architecture.aapt(which is a packing tool) does, however require azlib, which is dependend on the three last libraries.

sudo dpkg --add-architecture i386

sudo apt-get update

sudo apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386

If this is not added,  you will get a bunch of errors stating a lot of executables does not exist.

Finally installlibgl1-mesa-dev. This is an OpenGL library, and is needed to render some simulators (avd's) correctly.

sudo apt-get install libgl1-mesa-dev


In order to debug on the phone instead of the emulator, a Udev rule must be added, and the following text added in it

sudo /etc/udev/rules.d/51-android.rules

SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666"

SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666"

 

after this run the following commands in order to reload udev rules

sudo udevadm control --reload-rules

sudo service udev restart

The vendorid is different for different makes of phones, and can be seen here: USB Vendor IDs. Note that your vendorid may change if you install a ROM. Mine used to be 0bb4 (HTC), but changed to 18d1. Hence the two lines in the udev rules. You can always perform a lsusb to check vendorid.

After this reboot the computer. You should be able to use adb devices

to check if the device works.