[流水帳] Reinstalling 16.06

記一次系統重裝

Backup

Folders to back up

Ubuntu Side

  • ~/Documents
  • ~/workspace
  • ~/dotfiles
  • ~/.emacs.d
  • ~/.ipython/kernels

Windows Side

  • Videos
  • Pictures

Other files

  • python installation
  • Firefox bookmarks (Firefox sync takes care of all these)
  • Firefo.x saved passwords
  • Atom packages
  • Atom snippets

Prepare 16.04 installation

I ended up wiping out the Windows installation.

Set up system

  • Firefox (Comes prepackaged with it)
  • Dropbox
  • Atom (with packages)
  • Emacs (with package)
  • Scala
  • DB Browser
  • Haroopad
  • Skype
  • KMPlayer

Input method

  • fcitx
    This page talks about how to config system to use fcitx

  • Use emacs key
    Use Tweak Tool (found at Software Store), go to Typing > Caplocks Behavior > select “as additional Ctrl”

  • in the System setting Keyboard > shortcuts > Typing, Disable Ctrl+Space for switching input methods, as this conflicts with emacs’ C-SPACE selection key-binding.

Switch default shell from bash > zsh

  1. install zsh in package manager
  2. sudo usermod -s /bin/zsh $USER

Python environment

Turns out, most system modules are now in python3, unlike in Ubuntu 15.10 when they were under python2. So now it’s the pip3 that gets all the mess. Good thing is the system comes pre-packaged with python3.5.

Problem: The packaged python doesn’t contain

  • pip (pip2, pip3)
    go to pip website, download get_pip.py and run it with sudo for both python2 and python3. This will install pip2 and pip3 respectively. I don’t know whether the order matters, but I ran 2 and then 3.
  • virtualenv
    Find python-virtualenv package in Synaptic
  • Also find python-dev and python3-dev package in Synaptic, because some python libraries require compiling with Python.h.
  • Matplotlib requires the dev portions of libfreetype and libpng to be installed

Permission Problem

Turns out the mobile hard drive I used to backup my files is NTFS or something and this messed up all the permission codes (All become 777)…

I wrote a script to recursively change all the directory and executable files permission to 755, all the normal file permission to 644. The way it differentiates executable files and non-executable is first by extension name: those ending in bin, sh, exe are usually executable files. The trickier part is those executables without extension, which is a norm under Linux. To tackle those types of files (and differentiatbe them from normal files without extension like Makefile) I leveraged the file system program, which will usually tell you whether something is an executable binary. However it also has the bad habbit of saying executalbe on python script file, even those without shebang. Therefore I can’t trust it completely.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python3.5
import os
import sys
import subprocess
from subprocess import run # >= py3.5
file_uuid = 0o664
exec_uuid = 0o755
dir_uuid = 0o755
exec_file_types = [
"exe", "sh", "bin",
]
path = os.getcwd()
if len(sys.argv) > 1:
path = sys.argv[1]
for folder, dirs, files in os.walk(path):
for d in dirs:
p = os.path.join(folder, d)
os.chmod(p, dir_uuid)
for f in files:
p = os.path.join(folder, f)
ext = os.path.splitext(f)[1][1:] # skip the dot
if ext:
uuid = exec_uuid if ext in exec_file_types else file_uuid
else: # there is no extension, this may be a executable file
res = run(["file", p], stdout=subprocess.PIPE)
res_str = res.stdout.decode()
uuid = exec_uuid if "executable" in res_str else file_uuid
os.chmod(p, uuid)