Post list
How to set up git + cgit on a remote server

Today's teaching/learning transference will elaborate on how to use git and cgit on a remote server which will allow us to work with our own simple, fast, self-hosted distributed source code management web solution using Nginx and any Debian-based distribution, as an alternative to storing our source files in corporate platforms such as Github. We will not get into much detail since our job will be to simply get the work done.

  1. Firstly log in our remote server and install the required packages:

    sudo apt-get install git-core cgit fcgiwrap
  2. Create a new username called git that will be used to manage our repositories; we also set up a password and bash permissions for it:

    sudo useradd git
    sudo passwd git
    sudo usermod -s /bin/bash git
  3. Log in as our new git user and create a folder for our first repository inside the personal directory:

    su - git
    mkdir /home/git/myfirstrepo
  4. Initialize an empty git repository which will be later used to push changes from the local machine:

    git init --bare /home/git/myfirstrepo
  5. That is all we need to do at the remote server for now. Our next step will be pointing our local repository to its new remote location. In the local machine, go to the directory where your .git repository folder is located and run:

    git remote add origin ssh://git@ourserverip/home/git/myfirstrepo
  6. If there is an existing remote called origin, it can be removed by previously executing:

    git remote remove origin
  7. We are now ready to push the repo to our remote server:

    git push origin master
  8. Pushing changes is great, but what about using a web interface to navigate through them? That is where cgit comes into play. Since we already installed it at step 1, just log back to our remote server and edit the cgit configuration file to add our repository location:

    sudo nano /etc/cgitrc
  9. This file allows to set up many different configuration options for cgit. Check out this sample file for more information. Once all desired options have been added, we scroll down to the end of the file and add our repository information. On this occasion, this data will be set manually. A simpler option would be to just use the scan-path option, which automatically scans all repository folders inside the specify path. On this case though we will not use such option and define each field manually instead by adding the following lines:

    repo.desc=My first self-hosted repo
  10. Close nano after saving changes and initialize the fcgiwrap service:

    sudo systemctl enable fcgiwrap
    sudo systemctl start fcgiwrap
    sudo systemctl status fcgiwrap
  11. We will now configure Nginx so that the cgit web interface can be accessed under a custom domain on the web, which should be already pointing to our server's IP. Create a new file inside Nginx sites-avaialable directory with the following contents:

    sudo nano /etc/nginx/sites-available/cgit
    server {
        listen [::]:80;
        listen 80;
        # Path to the static web resources of cgit
        root /usr/share/cgit;
        try_files $uri @cgit;
        location @cgit {
            include             fastcgi_params;
            # Path to the CGI script that comes with cgit
            fastcgi_param       SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi;
            fastcgi_param       PATH_INFO       $uri;
            fastcgi_param       QUERY_STRING    $args;
            fastcgi_param       HTTP_HOST       $server_name;
            # Path to the socket file that is created/used by fcgiwrap
            fastcgi_pass        unix:/run/fcgiwrap.socket;
  12. Create a symlink on sites-enabled to the file we just created:

    sudo ln -s /etc/nginx/sites-available/cgit /etc/nginx/sites-enabled
  13. Restart Nginx and cgit should be now visible at the domain we specified previously containing our remote repository:

    sudo systemctl restart nginx

That is all for today's session, hopefully it will be helpful to somebody somewhere out there. Feel free to share any issues in the comments section. Stay tuned for more stellar transmissions soon, coming out of these remote places of the galaxy. Over grrrgrhjr.

A new design appears on the horizon

Reporting from the command center. Our spaceship has been upgraded with a fancy new design that carefully embraces an even more minimalist approach while hoping to improve readability.

Our lab engineers decided to go crazy and additionally implemented a set of advanced engine modules such as pagination and a sane RSS log, we are traveling into the future after all. Not only that, but all git datacores are being translocated to our own local database. Once the migration gets finished we will proceed to destroy the previous Github instance, making our cosmic operations completely free from any Microsoft spyware. The empire shall go down.

That is all for today's report. Stay tuned to this bandwidth for updates on a few upcoming projects. Over grsshhhhsh.

UnconsciousBot likes generating procedural text based on Carl Jung's writings

It turns out this blog is not dead, it was only sleeping! You see, my mind works in a somewhat obsessive way. Whenever I find something I enjoy, I tend to focus all my being into it, and it becomes my main and only focus of attention. For a period of time, I live exclusively towards that goal, leaving everything else aside. Eventually I burn out, say "fuck it" and leave it for something else. I am aware that this behavior is somewhat pathological, even though I get extremely productive when I stay in the zone. Nevertheless I try to make some effort to create balance in my life, with greater or lesser success. In fact, this blog was created out of the intention to subject myself to some sort of posting schedule discipline, which I managed to maintain... for a few days. But here we are again!

Leaving my self-diagnosed psychological evaluation aside, the actual point of this post is to answer a request from a fellow Mastodoner asking how UnconsciousBot, one of my latest digital minions, works. This Mastodon bot procedurally generates text based on Jung's writings, works that by themselves are full of symbolic synchronicity potential, but even more so when we apply some randomness! As everything we have previously seen here, the results look more complex than the implementation. The human race is so prolific that it is increasingly difficult to create something that does not already exist, and in this case too it was just a matter of finding the proper library. Thanks to ddycai, we can use his random sentence generator to create random sentences based on an input file using Markov chains. This library acts as a handy wrapper for the Natural Language Toolkit, an interesting framework designed to work with human language data.

So how does it work? In order to generate text, we feed the algorithm with a text file composed of sentences that are tokenized. Then a random sentence is selected, and the first group of words are searched across the text file for coincidences. The sentence is then joined with another random sentence that matches those words, and the process is repeated till a dot is found. In this way, the bigger the group of words, the more strict the results will be. So for instance, many matches can be found if the group consists of two words, while a group of five words will mostly return literal sentences from the text. For UnconsciousBot I only used Aion as the text source, however the bigger input, the more possibilities. At some point I would like to improve it by adding more of Jung's books, but even as it is now, it tends to give interesting results from time to time. There are also some spacing issues in the original text file that I should fix at some point. Maybe tomorrow.

Here is the code, which is an adapted version of ddycai's script; it can also be found in my Github:

import requests, json, os
from mastodon import Mastodon
from nltk import word_tokenize
from sentence_generator import Generator

# Mastodon token and domain
mastodon = Mastodon(
    access_token = 'asdf',
    api_base_url = ''

# How many words we are taking (the bigger the variable, the more strict it will be)
words = 2
text = ""
found = False

# We open the file and apply some tokenizing magic
while(found == False):
    with open("text.txt", 'r',encoding='utf-8') as f:
        sent_detector ='tokenizers/punkt/english.pickle')
        sents = sent_detector.tokenize(
        sent_tokens = [word_tokenize(sent.replace('\n', ' ').lower()) for sent in sents]
        generator = Generator(sent_tokens, words)

        # We capitalize the first word to make it pretty
        text = generator.generate().capitalize()

        # We only accept the result if it is smaller than Mastodon's character limit
        if(len(text) <  500):
            found = True

# Send result to Mastodon

I hope this entry was somewhat useful! If not then I guess I failed miserably. This was post #11 in the #100DaysToOffload challenge. At this point, my personal goal with the challenge is to reach a hundred posts, no matter how long it takes, since I am more fond of quality over quantity. As always, thank you for reading and see you next time.

Next page