Skip to content

Commit 7829e98

Browse files
authored
Add Linux support (#1)
* Format missing indentation * Add Linux support using libsecret-tools (secret-tool command) * Add Linux instructions to README
1 parent 08904b7 commit 7829e98

2 files changed

Lines changed: 51 additions & 16 deletions

File tree

README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ What is dotfilesync?
66

77
dotfilesync is a bash script that syncs a list of local files that _you_ define, into a secret gist, that _you_ own.
88

9-
dotfilesync is very easy to use as it stores your gist credentials into Mac OS X Keychain, so you don't have to provide it each time.
9+
dotfilesync is very easy to use as it stores your gist credentials into an encrypted Keychain, so you don't have to provide it each time.
1010

1111
You are not limited to syncing only dotfiles. Although this tool is meant for you to sync local dotfiles, it can also be used to sync any file that can be synced with gist.
1212

@@ -36,9 +36,13 @@ A sample config shape can look like this:
3636
}
3737
```
3838

39-
### Uses OS X Keychain
39+
### Tools used as Keychain
4040

41-
The tool uses [OSX security](https://ss64.com/osx/security.html) command to manage your GitHub Personal Access Token within your Keychain. This way your token is safe and encrypted by the Keychain, and you don't have to provide it each time you run the command to sync files.
41+
This tool stores and manage your GitHub Personal Access Token within into an encrypted Keychain. This way your token is safe and encrypted by the Keychain, and you don't have to provide it each time you run the command to sync files.
42+
43+
For OS X based operating systems, the [OSX security](https://ss64.com/osx/security.html) command is used.
44+
45+
For Linux based operating systems, the [secret-tools](http://www.linuxfromscratch.org/blfs/view/svn/gnome/libsecret.html) command is used to interact with [GnomeKeyring](https://wiki.gnome.org/Projects/GnomeKeyring). For more info about keyrings used on Linux systems [read this article](https://rtfm.co.ua/en/what-is-linux-keyring-gnome-keyring-secret-service-and-d-bus/#Linux_keyring_vs_gnome-keyring).
4246

4347
### Sync multiple files into a single secret gist
4448

@@ -59,10 +63,18 @@ During a fetch operation (syncing local files from gist), a sync is performed, o
5963
Prerequisites
6064
-------------
6165

62-
This script uses [jq](https://stedolan.github.io/jq/download/) to parse the `config.json` on the local filesystem. You can run the following command on OS X, if you have [Homebrew](https://brew.sh/) installed:
66+
This script uses [jq](https://stedolan.github.io/jq/download/) to parse the `config.json` on the local filesystem.
67+
68+
## OS X
69+
You can run the following command on OS X, if you have [Homebrew](https://brew.sh/) installed:
6370

6471
brew install jq
6572

73+
## Linux
74+
You can install the required packages on a Debian based distro running the following command:
75+
76+
apt-get install jq libsecret-tools
77+
6678
Installation
6779
------------
6880

@@ -77,13 +89,13 @@ Ensure the [prerequisite](#prerequisites) tools are setup. Installing dotfilesyn
7789
* With curl:
7890

7991
mkdir -p ${HOME}/.dotfilesync \
80-
&& curl -fsSL https://raw.githubusercontent.com/snvishna/dotfilesync/master/src/dfsync_osx.sh \
92+
&& curl -fsSL https://raw.githubusercontent.com/snvishna/dotfilesync/master/src/dfsync.sh \
8193
>| ${HOME}/.dotfilesync/dfsync.sh
8294

8395
* With wget:
8496

8597
mkdir -p ${HOME}/.dotfilesync \
86-
&& wget -nv -O - https://raw.githubusercontent.com/snvishna/dotfilesync/master/src/dfsync_osx.sh \
98+
&& wget -nv -O - https://raw.githubusercontent.com/snvishna/dotfilesync/master/src/dfsync.sh \
8799
>| ${HOME}/.dotfilesync/dfsync.sh
88100

89101
3. Add an entry in zshrc:
@@ -98,7 +110,7 @@ Ensure the [prerequisite](#prerequisites) tools are setup. Installing dotfilesyn
98110

99111
You can create a new [person access tokens page](https://github.com/settings/tokens/new) for running the script on the command line. Follow [these instructions](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) on how to create one. Make sure you have the __gist__ scope selected to grant permission on this token.
100112

101-
Once you generate the personal access token, either copy it on your clipboard, or save it somewhere, since the script will need this to store within the OS X Keychain, before syncing your files in gist.
113+
Once you generate the personal access token, either copy it on your clipboard, or save it somewhere, since the script will need this to store within the Keychain, before syncing your files in gist.
102114

103115
![](./resources/generate_personal_access_token.gif)
104116

@@ -124,7 +136,7 @@ Commands
124136

125137
It is run only __once__ as part of the installation instructions. This command does the following:
126138

127-
* Prompts for your GitHub username and the personal access token. It then stores this information securely in the OS X Keychain.
139+
* Prompts for your GitHub username and the personal access token. It then stores this information securely in the Keychain.
128140

129141
* Creates a new secret gist in your account with the description - "Generated by dotfilesync utility".
130142

@@ -152,7 +164,7 @@ Commands
152164

153165
This command will do the following:
154166

155-
* Delete the saved GitHub gist credentials from the OS X Keychain.
167+
* Delete the saved GitHub gist credentials from the Keychain.
156168
* Delete `config.json` file from the `${HOME}/.dotfilesync` directory.
157169
* It does not automatically delete the saved gist from your GitHub account. Rather, it prints out the HTTP link to your gist, so you can choose to delete it.
158170
* It provides a link to the uninstall instructions in this README, so you can run the commands to delete the script and update the zsh config.
@@ -164,7 +176,7 @@ You can cleanup the script and all resources created by it, using the following
164176

165177
* __Run__ `dfsync cleanup`
166178

167-
You can run the command to 1) Delete the saved GitHub gist credentials from the OS X Keychain 2) Delete `config.json` file from the `${HOME}/.dotfilesync` directory.
179+
You can run the command to 1) Delete the saved GitHub gist credentials from the Keychain 2) Delete `config.json` file from the `${HOME}/.dotfilesync` directory.
168180

169181
* __Delete the gist__
170182

src/dfsync_osx.sh renamed to src/dfsync.sh

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,44 @@ HOME_DIR=~
88
DOTFILESYNC_ROOT_PATH="~/.dotfilesync"
99
DOTFILESYNC_CONFIG_PATH="$DOTFILESYNC_ROOT_PATH/config.json"
1010
eval DOTFILESYNC_CONFIG=$DOTFILESYNC_CONFIG_PATH
11+
UNAME="$( command -v uname )"
12+
OSTYPE="$( "${UNAME}" | tr '[:upper:]' '[:lower:]')"
1113

1214
backup() {
1315
cp -n $1{,.bak."$(date +%Y%m%d-%H%M%S)"}
1416
}
1517

1618
addKeychainPassword() {
17-
security add-generic-password -a $1 -s $3 -w $2
19+
case $OSTYPE in
20+
darwin*)
21+
security add-generic-password -a $1 -s $3 -w $2
22+
;;
23+
linux*)
24+
echo $2 | secret-tool store --label $3 user $1 usage $3
25+
;;
26+
esac
1827
}
1928

2029
getKeychainPassword() {
21-
security find-generic-password -wga $1 -s $2
30+
case $OSTYPE in
31+
darwin*)
32+
security find-generic-password -wga $1 -s $2
33+
;;
34+
linux*)
35+
secret-tool lookup user $1 usage $2
36+
;;
37+
esac
2238
}
2339

2440
deleteKeychainPassword() {
25-
security delete-generic-password -a $1 -s $2
41+
case $OSTYPE in
42+
darwin*)
43+
security delete-generic-password -a $1 -s $2
44+
;;
45+
linux*)
46+
secret-tool clear user $1 usage $2
47+
;;
48+
esac
2649
}
2750

2851
getGistFileName() {
@@ -121,9 +144,9 @@ push() {
121144
read -r -p "Pushing $row to $fileName?" put_confirm_response
122145
if [[ "$put_confirm_response" =~ ^([yY][eE][sS]|[yY])$ ]];
123146
then
124-
# Workaround for "No such file or directory" error when using ~ in the path: https://stackoverflow.com/a/3963747/640607
125-
local absolutePath=$(echo $row | sed -e "s:~/:$homedir/:g")
126-
cat $absolutePath | updateGistFile $github_user $github_password $dotfiles_gistid $fileName
147+
# Workaround for "No such file or directory" error when using ~ in the path: https://stackoverflow.com/a/3963747/640607
148+
local absolutePath=$(echo $row | sed -e "s:~/:$homedir/:g")
149+
cat $absolutePath | updateGistFile $github_user $github_password $dotfiles_gistid $fileName
127150
fi
128151
done
129152
}

0 commit comments

Comments
 (0)