Skip to main content

Execute bash scripts on top of KDEConnect's sftp mount

Project description

kcb

Python helper to execute bash scripts inside KDEConnect's sftp mount. The main motivation behind this helper is to backup my smartphone's photos and Whatsapp folders with a single command and without resorting to a file manager. The approach however allows a whole range of possible use cases.

Installation and configuration

pip3 install --user kcb
mkdir ~/.config/kcb
wget https://raw.githubusercontent.com/ReSqAr/kcb/master/Documentation/Examples/My%20Smartphone.sh -O ~/.config/kcb/"PHONENAME.sh"
chown u+x ~/.config/kcb/PHONENAME.sh
pico ~/.config/kcb/PHONENAME.sh

One has to repeat the last three lines such that in the end the local ~/.config/kcb/ folder contains bash scripts for all phones. Here PHONENAME is a placeholder for the KDEConnect phone name and phones without a corresponding bash script are ignored. These scripts can assume that they are run in the phone's sftp mount point, i.e. the folders DCIM, Downloads, Android, etc are actually directly visible. One should note that the connection can drop, hence the bash script must be sufficiently resilient to avoid tears.

Example bash scripts

The following is a sample bash script which backups the photo folder, OSMAnd's GPS tracks and the WhatsApp folder to the local ~/MySmartphone folder.

set -x

TARGET="~/MySmartphone"

echo "file listing"
ls

echo "GPS Tracks"
rsync --human-readable --progress --archive --ignore-existing --itemize-changes --prune-empty-dirs "Android/data/net.osmand.plus/files/tracks/rec/" "$TARGET/GPS Tracks/"

echo "WhatsApp"
rsync --human-readable --progress --archive --ignore-existing --itemize-changes --prune-empty-dirs "WhatsApp/" "$TARGET/WhatsApp/"

echo "Photos"
rsync --human-readable --progress --archive --ignore-existing --itemize-changes --prune-empty-dirs "DCIM/Camera/" "$TARGET/"

Usage

Since we installed the kcb executable in ~/.local/bin/, we start the application via ~/.local/bin/kcb. There are multiple ways around that, i.e. being able to just type kcb; one could add ~/.local/bin to the $PATH variable for example or - however use that at your own peril - by running the pip3 command as root.

Regarding the command line parameters of kcb, you can run kcb without any parameters in which case all bash scripts of all phones which are online are executed. Or you can list the names of the devices whose bash scripts should be executed.

Example usage

Assume that KDE Connect knows two smartphones named OnePlus and Samsung S8.

  • kcb OnePlus executes just OnePlus.sh (if it exists)
  • kcb "Samsung S8" executes just Samsung S8.sh (if it exists)
  • kcb executes both shell scripts (if they exist)
  • kcb OnePlus "Samsung S8" executes both shell scripts (if they exist)

License

Released under the GPL 3.

Contact

For bug reports please use the GitHub bug tracker. I would love to hear from you about your thoughts/use cases/etc, just drop me a line via yasin.zaehringer-kcb@yhjz.de.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kcb-0.9.2.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kcb-0.9.2.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file kcb-0.9.2.1.tar.gz.

File metadata

  • Download URL: kcb-0.9.2.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for kcb-0.9.2.1.tar.gz
Algorithm Hash digest
SHA256 d4706de18aa5012773ec78095a554f417d06f6f77795c0532049cda613ab8c1e
MD5 9d8567d33d8ddc36d9711ab2d7d70826
BLAKE2b-256 7f6e7902ef81596f43f057ae6ae4087d208e15f921d0eba762bef43aa62554c4

See more details on using hashes here.

File details

Details for the file kcb-0.9.2.1-py3-none-any.whl.

File metadata

  • Download URL: kcb-0.9.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for kcb-0.9.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 687138e906aab4b0209e0dc190f957924826c835bdc35348788381ff151096c4
MD5 abc5a59e598ca626f7f14bf30c4f1025
BLAKE2b-256 0228eafe15faeb531f61a7fd7ec3db54c006c218087e1228b887f9dc423d5b76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page