[Mobile] Sync with git on iOS for free using iSH

I strongly dislike the idea of having my notes unencrypted on a hosting service like github so I extended the idea to support end-to-end symmetric AES256 encryption using gnupg on iSH. As the encryption is open source and cross platform you can decrypt your notes anywhere.

Steps:

  1. Make a folders /obsidian and initialize a git repository. This will be a local git repo for rollbacks (see why it is needed later).
  2. Make a subfolder /obsidian/vaults. Mount your ios obsidian folder here. Make sure to delete the .git file so the folder is staged correctly.
  3. Make a folder /syncrepo. This is the repo that pushes/pulls encrypted files to/from the remote.
  4. Initialize a repository in /syncrepo and connect it to your chosen remote repository.

Encryption is done using tar to compress the vaults folder into a single file, and then using gnupg to encrypt the file. As pulling involves overwriting parts of you existing vault, the local repository lets you rollback in case of an accidental pull.

  1. Make sure to install gnupg using apk add gnupg.
  2. Add the push/pull scripts to your root directory.

NOTE: Replace *** with your passphrase in scripts.


Pull script (~/pull)

#!/bin/sh

cd ~/obsidian
git add .
git commit -m "Save before pull"
echo "saved state before pull"

cd ~/syncrepo
git pull
cd ~
echo "pulled repo"

gpg -d --batch --cipher-algo AES256 --passphrase ****** -o - syncrepo/obsidianfile | tar -xzvf -
echo "uncompressed and decrypted"

Push script

#!/bin/sh

cd ~/obsidian
git add .
git commit -m "Save before Push"
echo "saved state before push"
cd ~

tar -czvf - obsidian/vaults | gpg -c --batch --cipher-algo AES256 --yes --passphrase ******* -o syncrepo/obsidianfile

echo "compressed and encrypted"

cd ~/syncrepo
git add .
git commit -m "Commit from Mobile"
git push
cd ~
echo "pushed to remote"
  1. Set both files to run as scripts chmod +x ./pull (and for ./push)
  2. Push/pull whatever content you please :smile:
3 Likes