This is a way to write and share notes for yourself between multiple devices, without signing up for locked-in cloud services, using only future-proof formats and open tools!
This is built on Android and Obsidian, which are only semi-open, but because it's built on syncing with git and markdown if you need to replace the platform you can, because markdown and git work everywhere and will continue to work everywhere for a long time.
(Android) phone:
-
(Optional) Install Markor which is a more fully-featured markdown editor
-
- pay attention to all the setup steps, especially "Draw over other apps"
- add the Widget to your homescreen
-
- open the Termux:API launcher and:
- Disable Battery Optimiziations
- enable Draw Over Other Apps
pkg install termux-api
to give Termux access to it
- open the Termux:API launcher and:
-
termux-setup-storage
+ allow access to files (if not already done) -
pkg install jq openssh git termux-api termux-services
-
Relaunch termux to load
sv
(fromtermux-services
) -
Install scripts below to
~/.shortcuts/sync-notes
and~/.local/bin/android_ssh_askpass
.Remember to
chmod +x
both of them. -
Make an ssh key
ssh-keygen -t ed25519
- (optional but STRONGLY recommended): set a passphrase on the key. This will mean you need to unlock the key.
cat ~/.ssh/id_ed25519.pub
+ copy the public key and send it to yourself- Install the key on whatever git server you're using
-
Set up a git repo:
cd storage/shared git clone git+ssh://yhour-server/your-path/to-diary-repo.git Diary
OR if you're starting from scratch:
Open Diary at least once so that it creates its default folder, then sync that folder to a git server.
cd storage/shared/Diary git init git remote add origin git+ssh://yhour-server/your-path/to-diary-repo.git git push -u origin
but it's probably easier to init the repo from anywhere that's not your phone -- do it from your desktop, with Obsidian and GitHub/Lab/BitBucket/Forgejo/your own server with ssh access handy.
-
If you set a passphrase, make it remain unlocked in RAM
(or you'll be re-unlocking it every 15 minutes)
sv enable ssh-agent
- Install Termux:Boot
- make sure to follow the setup steps, especially disabling battery optimizations for both Termux and Termux:Boot
- Install
~/.termux/boot/start-services
(from below) - Run
termux-wake-lock
at least once and accept the "Disable battery optimizations" prompt that comes up (TODO: why does this have to be done twice? did I just not do it right the first time?) - Add
export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR:-"${TERMUX__PREFIX:-"${PREFIX}"}/var/run"}"/ssh-agent.socket
to~/.bashrc
- Reboot.
-
(optional) Tune git to better defaults
(these are my preferences, read about them first)
git config --global advice.mergeConflict false git config --global merge.conflictStyle diff3 git config --global push.default current git config --global push.autosetupremote true
-
git config --global --add safe.directory /storage/emulated/0/Diary
-- annoyingly, because the shared storage perms are..faked? -
Test:
- run
~/.shortcuts/sync-notes
from Termux - run 'sync-notes' from the Termux:Widget on your Homescreen
- run
-
If works, schedule it:
termux-job-scheduler --job-id "$RANDOM" -s ~/.shortcuts/sync-notes --period-ms 900000 --persisted true
--job-id
defaults to 0 if not given, and would mean multiple jobs overwrite each other.
Now your notes should also automatically attempt a sync every 15 minutes.
If the sync fails due to network problems or a conflict, your notes will be left untouched but you will get a notification about it, and you should cd storage/shared/Diary
and attempt git pull
to investigate the situation. If you have conflicts you will have to fix them using Diary or Markor, or maybe vi if you're comfortable with vi, and then recommit and push.
Desktop:
- these are the only markdown editors that currently exist that understand folders.
- install Obsidian-Git and configure it to
- commit-and-sync every 15 minutes
- commit-and-sync on opening
- there are lot of plugins for obsidian that help; but I don't want to become reliant on them
Server:
- Git
- (Optional) GitHub/Gitea/Gitlab/Forgejo (to get a web-based diary) 2. TODO: link to a guide to setup mkdocs
-
Edit files on phone
-
Wait for sync to happen in the background.
- If it errors you will get the error as a notification, and also in
logcat
- If it errors you will get the error as a notification, and also in
-
Run
sync-notes
manually if you don't want to wait; it will pop to the foreground.- If it errors, you will see the error message on screen, and also in
logcat
- If it errors, you will see the error message on screen, and also in
-
It will prompt you if it needs the key (on first boot, or if it's been idle long enough that Android has killed the background termux session)
- Obsidian cloud
- PuppyGit (see demo)
- the various orgmode apps in fdroid? I haven't explored these too much, but I think some of them do syncing?
- EverNote, Notion
View log:
adb logcat | grep sync_notes
- Android is very kill-happy. Termux:Boot doesn't seem to be doing it's job of providing
ssh-agent
, and therefore the unlock prompt comes up over and over again.- Workaround: launching Termux and just leaving it in the background keeps
ssh-agent
alive. - To investigate: does using
termux-wake-lock
as recommended prevent this? Doestermux-wake-lock
have other negative consequences? - To investigate: instead of using the Android job scheduler, use a Termux:Widget ~/.shortcuts/tasks instead. Can that stay up in the background without being killed?
- Workaround: launching Termux and just leaving it in the background keeps
Handle multiple repos
Handle read-only repositories (i.e. disable the push step)
There's something unreliable about
sv start ssh-agent
.Sometimes it spawns new processes and doesn't record 'up' in
$PREFIX/var/service/ssh-agent/supervise/stat
nor the PID in$PREFIX/var/service/ssh-agent/supervise/pid
.rm /data/data/com.termux/files/usr/var/run/ssh-agent.socket
+ restarting may have fixed it??sv-enable
in the script doesn't do anything when run from Termux:WidgetIt says
which is because SVDIR isn't getting exported.... moreover, if SVDIR is exported, then
sv-enable; sv start
says "fail: ssh-agent: runsv not running" and cause ssh-agent to reset and forget the ssh keys! but if run from the termux shell it's fine??