Category Archives: Tips

How to remove a copr repository in Fedora

This is just a quick note to remind myself how to remove a Copr repository. What’s a Copr?

“Copr (Cool Other Package Repo) is a Fedora project to help make building and managing third party package repositories easy.” – https://fedoraproject.org/wiki/Category:Copr.

Why do I want to remove it? One of the Copr repo I added a while back seemed to be no longer working, so I wanted to remove it.

# dnf update --refresh
Failed to synchronize cache for repo 'tcg-themes', disabling.
Last metadata expiration check: 0:00:00 ago on Fri 08 Dec 2017 11:12:45 AM AEDT.
Dependencies resolved.
Nothing to do.
Complete!

To list all repos on Fedora (27):

# dnf repolist
Last metadata expiration check: 0:05:59 ago on Fri 08 Dec 2017 11:12:45 AM AEDT.
repo id                    repo name                                      status
*fedora                    Fedora 27 - x86_64                             54,801
google-chrome              google-chrome                                       3
tcg-themes                 Copr repo for themes owned by tcg                  23
*updates                   Fedora 27 - x86_64 - Updates                    6,420

To list just the Corp-repositories:

# dnf copr list
tcg/themes

And finally, to remove the above repo, tcg/themes:

# dnf copr remove tcg/themes
Repository successfully removed.
# dnf update
Last metadata expiration check: 5:18:23 ago on Fri 08 Dec 2017 11:12:45 AM AEDT.
Dependencies resolved.
Nothing to do.
Complete!

Ref: http://dnf-plugins-core.readthedocs.io/en/latest/copr.html

How to unban IP from PF firewall

This post is probably more relevant to my use case of PF firewall running on FreeBSD 11.1, and I need to remind myself how to unblock an IP from the block list.
Here’s a snippet of what’s in /etc/pf.conf:

table persist

# Don't send rejections. Just drop.
set block-policy drop

# Exempt the loopback interface to prevent services utilizing the
# local loop from being blocked accidentally.
set skip on lo0

# all incoming traffic on external interface is normalized and fragmented
# packets are reassembled.
scrub in on $ext_if all fragment reassemble

# set a default deny policy.
block in log all

# This is a desktop so be permissive in allowing outgoing connections.
pass out quick modulate state

# Enable antispoofing on the external interface
antispoof for $ext_if inet
#antispoof for $ext_if inet6

# block packets that fail a reverse path check. we look up the routing
# table, check to make sure that the outbound is the same as the source
# it came in on. if not, it is probably source address spoofed.
block in from urpf-failed to any

# drop broadcast requests quietly.
block in quick on $ext_if from any to 255.255.255.255

block in log quick on $ext_if inet from  to any

In the pf.conf, the blocked IP table is called “sshguard”. To list all the blocked IPs, run:

# pfctl -t sshguard -T show
   1.0.246.105
   1.9.79.191
   1.52.149.133
   1.53.170.75
   1.164.252.130
   1.212.246.18
   1.217.60.210
   1.235.197.132
...

To unblock an IP, e.g. 1.235.197.132, run:

# pfctl -t sshguard -T delete 1.235.197.132
1/1 addresses deleted.

That’s it. Why is it so hard for me to remember? 😛

Set the HostName and Computer Name via command line on OS X

Work recently acquired a few MacBook laptops to be used and shared by staff. Though the computing staff is not expected to have immense knowledge about OS X,  when things break down we are the first point of contact.

The last time I used a Mac machine extensively was around 2007. Then I switched to Debian and could never look back. Anyway, there must be lot of new things and I’ll try document or post snippets here as I learn new things.

The first one for today is to set the hostname and computer name from a command line.

$ export PC_NAME="macarena"
$ sudo scutil --set ComputerName "$PC_NAME" && \
$ sudo scutil --set HostName "$PC_NAME" && \
$ sudo scutil --set LocalHostName "$PC_NAME"

Reference: OS X – Set the HostName, Computer Name, and Bonjour Name via command line

How to list all installed R-packages

I don’t use R, and I don’t know much about it. However, I maintain R installation on Linux machines at work.

Today, I learned a new trick of listing all installed R-packages. Here it is:

ip = as.data.frame(installed.packages()[,c(1,3:4)])
ip = ip[is.na(ip$Priority),1:2,drop=FALSE]
ip

And here is the sample output:

Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> ip = as.data.frame(installed.packages()[,c(1,3:4)])
> ip = ip[is.na(ip$Priority),1:2,drop=FALSE]
> ip
                  Package   Version
