Skip to main content

Updating the Raspberry PI GIT server.

I took time to refresh my Raspberry PI GIT server. I am still using the v1 board, but with a few upgrades and modifications. It was more to streamline the entire package instead of performance upgrades.


The original Raspberry Pi in a modded case.

Changes:

  • I bought a half-height SD to Micro SD adapter. This makes it stick out less from the case. Sadly it’s not totally flush, but better at least. Along with that I upgraded to a 64GB micro SD card from a 32GB SD card.
  • I upgraded the backup drives with 64GB Lexar JumpDrives (S45 LJDS45-64GABNL). They are super compact and had decent reviews. I decided to skip the RAID 01 mirroring approach with these. It simplifies things and there really isn’t any drawback besides maybe hot swap (which I don’t think would work because fstab uses unique drive identifiers).
  • I picked up another power supply on a whim when I saw it at the store “Five Below” for a great price. This again streamlines things over my previous setup that was combo type where you would plug in a USB cable into the unit. In this case it’s one single piece. The maximum amp rating on it is 2.4 amps, which is great for $5.
  • I drilled vent holes into the top case as seen in the photos. I might add more in the future, but I thought at least a few would be good.

Anything over 32GB will require an extra formatting step detailed here. The current install takes the user directly to the GUI operating system after it is finished setting things up. You need to go into the start (raspberry) button >> “Preferences” >> “Raspberry Pi Configuration” to find options. From there you can switch it up to boot from the command line instead of the GUI.

Once you are at a command prompt you can do this to enable SSH:

  • Enter sudo raspi-config in a terminal window
  • Select Interfacing Options
  • Navigate to and select SSH
  • Choose Yes
  • Select Ok
  • Choose Finish

Once you are setup, you can slim down what NOOBS pre-installs into the OS thanks to this person who made this script.

Download PuTTY for SSH (used for the remote command line interface):
http://www.putty.org/
A Windows installer for everything except PuTTYtel

Download and install Window GIT:
https://git-for-windows.github.io/

Download and install Tortoise GIT:
https://tortoisegit.org/

Linking RP and your client with source code:
Create the local repository by adding a folder to your computer and right-clicking on it and selecting “Git create repository here…” from the context menu. Have it make a standard setup (not bare).

Generate your SSH keys:
Use Puttygen to make the keys, save both the public and private keys. Name the private key with a .ppk extension.
Seems to be optional if you do everything on the same local network.

SSH to your pi:

# 1. Install Git on your Pi (If not already installed):
sudo apt-get install git git-core

# 2. Add a user 'git' (or use a different name if preferred):
sudo adduser --system --shell /bin/bash --group --home /home/git --gecos 'git version control by pi' git

# 3. Set the password for the new user 'git':
sudo passwd git

# 4. Switch to the 'git' user and create an empty repository:
su git
cd /home/git
mkdir repo.git
cd repo.git
git --bare init

Back to your working machine where you have a folder you want to push to the new GIT server:
You can use TortoiseGit to set things up.
Right-click on the main folder. Select Git Create Repository here.
Right-click >> TortoiseGIT >> Settings >> Remote…
From there you can add server details.
Remote: A name you want to call it.
URL: something like git@X.X.X.X:repo.git
Where X.X.X.X would be the IP address of the new server on your local network.
The Push URL is the same as the URL.
All of the other options can be left default unless you made a Putty Key earlier.

Setup the backup drives:
Prepare directories that you will mount your drives to.


sudo mkdir /media/usbdrive
sudo chown -R git:git /media/usbdrive
sudo chmod -R 775 /media/usbdrive
sudo setfacl -Rdm g:git:rwx /media/usbdrive
sudo setfacl -Rm g:git:rwx /media/usbdrive

sudo mkdir /media/usbdrive2
sudo chown -R git:git /media/usbdrive2
sudo chmod -R 775 /media/usbdrive2
sudo setfacl -Rdm g:git:rwx /media/usbdrive2
sudo setfacl -Rm g:git:rwx /media/usbdrive2

