shell

Moving a Repository from Bitbucket to GitHub

Some people have asked me how they can move a repository from Bitbucket to Github (or vice versa). To know how to do it we need to understand Git’s remote repositories. Remote repositories are versions of your project that are hosted on the Internet or network somewhere (you can have several of them).

First, let’s clone the Bitbucket repository:

$ git clone https://bitbucket.org/rafacas/test.git
Cloning into ’test'...
remote: Counting objects: 124, done.
remote: Compressing objects: 100% (120/120), done.
remote: Total 124 (delta 42), reused 0 (delta 0)
Receiving objects: 100% (124/124), 1.31 MiB | 541.00 KiB/s, done.
Resolving deltas: 100% (42/42), done.
Checking connectivity... done.

To see which remote servers you have configured, you can run the git remote command. It lists the shortnames of each remote handle you have specified. After cloning your repository you will see origin (that is the default name Git gives to the server you cloned from):

$ cd test
$ git remote
origin

If you use the -v option it will show the URLs that Git has stored for the shortname to be used when reading and writing to that remote:

$ git remote -v
origin    https://bitbucket.org/rafacas/test.git (fetch)
origin    https://bitbucket.org/rafacas/test.git (push)

Right now origin (our only remote repository) is pointing to Bitbucket, so we could create another remote repository called github and point it to the Github repository we want to move it to. After creating it you could work with both repositories.

Because what we really want is moving it and stop using our original remote repository we should change where origin points to.

We will start renaming origin to bitbucket:

$ git remote rename origin bitbucket

If we want to check it has been renamed we will type:

$ git remote
bitbucket

Then we will add a new remote repository called origin that points to the Github repository we want to move it to:

$ git remote add origin https://github.com/rafacas/test.git

Now we have two remote repositories (bitbucket and origin):

$ git remote
bitbucket
origin

We can check where they point to:

$ git remote -v
bitbucket     https://bitbucket.org/rafacas/test.git (fetch)
bitbucket     https://bitbucket.org/rafacas/test.git (push)
origin     https://github.com/rafacas/test.git (fetch)
origin     https://github.com/rafacas/test.git (push)

Then we will push our master branch to the origin remote repository (Github):

$ git push origin master

Once you check the push has been successful you can delete the remote bitbucket repository:

$ git remote rm bitbucket
$ git remote -v
origin     https://github.com/rafacas/test.git (fetch)
origin     https://github.com/rafacas/test.git (push)

You can follow the same process if you want to move a repository from Github to Bitbucket. Just be careful with the repository URLs.

References

shell

Editing Binary Files

In a previous post we learnt how to back up the MBR of a hard disk in a file called mbr.img. That file has the first 512 bytes (the first sector) of the hard disk.

One way to see the content of a binary file is dumping it to hexadecimal.

In Linux the xxd command makes a hex dump:

