Saturday, December 30, 2023

Installing, configuring and using tin to read Usenet articles in Linux (WSL-2)

 I recently learned about Gemini and how its development is being tracked on Usenet. This got me interested in accessing Usenet.

Registering with Usenet Provider


The first step is to register with a Usenet provider. Since I am primarily interested in the comp.infosystems.gemini group I can use a free provider which only gives text access. I chose to use https://www.eternal-september.org/. Registration was extremely straight forward and I received credentials via email.

Installing tin (Usenet reader)


I looked around for a Linux based Usenet reader and came across tin. I am currently using a Windows laptop with WSL-2 installed running Ubuntu 20.04. I installed tin using:
sudo apt-get install tin

Authenticating with tin


I created a ~/.newsauth file readable only by myself (chmod go-r ~/.newsauth) and placed my credentials inside it in the recommended format:
news.eternal-september.org <password> <username>

All of this information came from the registration email I got from eternal-septemeber.

Configuring tin


To use neovim as the editor of choice when replying to articles I set export EDITOR='nvim' in my ~/.zshrc. I also set TIN_HOMEDIR="$HOME/.tin" to consolidate the various configuration files.

To correctly identify myself when posting articles (replies) I modified ~/.tin/tinrc and set mail_address="Abid H. Mujtaba" <abid.mujtaba@protonmail.com>

Running tin


Launch via: tin -r -g news.eternal-september.org -A comp.infosystems.gemini

