SparkleShare is an open source, Dropbox style file sharing application based on Git. Learn about little-known uses of Git in our series.

Git is one of the few applications that encapsulates so much modern computing in a single program, and it can be used as a computing engine for many other applications. While it’s best known for tracking source code changes in software development, it has many other uses that can make your life easier and more organized. In this Git series, we’ll share seven little-known ways to use Git.

Today, we’ll take a look at SparkleShare, which uses Git as the basis for file sharing.

Git for file sharing

One of the advantages of Git is its inherent distribution capabilities. It can be used to establish a share. Git brings transparency to retrieving files from a shared location, even if you’re only sharing repositories with other computers on your network.

As its interface has evolved, Git has become very simple. Although it varies from user to user, all they have in common when they sit down to get some work done is git pull or slightly more complicated git pull && git checkout -b my-branch. For some people, however, entering commands into their computer can be completely confusing or annoying. Computers are designed to make life easier, and because they excel at repetitive tasks, there is an easier way to share files with Git.

SparkleShare

SparkleShare project is a cross-platform, open source, Dropbox-style file sharing application based on Git. It automatically executes all Git commands, triggering add, commit, push, and pull processes by simply dragging and dropping files into a specially designated SparkleShare directory. Because it’s git-based, you get quick push and pull based on diff, and inherit all the benefits of Git version control and back-end infrastructure like Git hooks. It can be fully self-hosted or used with Git hosting services such as GitLab, GitHub, and Bitbucket. Also, because it’s basically just a Git front end, you can access files in SparkleShare on devices that may not have SparkleShare clients, but do have Git clients.

Just as you get all the benefits of Git, you’re also subject to all the usual Git limitations: Storing hundreds of photos, music, and videos with SparkleShare is impractical because Git is designed and optimized for text. Git can certainly store large files of binaries, but because it can keep track of history, it’s nearly impossible to remove a file completely once it’s been added to it. This somewhat limits SparkleShare’s usefulness for some people, but makes it ideal for many workflows, including scheduling.

Install the SparkleShare

SparkleShare is cross-platform, with Windows and Mac installers available from the website. For Linux, there is a Flatpak installation package, or you can run the following command from the terminal:

$ sudo flatpak remote-add flathub https://flathub.org/repo/flathub.flatpakrepo
$ sudo flatpak install flathub org.sparkleshare.SparkleShare
Copy the code

Create a Git repository

SparkleShare is not software as a service (SaaS). You run SparkleShare on your computer to communicate with your Git repository, and SparkleShare doesn’t store your data. If you don’t already have a Git repository that syncs with folders, you must create a folder before starting SparkleShare. You have three options: hosted Git, self-hosted Git, or self-hosted SparkleShare.

Hosting Git

SparkleShare can be stored using any Git repository you have access to, so if you have an account (or create one) for GitLab or any other hosting service, it can be the back end of SparkleShare. For example, the open source Notabug.org service is a Git hosting service similar to GitHub and GitLab, but unique enough to demonstrate SparkleShare’s flexibility. Different managed services create new repositories differently depending on the user interface, but all major repositories follow the same general model.

First, find the button to create a new project or repository in the managed service and click it to get started. You then step through the repository creation process, providing the repository name, privacy level (the repository is usually public by default), and whether to initialize the repository with a README file. Whether you need a README file or not, initialize one. Using a file to create the repository is not absolutely necessary, but it forces the Git host to instantiate the Master branch in the repository, which helps ensure that front-end applications (such as SparkleShare) have branches to commit and push. Even if the file is a nearly empty README file, you can view it to confirm that you connected successfully.

Creating a Git repository

After the repository is created, get its URL for SSH cloning. You can get this URL just as you get it from your Git project: navigate to the repository page and look for the “Clone” button or field.

Cloning a URL on GitHub

GitHub clone URL.

Cloning a URL on GitLab

GitLab’s clone URL.

This is the address SparkleShare uses to get data, so make a note of it. Your Git repository is now configured.

Self-hosted Git

You can use SparkleShare to access Git repositories on any computer you have access to. Aside from a bare Git repository, no special Settings are required. However, if you want to grant access to your Git repository to anyone else, you should run a Git manager like Gitolite or SparkleShare’s own Dazzle server to help you manage your SSH keys and accounts. At a minimum, create a Git-specific user so that users with access to your Git repository don’t automatically gain access to the rest of the server.

Log in to the server as a Git user (or your own if you are very good at managing user and group permissions) and create the repository:

$ mkdir ~/sparkly.git
$ cd ~/sparkly.git
$ git init --bare .
Copy the code

Your Git repository is now configured.

Dazzle

SparkleShare developers provide a Git management system called Dazzle to help you self-host your Git repository.

On your server, download the Dazzle application to a location in your path:

$ curl https://raw.githubusercontent.com/hbons/Dazzle/master/dazzle.sh --output ~/bin/dazzle
$ chmod +x ~/bin/dazzle
Copy the code

Dazzle sets up a user specific to Git and SparkleShare, and also implements access based on keys generated by the SparkleShare application. Now, just set up one project:

$ dazzle create sparkly
Copy the code

Your server is now configured to be used as SparkleShare hosting.

Configuration SparkleShare