akima               akima    0.5-12
alr3                 alr3     2.0.5
BRugs               BRugs     0.8-6
car                   car     2.1-2
coda                 coda    0.18-1
colorspace     colorspace     1.2-6
DEoptimR         DEoptimR     1.0-5
dichromat       dichromat     2.0-0
digest             digest     0.6.9
distillery     distillery     1.0-2
extRemes         extRemes     2.0-7
fields             fields     8.4-1
...

I don’t have time to explain what each line does. If you’re curious, just check out the references below:

Install Grub on GPT

I came across a problem with grub being broken recently on a system running Ubuntu 16.04. This happened after the grub2 package got upgraded. This post will explain how I solved the problem. If you have similar issues, please do not just copy and paste the commands and execute on your machine. First read on, and try to understand it.

Usually, when this happened in the past, we just need to chroot into the system and reinstall grub. On Ubuntu, assuming you’ve chrooted into the system, and the boot disk is /dev/sda, this could be done by running:

# grub-install /dev/sda

This works because /dev/sda was partitioned using MBR. So why didn’t this method work anymore with my current machine?

Well, it’s because the main hard drive was formatted using GPT.

# parted /dev/sda print
Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End    Size   File system  Name  Flags
 1      1049kB  538MB  537MB  ext4
 2      538MB   250GB  250GB

In my case of GPT, because there is no boot partition, grub can’t be installed. Here’s the messages when I tried to install grub:

# grub-install /dev/sda
Installing for i386-pc platform.
grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
grub-install: error: will not proceed with blocklists.

Fortunately, the space of the legacy MBR is still reserved in the GPT specification for limited backward compatibility(1). The grub-install command has just the right option to force install into that MRB space.

# grub-install --force /dev/sda
Installing for i386-pc platform.
grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
Installation finished. No error reported.

Notice the “Installed finished. No error reported.” message.

We can also view the first 512 byte sectors on /dev/sda:

# xxd -l 512 /dev/sda
00000000: eb63 9000 0000 0000 0000 0000 0000 0000  .c..............
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0080 481c 0600  ............H...
00000060: 0000 0000 fffa 9090 f6c2 8074 05f6 c270  ...........t...p
00000070: 7402 b280 ea79 7c00 0031 c08e d88e d0bc  t....y|..1......
00000080: 0020 fba0 647c 3cff 7402 88c2 52bb 1704  . ..d|<.t...R...
00000090: f607 0374 06be 887d e817 01be 057c b441  ...t...}.....|.A
000000a0: bbaa 55cd 135a 5272 3d81 fb55 aa75 3783  ..U..ZRr=..U.u7.
000000b0: e101 7432 31c0 8944 0440 8844 ff89 4402  ..t21..D.@.D..D.
000000c0: c704 1000 668b 1e5c 7c66 895c 0866 8b1e  ....f..\|f.\.f..
000000d0: 607c 6689 5c0c c744 0600 70b4 42cd 1372  `|f.\..D..p.B..r
000000e0: 05bb 0070 eb76 b408 cd13 730d 5a84 d20f  ...p.v....s.Z...
000000f0: 83d0 00be 937d e982 0066 0fb6 c688 64ff  .....}...f....d.
00000100: 4066 8944 040f b6d1 c1e2 0288 e888 f440  @f.D...........@
00000110: 8944 080f b6c2 c0e8 0266 8904 66a1 607c  .D.......f..f.`|
00000120: 6609 c075 4e66 a15c 7c66 31d2 66f7 3488  f..uNf.\|f1.f.4.
00000130: d131 d266 f774 043b 4408 7d37 fec1 88c5  .1.f.t.;D.}7....
00000140: 30c0 c1e8 0208 c188 d05a 88c6 bb00 708e  0........Z....p.
00000150: c331 dbb8 0102 cd13 721e 8cc3 601e b900  .1......r...`...
00000160: 018e db31 f6bf 0080 8ec6 fcf3 a51f 61ff  ...1..........a.
00000170: 265a 7cbe 8e7d eb03 be9d 7de8 3400 bea2  &Z|..}....}.4...
00000180: 7de8 2e00 cd18 ebfe 4752 5542 2000 4765  }.......GRUB .Ge
00000190: 6f6d 0048 6172 6420 4469 736b 0052 6561  om.Hard Disk.Rea
000001a0: 6400 2045 7272 6f72 0d0a 00bb 0100 b40e  d. Error........
000001b0: cd10 ac3c 0075 f4c3 0000 0000 0000 0000  ...<.u..........
000001c0: 0100 eefe ffff 0100 0000 6f59 1c1d 0000  ..........oY....
000001d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001f0: 0000 0000 0000 0000 0000 0000 0000 55aa  ..............U.

Ref:

(1) https://en.wikipedia.org/wiki/GUID_Partition_Table