$ xxd mbr.img
0000000: eb63 9010 8ed0 bc00 b0b8 0000 8ed8 8ec0  .c..............
0000010: fbbe 007c bf00 06b9 0002 f3a4 ea21 0600  ...|.........!..
0000020: 00be be07 3804 750b 83c6 1081 fefe 0775  ....8.u........u
0000030: f3eb 16b4 02b0 01bb 007c b280 8a74 018b  .........|...t..
0000040: 4c02 cd13 ea00 7c00 00eb fe00 0000 0000  L.....|.........
0000050: 0000 0000 0000 0000 0000 0080 0100 0000  ................
0000060: 0000 0000 fffa 9090 f6c2 8074 05f6 c270  ...........t...p
0000070: 7402 b280 ea79 7c00 0031 c08e d88e d0bc  t....y|..1......
0000080: 0020 fba0 647c 3cff 7402 88c2 52bb 1704  . ..d|<.t...R...
0000090: f607 0374 06be 887d e817 01be 057c b441  ...t...}.....|.A
00000a0: bbaa 55cd 135a 5272 3d81 fb55 aa75 3783  ..U..ZRr=..U.u7.
00000b0: e101 7432 31c0 8944 0440 8844 ff89 4402  ..t21..D.@.D..D.
00000c0: c704 1000 668b 1e5c 7c66 895c 0866 8b1e  ....f..\|f.\.f..
00000d0: 607c 6689 5c0c c744 0600 70b4 42cd 1372  `|f.\..D..p.B..r
00000e0: 05bb 0070 eb76 b408 cd13 730d 5a84 d20f  ...p.v....s.Z...
00000f0: 83d0 00be 937d e982 0066 0fb6 c688 64ff  .....}...f....d.
0000100: 4066 8944 040f b6d1 c1e2 0288 e888 f440  @f.D...........@
0000110: 8944 080f b6c2 c0e8 0266 8904 66a1 607c  .D.......f..f.`|
0000120: 6609 c075 4e66 a15c 7c66 31d2 66f7 3488  f..uNf.\|f1.f.4.
0000130: d131 d266 f774 043b 4408 7d37 fec1 88c5  .1.f.t.;D.}7....
0000140: 30c0 c1e8 0208 c188 d05a 88c6 bb00 708e  0........Z....p.
0000150: c331 dbb8 0102 cd13 721e 8cc3 601e b900  .1......r...`...
0000160: 018e db31 f6bf 0080 8ec6 fcf3 a51f 61ff  ...1..........a.
0000170: 265a 7cbe 8e7d eb03 be9d 7de8 3400 bea2  &Z|..}....}.4...
0000180: 7de8 2e00 cd18 ebfe 4752 5542 2000 4765  }.......GRUB .Ge
0000190: 6f6d 0048 6172 6420 4469 736b 0052 6561  om.Hard Disk.Rea
00001a0: 6400 2045 7272 6f72 0d0a 00bb 0100 b40e  d. Error........
00001b0: cd10 ac3c 0075 f4c3 de57 0900 0000 8020  ...<.u...W.....
00001c0: 2100 83fe ffff 0008 0000 0018 d205 00fe  !...............
00001d0: ffff 82fe ffff 0020 d205 00a0 6501 00fe  ....... ....e...
00001e0: ffff 83fe ffff 00c0 3707 0090 e415 0000  ........7.......
00001f0: 0000 0000 0000 0000 0000 0000 0000 55aa  ..............U.

The command od can also be used. It dumps files in octal and other formats (hexadecimal, decimal -signed and unsigned-, floating point and ASCII):

$ od -A x -t x1z -v mbr.img
000000 eb 63 90 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0  >.c..............<
000010 fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00  >...|.........!..<
000020 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75  >....8.u........u<
000030 f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 01 8b  >.........|...t..<
000040 4c 02 cd 13 ea 00 7c 00 00 eb fe 00 00 00 00 00  >L.....|.........<
000050 00 00 00 00 00 00 00 00 00 00 00 80 01 00 00 00  >................<
000060 00 00 00 00 ff fa 90 90 f6 c2 80 74 05 f6 c2 70  >...........t...p<
000070 74 02 b2 80 ea 79 7c 00 00 31 c0 8e d8 8e d0 bc  >t....y|..1......<
000080 00 20 fb a0 64 7c 3c ff 74 02 88 c2 52 bb 17 04  >. ..d|<.t...R...<
000090 f6 07 03 74 06 be 88 7d e8 17 01 be 05 7c b4 41  >...t...}.....|.A<
0000a0 bb aa 55 cd 13 5a 52 72 3d 81 fb 55 aa 75 37 83  >..U..ZRr=..U.u7.<
0000b0 e1 01 74 32 31 c0 89 44 04 40 88 44 ff 89 44 02  >..t21..D.@.D..D.<
0000c0 c7 04 10 00 66 8b 1e 5c 7c 66 89 5c 08 66 8b 1e  >....f..\|f.\.f..<
0000d0 60 7c 66 89 5c 0c c7 44 06 00 70 b4 42 cd 13 72  >`|f.\..D..p.B..r<
0000e0 05 bb 00 70 eb 76 b4 08 cd 13 73 0d 5a 84 d2 0f  >...p.v....s.Z...<
0000f0 83 d0 00 be 93 7d e9 82 00 66 0f b6 c6 88 64 ff  >.....}...f....d.<
000100 40 66 89 44 04 0f b6 d1 c1 e2 02 88 e8 88 f4 40  >@f.D...........@<
000110 89 44 08 0f b6 c2 c0 e8 02 66 89 04 66 a1 60 7c  >.D.......f..f.`|<
000120 66 09 c0 75 4e 66 a1 5c 7c 66 31 d2 66 f7 34 88  >f..uNf.\|f1.f.4.<
000130 d1 31 d2 66 f7 74 04 3b 44 08 7d 37 fe c1 88 c5  >.1.f.t.;D.}7....<
000140 30 c0 c1 e8 02 08 c1 88 d0 5a 88 c6 bb 00 70 8e  >0........Z....p.<
000150 c3 31 db b8 01 02 cd 13 72 1e 8c c3 60 1e b9 00  >.1......r...`...<
000160 01 8e db 31 f6 bf 00 80 8e c6 fc f3 a5 1f 61 ff  >...1..........a.<
000170 26 5a 7c be 8e 7d eb 03 be 9d 7d e8 34 00 be a2  >&Z|..}....}.4...<
000180 7d e8 2e 00 cd 18 eb fe 47 52 55 42 20 00 47 65  >}.......GRUB .Ge<
000190 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 65 61  >om.Hard Disk.Rea<
0001a0 64 00 20 45 72 72 6f 72 0d 0a 00 bb 01 00 b4 0e  >d. Error........<
0001b0 cd 10 ac 3c 00 75 f4 c3 de 57 09 00 00 00 80 20  >...<.u...W..... <
0001c0 21 00 83 fe ff ff 00 08 00 00 00 18 d2 05 00 fe  >!...............<
0001d0 ff ff 82 fe ff ff 00 20 d2 05 00 a0 65 01 00 fe  >....... ....e...<
0001e0 ff ff 83 fe ff ff 00 c0 37 07 00 90 e4 15 00 00  >........7.......<
0001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa  >..............U.<
000200