When You first start SparkleShare, you will be prompted to configure the server SparkleShare will use for storage. This process may look like a first-time setup wizard, but it’s actually the usual process for setting up a new shared location in SparkleShare. Unlike many shared drive applications, you can configure multiple locations at once with SparkleShare. The first shared location you configure is no more important than any other shared location you can configure later, and you don’t have to sign up for SparkleShare or any other service. You just point SparkleShare to the Git repository so that it knows how to keep the first SparkleShare folder in sync.

On the first screen, you give an identity that SparkleShare will use in the Git commit record it makes on your behalf. You can use anything, even fake information that doesn’t mean anything. It is only used for submitting messages, and if you are not interested in reviewing Git backend processes, you may not even see them.

The next screen prompts you to select the host type. If you’re using GitLab, GitHub, Planio, or Bitbucket, you can choose an appropriate one. Otherwise, select Your own server.

Choosing a Sparkleshare host

At the bottom of this screen, you must enter the SSH clone URL. If you are self-hosting Git, the address is something like < SSH ://[email protected]>, and the remote path is the absolute path to the Git repository created for this purpose.

Based on the self-hosted example above, the address of my fictitious server is SSH ://[email protected]:22122 (:22122 indicates a non-standard SSH port) and the remote path is /home/git/sparkly.git.

If I use the Notabug.org account, the above example address is SSH ://[email protected] and the path is Seth /sparkly.git.

SparkleShare’s first attempt to connect to the host will fail because you haven’t copied the SparkleShare client ID (the SSH key specific to the SparkleShare application) to the Git host. This is expected, so do not cancel the process. Leave the SparkleShare Settings window open and get the client ID from the SparkleShare icon in the system taskbar. Then copy the client ID to the clipboard so it can be added to the Git host.

Getting the client ID from Sparkleshare

Add your client ID to your managed Git account

Aside from minor UI differences, the process for adding an SSH key (as is the case for all client ids) on any managed service is essentially the same. In the Web dashboard of your Git host, navigate to your user Settings and find the “SSH Key” category. Click the Add New Key button (or similar) and paste the contents of your SparkleShare client ID.

Adding an SSH key

Save the key. If you want others (such as collaborators or family members) to have access to the same repository, they must provide you with their SparkleShare client ID so you can add it to the account.

Add your client ID to your self-hosted Git account

The SparkleShare client ID is just an SSH key, so copy and paste it into the ~/.ssh/authorized_keys file of your Git user.

Use Dazzle to add your customer ID

If you are using Dazzle to manage SparkleShare projects, add the client ID using the following command:

$ dazzle link
Copy the code

When the Dazzle prompts you for this ID, paste the client ID you found in the SparkleShare menu.

Using SparkleShare

After adding the client ID to the Git host, click the Retry button in the SparkleShare window to complete the setup. Once the clone repository is complete, you can close the SparkleShare Settings window and find a new SparkleShare folder in your home directory. If you set up a Git repository with a hosting service and choose to include README files or license files, you’ll see them in the SparkleShare directory.

Sparkleshare file manager

In addition, there are some hidden directories that you can view by displaying hidden directories in file Manager.

Showing hidden files in GNOME

You use SparkleShare the same way you would use any directory on your computer: you put your files into it. Every time you put a file or directory into the SparkleShare folder, it copies to your Git repository in the background.

Exclude certain files

Since Git is designed to remember everything, you may want to exclude specific file types from your records. There’s a reason to exclude some files. By defining files that are not managed by SparkleShare, you can avoid accidentally copying large files. You can also design a scheme for yourself that lets you store in a directory that logically belongs to the same file (for example, a MIDI file and its.flac export file), but can manually back up large files yourself while having SparkleShare back up text-based files.

If you do not see hidden files in your system’s file manager, show them. Navigate to your SparkleShare folder, then to the directory that represents your repository, find a file called.gitignore, and open it in a text editor. You can enter the file extension or filename (one per line) in.gitignore, and any files that match the ones you list will be ignored (as shown in the filename).

Thumbs.db
$RECYCLE.BIN/
.DS_Store
._*
.fseventsd
.Spotlight-V100
.Trashes
.directory
.Trash-*
*.wav
*.ogg
*.flac
*.mp3
*.m4a
*.opus
*.jpg
*.png
*.mp4
*.mov
*.mkv
*.avi
*.pdf
*.djvu
*.epub
*.od{s,t}
*.cbz
Copy the code

You know which file types you encounter most often, so concentrate on the files that are most likely to sneak into your SparkleShare directory. If you want to overcorrect a bit, you can find a good collection of.gitignore files at Notabug.org and throughout the web.

By storing these entries in a.gitignore file, you can place large files that don’t need to be sent to Git hosts in the SparkleShare directory, where SparkleShare will ignore them completely. Of course, this means you need to make sure they can be backed up or otherwise distributed to your SparkleShare collaborators.

automation

Automation is one of the tacit understandings we have with computers: they perform repetitive, boring tasks that we humans are either bad at or bad at remembering. SparkleShare is a good, simple way to automate routine data distribution. However, this is not suitable for every Git repository. It has no interface for advanced Git functionality, no pause button or manual administration. It doesn’t matter, because its use is deliberately limited. SparkleShare does what it sets out to do, it does it well, and it’s a Git repository you don’t need to care about.

If you want to use this kind of stable, invisible automation, try SparkleShare.


Via: opensource.com/article/19/…

By Seth Kenlon (lujun9972

This article is originally compiled by LCTT and released in Linux China