Categories
Server admin

Installing OMV on Raspberry Pi

Open media vault allows you to run a NAS server on your raspberry pi. the easiest way to install it on your pi is to install the default “lite” version of the OS. That is the one with no “Desktop” and then run the following script:

wget -O - https://github.com/OpenMediaVault-Plugin-Developers/installScript/raw/master/install | sudo bash

After that completes, you’ll also want to run this one:

wget -O - https://github.com/OpenMediaVault-Plugin-Developers/packages/raw/master/install | sudo bash

Give it a few minutes to run, and it should be accessible through the website at it’s ip address. You will then use the default username and password to log in. The default username is “admin” and the default password is “openmediavault”
Source: https://www.reddit.com/r/OpenMediaVault/comments/16qcny4/guide_for_setting_up_omv_on_raspberry_pi/

Categories
Server admin

Backing up Raspberry Pi

Why!?!?

“Why!?!?” That’s what I was asking when my pi stopped working. After days of configuration and tinkering it just wouldn’t connect to the network anymore. I said to myself “Welp, I guess I’ll reinstall from scratch” and spent the next few hours installing and setting everything back up again.

Solution? Make a Backup using a Mac

Obviously this is what I should have done from the beginning. Now what’s the “right” backup solution?

The simplest one is to insert an identical sd card into a card reader and insert that into the USB port. And then running this command from the terminal while the pi is off. Replace /dev/mmcblk0 with the location of your pi installation drive, and /dev/sda with where you want to store it to.

On mac, you can see all the drives and their paths by using this command. Source: https://pbxbook.com/other/dd_clone.html

diskutil list

The output should inform you on what disk you should be copying from. If it says /dev/disk5, then use /dev/rdisk5 that is just prepend an ‘r’ in front of the drive name and it will work faster. For details see https://superuser.com/questions/631592/why-is-dev-rdisk-about-20-times-faster-than-dev-disk-in-mac-os-x

# Warning: Do not do this on a raspberry pi system that is powered on. It might work, but might not since your system may write stuff at the same time.
sudo dd if=/dev/rdisk5 of=/dev/sda bs=4M status=progress

If you’d like to save the data to a file on your computer, use the following command. When running this on my own system, it took a long time (about 25 minutes or so), and doesn’t provide any output while running, so be patient with it when it is running. Source: https://forums.raspberrypi.com/viewtopic.php?t=46911

sudo dd bs=4M if=/dev/rdisk5 | gzip > ~/image`date +%d%m%y`.gz

To restore to a disk, use the following code. Source: https://forums.raspberrypi.com/viewtopic.php?t=46911

sudo gzip -dc /home/your_username/image.gz | dd bs=4M of=/dev/sdb

Then at the end, I swapped the SD cards to verify that the backup worked and it did!

For the people willing to install more stuff

Additionally if you installed zstd and pv, you can use combine them for a small and fast file with estimation replace 60906M with your estimate of the transfer size or use it without the -s and 60906M to just have a progress bar without a time estimate:

sudo dd bs=4M if=/dev/rdisk5 | pv -s 60906M | zstd -3 > ~/ddpvomv64_image`date +%y%m%d`.img.zst

And to restore use:

sudo zstd -dc /Users/shawn/Downloads/omv16_duckdns_image240116.img.zst | pv -s 15700M | sudo dd bs=4M of=/dev/rdisk5

Thanks, Sources:

Others using dd: https://forums.raspberrypi.com/viewtopic.php?t=46911
To get progress working: https://askubuntu.com/questions/215505/how-do-you-monitor-the-progress-of-dd
For a more complete solution: https://github.com/RichardMidnight/pi-safe

Categories
Mobile Development

Using Kotlin multi-platform for Android and iOS with firebase

So I just started a new app that is being built for Android and iOS. I’m building it using kotlin multi-platform (KMP). I started it by following a guide on jetbrains’ website. I started it by following this guide. https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-getting-started.html#next-step after kdoctor said that my machine was ready for cross platform compilation I moved on to cloning this repo. https://github.com/JetBrains/compose-multiplatform-ios-android-template This app is using firebase so I had to integrate it into the app. I found this library which is a cross platform firebase library. https://github.com/GitLiveApp/firebase-kotlin-sdk Getting it set up was a bit difficult as the app kept crashing everytime I tried to use firebase for anything. I later found this guide but as it is the only one online, and seems to miss a few pain points that I found. https://medium.com/@carlosgub/how-to-implement-firebase-firestore-in-kotlin-multiplatform-mobile-with-compose-multiplatform-32b66cdba9f7 So I’m writing this to document my process and and pain points so that if anyone else wants to do this they can. Also, it should be noted that I started with the Authentication library.

Adding the KMP firebase Authentication library to Android

Step 1: add this line to the plugins block of the project level build.gradle.kts that file can be found in the project root directory.

