TODAY I LEARNED - page 2

This is a place for small snippets of knowledge.
  • chroot and serial console to fix ubuntu distro upgrade gone wrong


    I had to fix a do-distro-upgrade from 16.04 to 18.04 due to a severed ssh connection, and no screen running (apparently earlier distro upgrades used screen to prevent this kind of problem)

    The machine as a PCengine apu2, so no video. Also, the root file system is sitting on a miniPCI ssd.

    Eventually, my thinkpad x230i, and this chroot cheatsheet helped: https://aaronbonner.io/post/21103731114/chroot-into-a-broken-linux-install

    1. Mount the root filesystem device

       mount -t ext4 /dev/<device> /mnt/
      
    2. If there’s a different boot partition or anything else

       mount -t ext2 /dev/<device> /mnt/boot
      
    3. Mount special devices

       mount -t proc none /mnt/proc
       mount -o bind /dev /mnt/dev
       mount -o bind /sys /mnt/sys
      
    4. chroot

       chroot /mnt /bin/bash
       source /etc/profile
      

    In order to help troubleshoot in the future, i followed this advice to get a systemd service unit for a constant shell on the serial port, but mine runs for some reason on S0: http://0pointer.de/blog/projects/serial-console.html

    systemctl enable serial-getty@ttyS0.service
    systemctl start serial-getty@ttyS0.service
    

    It won’t help if systemd does not start, but otherwise it is online really early.

  • Quick way to forward mails via postfix


    Thanks to Ben Tasker

    Assuming you’re running Postfix, it’s as simple as the steps below

    First we make sure the virtual mappings file is enabled

    vim /etc/postfix/main.cf
    
    # Scroll down until you find virtual_alias_maps
    
    # Make sure it reads something like
    virtual_alias_maps = hash:/etc/postfix/virtual
    # We also need to make sure the domain is enabled
    virtual_alias_domains=example.com
    

    Save and exit, next we add the aliases to our mapping file

    nano /etc/postfix/virtual
    # Forward mail for admin@example.com to jo.bloggs@hotmail.com
    admin@example.com  jo.bloggs@hotmail.com
    

    Simple! And if we want to send to two different addresses at once, we just specify them

    admin@example.com  jo.bloggs@hotmail.com jos.wife@hotmail.com
    

    Finally, we just need to create a hash (actually later versions of Postfix don’t require this)

    postmap /etc/postfix/virtual
    

    It’s exactly the same principle as passing mail into a local user’s mailbox.

  • How to create a self-signed (wildcard) certificate


    This is a quick step to generate self-signed certificate :

    openssl genrsa 2048 > host.key
    openssl req -new -x509 -nodes -sha1 -days 3650 -key host.key > host.cert
    #[enter *.domain.com for the Common Name]
    openssl x509 -noout -fingerprint -text < host.cert > host.info
    cat host.cert host.key > host.pem
    chmod 400 host.key host.pem
    

    from here

  • Seafile 3 GUI client and Fedora 20


    Currently there is no official rpm pacakge available for the GUI version of the Seafile 3 client. You can find extensive build instructions here:

    Build and Use Seafile client from Source

    I had to add the Vala package to the dependencies:

    sudo yum install vala vala-compat wget gcc libevent-devel openssl-devel gtk2-devel libuuid-devel sqlite-devel jansson-devel intltool cmake qt-devel fuse-devel
    

    Current versions:

    Here’s a little fix up for the script parts:

    #!/usr/bin/env bash
    
    echo "Building and installing seafile client"
    
    export version=3.0.2 # change this to your preferred version
    alias wget='wget --content-disposition -nc'
    wget https://github.com/haiwen/libsearpc/archive/v${version}.tar.gz
    wget https://github.com/haiwen/ccnet/archive/v${version}.tar.gz
    wget https://github.com/haiwen/seafile/archive/v${version}.tar.gz
    wget https://github.com/haiwen/seafile-client/archive/v${version}.tar.gz
    tar xf libsearpc-${version}.tar.gz
    tar xf ccnet-${version}.tar.gz
    tar xf seafile-${version}.tar.gz
    tar xf seafile-client-${version}.tar.gz
    
    export PREFIX=/usr
    export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH"
    export PATH="$PREFIX/bin:$PATH"
    
    echo "Building and installing libsearpc"
    
    cd libsearpc-${version}
    ./autogen.sh
    ./configure --prefix=$PREFIX
    make
    sudo make install
    
    cd ..
    
    echo "Building and installing ccnet"
    
    cd ccnet-${version}
    ./autogen.sh
    ./configure --prefix=$PREFIX
    make
    sudo make install
    
    cd ..
    
    echo "Building and installing seafile"
    
    cd seafile-${version}/
    ./autogen.sh
    ./configure --prefix=$PREFIX --disable-gui
    make
    sudo make install
    
    cd ..
    
    echo "Building and installing seafile-client
    
    cd seafile-client-${version}
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX .
    make
    sudo make install
    

    Run the lib linker, just in case sudo ldconfig

    Start the client with seafile-applet

  • Skype and Fedora 20


    Thanks to Negativo17’s blog I got skype running. Here’s the step by step:

    Run all commands as root or vias sudo

    1. Add the the negativo17 repo of skype wget http://negativo17.org/repos/fedora-skype.repo -O \ /etc/yum.repos.d/fedora-skype.repo

    2. Install skype normally via yum yum install skype

    NB: It considers the sound bug in Fedora 20:

    On Fedora 20+, the real Skype binary is used through a wrapper that sets PULSE_LATENCY_MSEC=30 before running the real binary. As of Skype 4.2.0.11 this is required for proper operation.

    NB: Always consider the trust implications of 3rd-party repo providers.

  • Keepass2 and Fedora 20


    Basically, you need to install mono env and use the portable version of keepass: sudo yum -y install mono-core mono-winforms

    I have yet to figure out how to make a convinient link to the Gnome menu structure.

  • Estonian ID card and Fedora 20


    Additionally to the standard packages which you would install like so from the standard repos of fedora: sudo yum install qesteidutil qdigidoc mozilla-esteid you should also install the pcscd package: sudo yum install pcsc-lite Finally, some useful tool here: sudo yum install pcsc-tools

    Thanks to this here

  • What's a full stack developer?


    Found here: http://www.laurencegellert.com/2012/08/what-is-a-full-stack-developer/

    Main points

    layers of the full stack

    Server, Network, and Hosting Environment

    1. This involves understanding what can break and why, taking no resource for granted.
    2. Appropriate use of the file system, cloud storage, network resources, and an understanding of data redundancy and availability is necessary.
    3. How does the application scale given the hardware constraints?
    4. What about multi-threading and race conditions? Guess what, you won’t see those on your development machine, but they can and do happen in the real world.
    5. Full stack developers can work side by side with DevOps. The system should provide useful error messages and logging capabilities. DevOps will see the messages before you will, so make them count.

    Data Modeling

    1. If the data model is flawed, the business logic and higher layers start to need strange (ugly) code to compensate for corner cases the data model doesn’t cover.
    2. Full stack developers know how to create a reasonably normalized relational model, complete with foreign keys, indexes, views, lookup tables, etc.
    3. Full stack developers are familiar with the concept of non-relational data stores and understand where they shine over relational data stores.

    Business Logic

    1. The heart of the value the application provides.
    2. Solid object oriented skills are needed here.
    3. Frameworks might be needed here as well.

    API layer / Action Layer / MVC

    1. How the outside world operates against the business logic and data model. Frameworks at this level should be used heavily.
    2. Full stack developers have the ability to write clear, consistent, simple to use interfaces. The heights to which some APIs are convoluted repel me.

    User Interface

    1. Full stack developers: a) understand how to create a readable layout, or b) acknowledge they need help from artists and graphic designers. Either way, implementing a good visual design is key.
    2. Can include mastery of HTML5 / CSS.
    3. JavaScript is the up and coming language of the future and lots of exciting work is being done in the JavaScript world (node, backbone, knockout…)

    User Experience

    1. Full stack developers appreciate that users just want things to work.
    2. A good system doesn’t give its users carpal tunnel syndrome or sore eyes. A full stack developer can step back and look at a process that needs 8 clicks and 3 steps, and get it down to one click.
    3. Full stack developers write useful error messages. If something breaks, be apologetic about it. Sometimes programmers inadvertently write error messages that can make people feel stupid.

    Understanding what the customer and the business need.

    1. Now we are blurring into the line of architect, but that is too much of a hands off role.
    2. Full stack developers have a grasp of what is going on in the field when the customer uses the software. They also have a grasp of the business.

    Other Pieces of the Puzzle:

    1. Ability to write quality unit tests. By the way, even JavaScript can have unit tests these days.
    2. Understanding of repeatable automated processes for building the application, testing it, documenting it, and deploying it at scale.
    3. An awareness of security concerns is important, as each layer presents its own possible vulnerabilities.