The -A x options displays the address radix in hexadecimal; the -t option selects the output format: x for hexadecimal, 1 is the number of bytes per integer and z displays printable characters at the end of each output line.

In OS X the command used is hexdump (od is also in the system):

$ hexdump -C mbr.img
00000000  eb 63 90 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |.c..............|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 80 01 00 00 00  |................|
00000060  00 00 00 00 ff fa 90 90  f6 c2 80 74 05 f6 c2 70  |...........t...p|
00000070  74 02 b2 80 ea 79 7c 00  00 31 c0 8e d8 8e d0 bc  |t....y|..1......|
00000080  00 20 fb a0 64 7c 3c ff  74 02 88 c2 52 bb 17 04  |. ..d|<.t...R...|
00000090  f6 07 03 74 06 be 88 7d  e8 17 01 be 05 7c b4 41  |...t...}.....|.A|
000000a0  bb aa 55 cd 13 5a 52 72  3d 81 fb 55 aa 75 37 83  |..U..ZRr=..U.u7.|
000000b0  e1 01 74 32 31 c0 89 44  04 40 88 44 ff 89 44 02  |..t21..D.@.D..D.|
000000c0  c7 04 10 00 66 8b 1e 5c  7c 66 89 5c 08 66 8b 1e  |....f..\|f.\.f..|
000000d0  60 7c 66 89 5c 0c c7 44  06 00 70 b4 42 cd 13 72  |`|f.\..D..p.B..r|
000000e0  05 bb 00 70 eb 76 b4 08  cd 13 73 0d 5a 84 d2 0f  |...p.v....s.Z...|
000000f0  83 d0 00 be 93 7d e9 82  00 66 0f b6 c6 88 64 ff  |.....}...f....d.|
00000100  40 66 89 44 04 0f b6 d1  c1 e2 02 88 e8 88 f4 40  |@f.D...........@|
00000110  89 44 08 0f b6 c2 c0 e8  02 66 89 04 66 a1 60 7c  |.D.......f..f.`||
00000120  66 09 c0 75 4e 66 a1 5c  7c 66 31 d2 66 f7 34 88  |f..uNf.\|f1.f.4.|
00000130  d1 31 d2 66 f7 74 04 3b  44 08 7d 37 fe c1 88 c5  |.1.f.t.;D.}7....|
00000140  30 c0 c1 e8 02 08 c1 88  d0 5a 88 c6 bb 00 70 8e  |0........Z....p.|
00000150  c3 31 db b8 01 02 cd 13  72 1e 8c c3 60 1e b9 00  |.1......r...`...|
00000160  01 8e db 31 f6 bf 00 80  8e c6 fc f3 a5 1f 61 ff  |...1..........a.|
00000170  26 5a 7c be 8e 7d eb 03  be 9d 7d e8 34 00 be a2  |&Z|..}....}.4...|
00000180  7d e8 2e 00 cd 18 eb fe  47 52 55 42 20 00 47 65  |}.......GRUB .Ge|
00000190  6f 6d 00 48 61 72 64 20  44 69 73 6b 00 52 65 61  |om.Hard Disk.Rea|
000001a0  64 00 20 45 72 72 6f 72  0d 0a 00 bb 01 00 b4 0e  |d. Error........|
000001b0  cd 10 ac 3c 00 75 f4 c3  de 57 09 00 00 00 80 20  |...<.u...W..... |
000001c0  21 00 83 fe ff ff 00 08  00 00 00 18 d2 05 00 fe  |!...............|
000001d0  ff ff 82 fe ff ff 00 20  d2 05 00 a0 65 01 00 fe  |....... ....e...|
000001e0  ff ff 83 fe ff ff 00 c0  37 07 00 90 e4 15 00 00  |........7.......|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200

The option -C is the Canonical hex+ASCII display. It displays the input offset in hexadecimal, followed by sixteen space-separated, two column, hexadecimal bytes, followed by the same sixteen bytes in %_p format enclosed in ``|'' characters.

Those commands also allow more options like choosing a specific range of bytes from the file. For example, to get the boot signature in the MBR we need 2 bytes, the bytes 510 (0x01FE) and 511 (0x01FF) which content should be 0x55AA:

In Linux:

$ xxd -s 510 -l 2 mbr.img
00001fe: 55aa                                     U.

or

$ od -A x -t x1z -j 510 -N 2 mbr.img
0001fe 55 aa                                            >U.<
000200

In OS X:

$ hexdump -C -s 510 -n 2 mbr.img
000001fe  55 aa                                             |U.|
00000200

Although there are some specific hex editors we are real commandliners so we only need a text editor like vim or emacs, because we love the terminal :)

In vim we can convert files to hex using the filter

:%!xxd

and

:%!xxd -r

to convert back. The only problem is that using an external program to do this is error-prone so I recommend the Improved hex editing article to easily enter and leave hex mode in vim.

In emacs there is a special major mode for editing binary files: Hexl mode. To use it, type:

M-x hexl-find-file

instead of C-x C-f to open the file. This command converts the file's contents to hexadecimal and lets you edit the translation. When you save the file, it is converted automatically back to binary.

You can also use:

M-x hexl-mode

to translate an existing buffer into hex.

More info about editing binary files in emacs.

Have fun editing binary files :)

shell

Find Integrated Lights-Out IPs in a network

Integrated Lights-Out, or iLO, is a proprietary embedded server management technology by Hewlett-Packard which provides out-of-band management facilities. The physical connection is an Ethernet port that can be found on most Proliant servers of the 300 and above series.

It is very useful because it allows to perform activities on an HP server from a remote location. The iLO card has a separate network connection (and its own IP address) to which one can connect via HTTPS.

Some of the options I have used are:

  • Reset the server (very useful when the server doesn’t respond anymore via the normal network card).
  • Power-up the server (possible to do this even if the server is shut down).
  • Remote console.

I was configuring a cluster remotely once but I didn’t have the iLO IP of the servers so I wrote a script that finds all the iLO IPs in a network. You can find it in the find-iLOs repository of my Github account.

Below is an example of how to use it:

$ ./find_iLOs 192.168.1.0/24
  IP Address   | iLO Type | iLO FW |   Server Model    | Server S/N
---------------|----------|--------|-------------------|------------
192.168.1.41   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2047JB9Y
192.168.1.42   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2044GZ0Z
192.168.1.43   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2044GZ1S
192.168.1.44   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2047JB9D
192.168.1.45   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2047JB9H
192.168.1.46   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2047JBBP
192.168.1.47   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2044GZ1J
192.168.1.48   |  iLO-2   | 2.09   | ProLiant DL360 G6 | ABJ005004R
192.168.1.61   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2047JB9N
192.168.1.62   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2047JB9M
192.168.1.63   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2050KGL5
192.168.1.64   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2050KGL9
192.168.1.65   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2047JB94
192.168.1.66   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2050KGLJ
192.168.1.67   |  iLO-3   | 1.28   | ProLiant DL380 G7 | AB2050KGL8
192.168.1.101  |  iLO-3   | 1.20   | ProLiant DL380 G7 | HC8108F1AA
192.168.1.102  |  iLO-3   | 1.20   | ProLiant DL380 G7 | HC8108F1A7
192.168.1.104  |  iLO-1   | 1.82   | ProLiant DL360 G4 | HCR532V000
192.168.1.106  |  iLO-2   | 2.07   | ProLiant DL360 G5 | ABM841AAVY
192.168.1.107  |  iLO-2   | 2.07   | ProLiant DL380 G5 | ABD7172C97
192.168.1.109  |  iLO-2   | 2.06   | ProLiant DL380 G5 | ABC9093RTS
192.168.1.110  |  iLO-2   | 2.06   | ProLiant DL380 G5 | ABD9093RY5
192.168.1.111  |  iLO-2   | 2.06   | ProLiant DL380 G5 | ABC90615Z7
192.168.1.112  |  iLO-2   | 2.05   | ProLiant DL360 G5 | ABK803A5WB
192.168.1.113  |  iLO-2   | 2.06   | ProLiant DL360 G6 | ABL93805BN
192.168.1.114  |  iLO-2   | 2.05   | ProLiant DL360 G6 | ABJ9230107
192.168.1.115  |  iLO-2   | 2.05   | ProLiant DL360 G6 | ABN94303T2
192.168.1.116  |  iLO-2   | 2.05   | ProLiant DL360 G6 | ABJ93805AN
192.168.1.117  |  iLO-2   | 2.07   | ProLiant DL360 G6 | ABJ91900RR
192.168.1.126  |  iLO-2   | 2.05   | ProLiant DL380 G5 | ABC7515KS6

30 iLOs found on 192.168.1.0/24.

Besides the iLO IP, it also displays the iLO type, iLO firmware version, server model and server serial number.

References

shell

Backup & Restore the Master Boot Record

Some days ago I had to recover the Master Boot Record (MBR) of a damaged hard disk.

The MBR is the first 512 bytes of a storage device. It contains an operating system boot loader and the storage device’s partition table.

If you need to make a backup of the MBR type the following command:

dd if=/dev/sda of=/root/mbr.img bs=1 count=512

You only have to change sda with the device name that correponds to your hard disk.

To restore it:

dd if=/root/mbr.img of=/dev/sda bs=1 count=512

And as before, change sda with the device name that corresponds to the hard disk you are going to restore the MBR to.

The partition table has a size of 64 bytes and it starts at position 0x01BE (446) so if you want to only restore it:

dd if=/temp/mbr.img of=/dev/sda skip=446 seek=446 bs=1 count=64

It may come in handy when you mess with the partition table. Yes, that moment where you press w in fdisk and immediately regret it ;)

For more information the Wikipedia MBR article is very detailed.

news, security

GHOST Vulnerability: glibc gethostbyname buffer overflow

The GHOST vulnerability was discovered and disclosed by Qualys. It is a serious weakness in the Linux glibc library. It allows attackers to remotely take complete control of the victim system without having any prior knowledge of system credentials. CVE-2015-0235 has been assigned to this issue.

Qualys researchers discovered a buffer overflow in the __nss_hostname_digits_dots() function of glibc. This bug can be triggered both locally and remotely via all the gethostbyname*() functions. Applications have access to the DNS resolver primarily through the gethostbyname*() set of functions. These functions convert a hostname into an IP address.

They have developed a full-fledged remote exploit against the Exim mail server that bypasses all existing protections (ASLR, PIE and NX) on both 32-bit and 64-bit machines. They will publish their exploit as a Metasploit module in the near future. Amol Sarwate, Qualys Vulnerability Labs Director, says in this YouTube interview that they will wait and monitor until the vulnerability reaches its half life, so until their data shows that at least half the servers have been patched they will not release the exploit.

The first vulnerable version of the GNU C Library is glib-2.2, released on November 10, 2000 (yes, it was released more than 14 years ago). The interesting thing is that it was fixed on May 21, 2013 but it was not recognised as a security threat so more stable and long-term-support distributions were left exposed (an still are), for example: Debian 7 (wheezy), Red Hat Enterprise Linux 6 & 7, CentOS 6 & 7 and Ubuntu 12.04. A more detailed list of Linux distributions that contains a vulnerable version of the glibc can be found in the Matasano vulnerability overview.

More information and an analysis about GHOST can be found on this advisory.

shell

Extracting a video clip from the command line

I had to extract a small clip from a very long video and I wanted to do it from the command line (of course!).

To do that we will use avconv (it is part of libav, an open source audio and video tools). It is a very fast audio and video converter that can be used to extract a clip from a video.

To install it in debian based distros:

$ sudo apt-get install libav-tools

In RedHat based distros there isn’t any source with a decent RPM package so the simplest way is build it from source.

In OS X there is a command called avconvert but its functionality is very limited. There is very good answer in Superuser about how to install libav/avconv in OS X.

Once you have avconv in your system let’s say you would like to take a 50 second clip starting at 25 minutes and 30 seconds from a video called original_video.mp4 then you would run the following command:

avconv -ss 00:25:30 -t 00:00:50 -i original_video.mp4 -codec copy video_clip.mp4

That would create a new video called video_clip.mp4 which duration would be 50 seconds and the clip would be the content of the original_video.mp4 from 00:25:30 to 00:26:20.

The option -ss seeks in the input file to position; -t exists after avconv has been running for duration seconds; -i is the input filename; -codec selects a decoder but the value copy is a special value to indicate that the stream is not to be reencoded.

As you can see in aconv manual it has a lot of capabilities.

fun

Merry Christmas!

  /\\,/\\,
 /| || ||
 || || ||   _-_  ,._-_ ,._-_ '\\/\\
 ||=|= ||  || \\  ||    ||    || ;'
~|| || ||  ||/    ||    ||    ||/
 |, \\,\\, \\,/   \\,   \\,   |/
_-                           (
                              -_-

  ,- _~. ,,                     ,
 (' /|   ||           '        ||             _
((  ||   ||/\\ ,._-_ \\  _-_, =||= \\/\\/\\  < \,  _-_,
((  ||   || ||  ||   || ||_.   ||  || || ||  /-|| ||_.
 ( / |   || ||  ||   ||  ~ ||  ||  || || || (( ||  ~ ||
  -____- \\ |/  \\,  \\ ,-_-   \\, \\ \\ \\  \/\\ ,-_-
           _/


             |\                     ,,
  _           \\          _         ||      _
 < \, \\/\\  / \\        < \,       ||/\\  < \, -_-_  -_-_  '\\/\\
 /-|| || || || ||        /-||       || ||  /-|| || \\ || \\  || ;'
(( || || || || ||       (( ||       || || (( || || || || ||  ||/
 \/\\ \\ \\  \\/         \/\\       \\ |/  \/\\ ||-'  ||-'   |/
                                      _/        |/    |/    (
                                                '     '      -_-
    __
   /  -,                    -_   _                     /\
  ||   )       ;              |,- `          _         \/
 ~||---)  _-_  \\/\/\        ~||__))  _-_   < \, ,._-_ }{
 ~||---, || \\ || | |        ~||__)) || \\  /-||  ||   \/
 ~||  /  ||/   || | |         |_ _,  ||/   (( ||  ||
  |, /   \\,/  \\/\\/        -' -    \\,/   \/\\  \\,  <>
-_-  --~                    ( _-_

More ASCII art about Christmas can be found here.

shell

Installing YouCompleteMe on FreeBSD

Recently, we had a discussion at work about editors and IDEs. And yes, I think Vim is not only a great editor but also a good IDE with the proper plugins installed.

There are several nice plugins out there, but I’m going to talk about YouCompleteMe. YouCompleteMe (in short, YCM), is a completion engine for Vim that uses libclang as a backend to support great C/C++ semantic completion. Unlike other pure Vim plugins, YCM needs a component that has to be compiled before you get semantic completion. Although it is not complicated, I’ll show you the steps to successfully install YCM in your FreeBSD:

  1. Install libclang. Since version 10.0, FreeBSD ships clang as a compiler, but not libclang itself. I installed clang35 (sudo pkg install clang35 or sudo portinstall clang35) which installs the library.
  2. Install vundle, the plugin manager.
  3. Use vundle to install YCM as explained in its site. It’s really simple
  4. Install all the needed libraries: sudo pkg install boost-libs boost-python-libs
  5. By default, YCM doesn’t find the boost libraries, so we need to help it a little: export LD_LIBRARY_PATH=/usr/local/llvm35/lib/
  6. Go to .vim/bundle/YouCompleteMe and execute ./install.sh --clang-completer --system-libclang --system-boost. After this, you’re almost done
  7. Copy the .ycm_extra_conf.py file to your home directory and tweak it at your own discretion. I can’t help you much here since your configuration will depend on the project and the language you are using.

Enjoy!

shell

Handling rc.conf(5) with sysrc

FreeBSD uses the traditional BSD boot system as opposed to the system used in Linux, i.e SysV.

This means that in FreeBSD, we have a directory called /etc/rc.d with a bunch of scripts that bring our system up and running. Alongside these scripts, there is a file used to control some configuration variables used at boot time:/etc/rc.conf

Since it is a very sensitive file, an unfortunate mistake while editing it can break havok if our system does not boot the next time. To avoid these kind of situations, there is a tool called sysrc. sysrc provides a way to edit rc.conf(5) safely and effectively.

In order to install the tool, just type:

% portinstall sysrc

or

% cd /usr/ports/sysutils/sysrc && make install

The tool is written completely in sh so it does not need any external dependencies and it does not require compiling. With a simple invocation, it reports the current configuration of our system:

$ sysrc -a
allscreens_flags: MODE_32
background_dhclient: YES
dbus_enable: YES
devfs_system_ruleset: localrules
dumpdev: /dev/ada0p3
hald_enable: YES
hostname: hammer
ifconfig_re0: DHCP
keymap: spanish.iso.acc.kbd
linux_enable: YES
moused_enable: YES
nisdomainname: NO
powerd_enable: YES
saver: daemon
sendmail_enable: NO
sendmail_msp_queue_enable: NO
sendmail_outbound_enable: NO
sendmail_submit_enable: NO
sshd_enable: NO

Changing the value of a variable is easy (and safe):

$ sysrc linux_enable=NO
linux_enable: YES -> NO
$ sysrc linux_enable
linux_enable: NO

Once we know about the existence of this utility it becomes indispensable in our installations of FreeBSD.

Enjoy!

shell

Mirroring a site

I recently had to mirror a website to make a backup. I found this very useful (though not perfect)

wget -mk www.website.com

Hope it helps