-r tells tin to fetch from articles from the remote server (rather than local). -g is used to specify which remote server to use (eternal-september in my case), and -A tells tin to authenticate with the remote server (using the credentials in ~/.newsauth, prompts for creds if that file doesn't exist).

One can set NNTPSERVER="news.eternal-september.org" to avoid having to specify -g. Similarly one can (initially) place the line comp.infosystems.gemini: (note the necessary colon at the end) in ~/.tin/.newsrc (extra info will be appended after the colon automatically as you interact with the usenet group). With these changes one can simply issue tin -r -A.

Using tin


To get started, select a thread (of articles). To read the next article in the thread click n (p for the previous article). Use j and k to move down and up inside an article. Can also enter the article number (within the thread) to jump to it.

To post in response to an article use f (follow-up). This is different then replying (r) which sends an email to the author (using sendmail).
 

Saturday, October 21, 2017

Compiling Latex with latexmk with tikz externalization and pre-compiled preamble (which includes tikz)

Compilation of LaTeX projects that contain tikz images can be sped up by an astronomical amount by properly separating the static and dynamic preamble and issuing the right commands.

A minimum-working-example that I wrote that demonstrates this in great detail can be found at: https://github.com/abid-mujtaba/mwe-latexmk-tikz-preamble

Sunday, July 2, 2017

Ubuntu - Copy large number of files easily to Android Phone

Situation:

The MTP protocol for transferring files to and from an Android Phone is utter garbage, especially when transferring a large number of files (like your Music collection for the first time - on my Google Pixel). The connection inevitably fails in the middle of the transfer, which is slow to boot.

Solution:

USB tether your phone to your computer (read http://abidmujtaba.blogspot.com/2017/07/ubuntu-usb-tethering-with-google-pixel.html if you get stuck). You don't even need internet pass-through, just an IP Address (so you can use sudo dhclient usb0 instead of sudo dhcpcd usb0 if you are using the terminal).

Next follow http://abidmujtaba.blogspot.com/2017/07/ubuntu-ssh-in-to-android-phone-google.html to set up an ssh connection. Once you have that you are home free.

I use lftp over ssh to copy all the files I want. I even have a simple lftp bookmark set up:
pixel sftp://abid:xx@pixel
where my ssh config section is titled "pixel" and the password "xx" is just a red-herring since ssh is configured to use an RSA key for authentication. This bookmark allows me to access my phone's files using a simple lftp pixel.

Ubuntu - SSH in to Android Phone (Google Pixel)

The ability to SSH in to your (unrooted) Android Phone is a very powerful one to have, and it is surprisingly simple.


  1. Install the "SimpleSSHD" app on your phone (form the Google Play Store).
  2. Copy your PUBLIC ssh key (form your computer) to the "/sdcard/ssh" (default) folder on your phone and rename it authorized_keys.
  3. Run the "SimpleSSHD" app and click start (uses port 2222 be default since it runs in user space). The app will tell you the IP address of the phone.
  4. SSH in to your phone by issuing:
    ssh -o StrictHostKeyChecking=no -p 2222 -i <private key location> <phone ip address>
    You will need to issue StrictHostKeyChecking=no the first time only.
  5. To avoid having to type all of this out every time you can add a section to the ssh config file (~/.ssh/config).
    Host pixel
    
        Hostname 192.168.42.129
        Port 2222
        IdentityFile ~/.ssh/pixel
    
    and simply run ssh pixel to connect.
Nore: This technique works with USB tethering as well. SimpleSSHD will show both the WiFi and the USB Tethering IP Addresses and you can use the latter for super-fast ssh.

Ubuntu - USB Tethering with the Google Pixel

Situation:

When I connected my Google Pixel to my Ubuntu (14.04) laptop with the USB cable and selected the option to USB tether on the phone the connection would fail. The Network Manager applet would show a greyed out option "Ethernet Network (Google Pixel)" with the status "disconnected" underneath it, also greyed out.

Interestingly running "ifconfig" revealed that a "usb0" section was present but no IP address had been assigned.
usb0      Link encap:Ethernet  HWaddr 32:a8:e6:6c:fe:9d  
          inet6 addr: fe80::30a8:e6ff:fe6c:fe9d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:560 (560.0 B)  TX bytes:1802 (1.8 KB)

This clue led to a long trawl across the internet that led to a surprisingly simple solution.

Solution:

Install the "dhcpcd" package.
sudo apt-get install dhcpcd
Now after connecting the Google Pixel simply run:
sudo dhcpcd usb0
And confirm by running:
ifconfig usb0
route -n
ping -c3 www.google.com

Thursday, June 22, 2017

Compiling Latex with scons with tikz externalization and pre-compiled preamble (which includes tikz)

Edit: I have created another MWE that uses latexmk instead of scons (which I found to be using more resources and not recompiling correctly when citations were added): http://abidmujtaba.blogspot.com/2017/10/compiling-latex-with-latexmk-with-tikz.html

Compilation of LaTeX projects that contain tikz images can be sped up by an astronomical amount by properly separating the static and dynamic preamble and issuing the right commands.

A minimum-working-example that I wrote that demonstrates this in great detail can be found at: https://github.com/abid-mujtaba/mwe-scons-tikz-preamble

Ubuntu - Connecting to a PPTP VPN server using the terminal

Situation:

I was away from Islamabad and needed to download some scientific papers. This required me to connect to my University's VPN which was of the PPTP variety. I tried using the Network Manager applet in Ubuntu 14.04 which would successfully connect but the moment I would open a page on Chrome the VPN connection would fail.


Solution:

Connect to the VPN from the terminal using instructions that were written for Ubuntu 7.04 (https://wiki.ubuntu.com/VPN) and were supposed to have become outdated 7 years ago. But what is in the command line can never die.

Based on help from https://superuser.com/a/459906/306711 and http://www.wikihow.com/Add-or-Change-the-Default-Gateway-in-Linux with a little tweaking I was able to successfully connect to the VPN in a stable fashion.


Details:
  1. Install pptp package: sudo apt-get install pptp-linux

  2. Create a peers file. I named mine 'comsats' so I created: /etc/ppp/peers/comsats with the following content
        pty "pptp <vpn server ip address> --nolaunchpppd"
        debug
        nodetach
        logfd 2
        noproxyarp
        ipparam comsats
        remotename comsats
        name <vpn username>
        require-mppe-128
        nobsdcomp
        nodeflate
        lock
        noauth
        refuse-eap
        refuse-chap
    
    This file needs to be executable (sudo chmod +x /etc/ppp/peers/comsats). Note the 'remotename' and the 'ipparam' which are set to 'comsats'. These will be used to activate the connection and to run automated scripts when the connection is setup and torn down.

  3. Add your VPN credentials to /etc/ppp/chap-secrets in the following format:
        * <vpn username> * <vpn password>
    At this point you can check your vpn connection by executing:
        sudo pon comsats
    For debugging the connection look at /var/log/syslog. At this stage your internet will NOT be forwarded over the vpn because the routes haven't been set up for it.

    To close the connection Ctrl+C is supposed to work but it didn't for me so I had to use ps -A | grep ppp to find the pid of the connection process and then sudo kill -KILL <pid> to kill it.

  4. To forward your internet packets over the VPN you must first find the ip addresses of the gateways for your internet interface (wlan0 in my case) and the vpn interface (ppp0). Simply use ipconfig. In my case my wifi gateway was 192.168.0.1 and the vpn gateway was 192.168.3.1. To take a look at the current routes issue the route command, it will show you the current default gateway.
    The first step is the delete the current default gateway:
        sudo route delete gw 192.168.0.1 wlan0
    Note the use of my wlan0 gateway ip address (192.168.0.1).
    Now switch to using the ppp0 gateway as the default so that all outgoing internet traffic is sent via the vpn:
        sudo route add gw 192.168.3.1 ppp0
    You can confirm the switch to using the VPN by looking at your external IP address (I simply navigate to https://www.icanhazip.com and a whois to confirm).

  5. After closing the vpn connection you will have to revert the changes to the routes to get your normal internet access back (the Network Manager applet does all of this automatically, when it works) as follows:
        sudo route delete gw 192.168.3.1 ppp0
        sudo add gw 192.168.0.1 wlan0

  6. To automate the route changes one can add files to the /etc/ppp/ip-up.d and /etc/ppp/ip-down.d folders that are automatically run when the connection is setup and torn down respectively.
    Create and populate /etc/ppp/ip-up.d/comsats:
        #!/bin/sh
    
        [ "$PPP_IPPARAM" = "comsats" ] || exit 0
        route delete default gw 192.168.0.1 wlan0
        route add default gw 192.168.3.1 ppp0
    
    Note how we use the $PPP_IPPARAM to match against the same we defined in /etc/ppp/peers/comsats to make the code run only when this connection is set up.
    Similarly create and populate /etc/ppp/ip-down.d/comsats:
        #!/bin/sh
    
        [ "$PPP_IPPARAM" = "comsats" ] || exit 0
        route delete default gw 192.168.3.1 ppp0
        route add default gw 192.168.0.1 wlan0
    
    Finally comment out nodetach in /etc/ppp/peers/comsats to run the connection as a deamon and use sudo poff comsats to close the connection when you need to. This connection is not as stable as I would like it (usable however) so I use tail -F /var/log/syslog | ccze -A to keep an eye on the connection while I am using it, restarting it as needed.