Figure out your USB drive IDs:
sudo blkid
(or)
ls -l /dev/disk/by-uuid/
You should see your two USB drives (sda1 and sdb1) with identifiers like XXXX-XXXX. Those are the unique IDs that we use in fstab to mount the drives. blkid will give you the type of formatting. In my case it is vfat.

Optionally, you might need different drivers that you can install such as ntfs or exfat:

sudo apt-get install ntfs-3g -y
sudo apt-get install exfat-utils -y
sudo pico /etc/fstab

UUID=AAAA-AAAA  /media/usbdrive vfat    nofail,uid=git,gid=git   0   0
UUID=BBBB-BBBB  /media/usbdrive2 vfat    nofail,uid=git,gid=git   0   0

This should get them mounted without a reboot:
sudo mount -a

Setup crontab tasks:
crontab -e

10 * * * * /usr/bin/rsync -av -delete /home/git/repo.git/ /media/usbdrive/repo.git/ --log-file=/home/git/rc1.log
15 * * * * /usr/bin/rsync -av /home/git/repo.git/ /media/usbdrive2/repo.git/ --log-file=/home/git/rc2.log

I run a rsync task for each backup drive. The first drive will be a true mirror and the second drive will be a mirror but keep *everything* that was ever added in case the main drive ever goes bad and tries to push deletes to the backups. The only issue could be drive space, but I am not using much. If it ever became an issue, I’d just upgrade the drives again.

I switched from Unison to rsync. It’s a lot simpler to use and doesn’t run the risk of back pushing changes (eg. deleting your source code if a backup drive has issues or is accidentally cleared)

That should be about it.

————————————————
Here are some useful commands:
Calculate the size of a directory:
du -sh /home/git/repo.git

To view mail from crontab:
cat /var/spool/mail/pi

Popular posts from this blog

ChatGPT is a new, and faster, way to do programming!

Currently ChatGPT is in a free “initial research preview” . One of its well known use cases at this point is generating software code. I’ve also just used it to write most of this article… Well, actually a future article about cleaning up SRT subtitle files of their metadata faster than I have been by hand with Notepad++ and its replace functionality. Update: I recorded a screencast of writing the SRT subtitle cleaner application loading and processing portion. I relied heavily on ChatGPT for code. It was a fun process! https://youtu.be/TkEW39OloUA ChatGPT, developed by OpenAI, is a powerful language model that can assist developers in a variety of tasks, including natural language processing and text generation. One such task that ChatGPT can help with is creating an SRT cleaner program. SRT, or SubRip Subtitle, files are commonly used to add subtitles to video files. However, these files can become cluttered with unnecessary information, such as timing lines or blank spaces. To clean...

Theme error in 2010s Android App after AppCompat Migration

I plan on releasing a lot of my old work as GPL open source, but most of it has aged to the point that it no longer functions, or if it does work it’s running in compatibility mode. Basically it’s no longer best practices. Not a good way to start off any new public GPL projects, in my opinion. The current project I’m working on is an Android app that calculates star trails meant to help photographers get or avoid that in their night time photos. For now I’m going to skip some of the import process because I didn’t document it exactly. It’s been mostly trial and error as I poke around Android Studio post import. The Android Studio import process… Removing Admob Google Play code before the project would run at all. After removing dependencies, it kind of worked, but when running it in the emulator it shows a pop-up message saying that the app was developed for an old version of Android. Going through the process of updating code to match current best practices… I had the IDE convert the ...

Printing to file in Linux WINE

I noticed that this post has been sitting as a draft since 2011. At this point I have no idea if it’s useful or what I was even doing, but I might as well make it public in case someone can find it helpful! So I’ve been trying to get one of those PDF print drivers working in WINE without success. I then came upon a process that might work. When printing you need to select the checkbox “Print to file” that creates a .prn file. Just Linux things... I was using a program that only has printing facilities, but I want to export around 100 pages of text and images. Once you have the .prn (postscript) file, you can do any number of things to it. In my case I want the postscript file to be converted to HTML. I am also considering PDF format because that has more conversion options to eventually get me to HTML or plain text. sudo apt-get install cups-pdf Or it looks like that package might have changed to this… sudo apt-get install printer-driver-cups-pdf Where PDFs would be generated in /home/...