id("com.google.gms.google-services") version "4.4.0" apply false

Step 2: Add the following to the plugins block of the androidApp build.gradle.kts

id("com.google.gms.google-services") // This line to add the google-services

It’s also a good time to make sure that the “applicationId” in that build.gradle.kts matches what you intend to use on firebase.

Step 3: Add this to the shared module build.gradle.kts inside of the kotlin -> sourceSets -> commonMain -> dependencies blocks

api("dev.gitlive:firebase-auth:1.10.4")

Step 4: Add your android app to firebase and put your google-services.json file in the androidApp module root folder as is shown below.

Step 5: Add this to your AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step 6: And the following to the MainActivity.kt right after super.onCreate(savedInstanceState) and before the setContent block

        Firebase.initialize(this)

After these changes you should be able to run the Android version of the app. An iOS build will fail until the next set of steps below are complete.

Adding the KMP firebase Authentication library to iOS

For the iOS app, you need to add the following lines to the iOSApp.swift
the import FirebaseCore statement, the AppDelegate class and the line in the code below that starts with @UIApplicationDelegateAdaptor

import SwiftUI
import FirebaseCore

class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()

return true
}
}

@main
struct iOSApp: App {

@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

You’ll need to register your app in firebase just like the Android app. Then you’ll need to copy the GoogleService-info.plist to the right spot in the file system as shown below.

Next open the iOSApp in xcode by navigating to the iOSApp folder and double clicking on the iosApp.xcodeproj file.

Once open, I had to add the firebase-ios-sdk package to the iOS app

Then click the “Add Package” button

Then click the libraries that you want to add, and click “Add Package”

The builds for iOS were still failing until I did the following steps. For some reason it wasn’t detecting the GoogleServices file. So I right clicked the iOSApp folder in xcode, and then “Add Files to “iosApp””

When the file dialog opens, just select the GoogleServices-info.plist file, and click “Add”.

Finally, the iOS app should build properly.

Categories
Uncategorized

QR codes

QR code text data formats

So I’ve been playing around with QR codes. I wanted to know how to generate different data that can be read by a phone. I found the following page that describes how to format the data using text only.
https://github.com/zxing/zxing/wiki/Barcode-Contents

Save space using all caps

QR codes have a special format for data that is in all caps and if you use it, the QR code will use less data. My understanding is that all you have to do to use it is to write the text in all caps (can include numbers and these symbols $, %, *, +, -, ., /, :, and space) and the QR code generator should automatically figure out how to represent it using less data. The downside is that some urls are case sensitive, so make sure to test the url before you print it.
Alphanumeric mode is for the decimal digits 0 through 9, as well as uppercase letters (not lowercase!), and the symbols $, %, *, +, -, ., /, and : as well as a space.” Source: https://www.thonky.com/qr-code-tutorial/data-analysis
Further reading here https://www.thonky.com/qr-code-tutorial/introduction

Finally a QR code that links to this page:

A QR-code that links to this page
Categories
Server admin

Ubuntu has a firewall enabled by default

So when setting up my ubuntu server. I was running into issues connecting from different machines on my local network. I ran a port scan using nmap to see that many ports were filtered. I tried many things, but in the end one simple command fixed it.

sudo ufw disable
Categories
Server admin

Upgrading portainer

To make this, I followed the guide posted here. https://docs.portainer.io/v/ce-2.9/start/upgrade/docker The latest portainer at the time of writing is portainer version 2.14.1 please replace that string with the latest version when using the following commands.

sudo docker stop portainer
sudo docker rm portainer
sudo docker pull portainer/portainer-ce:2.14.1
sudo docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 \
    --name=portainer --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v portainer_data:/data \
    portainer/portainer-ce:2.14.1
Categories
Server admin

Installing Docker and Portainer

So I recently needed to install docker and portainer so that I could run a few services on my server.

Installing docker

This is just helpful links for installing docker on ubuntu or lubuntu for me on lubuntu 22.04.
the most important commands on that were:

sudo apt update && sudo apt upgrade -y
sudo apt install docker.io
docker --version

After that you should be able to to test that your installation is installed and running.

How to install portainer once you have docker running

My main source for this section is https://docs.portainer.io/v/ce-2.9/start/install/server/docker/linux
The most important important commands to run from that article are below.

sudo docker volume create portainer_data
sudo docker container run -d --name portainer -p 8080:9000 \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data portainer/portainer
sudo docker start portainer
sudo docker container ls

To login to portainer

To login to portainer, the instructions say to use https://localhost:9443 of course I’m logging in remotely, so I thought that I could just replace localhost with the ip address of my server, but that didn’t work, but port forwarding with an ssh tunnel did work. To forward the port, I had to run the following command

ssh -L localhost:9443:localhost:9443 [email protected]
in chrome: https://localhost:9443

Only after running that command, could I use the localhost address in chrome on my remote machine.