From 8e93d4e726eedb924caa271d87c6e71cd03f368c Mon Sep 17 00:00:00 2001 From: glicOne Date: Mon, 4 Jun 2018 15:54:05 +0300 Subject: [PATCH] Upload files --- LICENSE | 13 ++++++++ README.md | 30 +++++++++++++++++++ backup.sh | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 backup.sh diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d8d2cbb --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + +Copyright (C) 2018 Eugene Obrezkov + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document, and changing it is allowed as long +as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5ff5b2d --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# Backup My GitHub Profile + +_Clones all your GitHub public repositories to your machine_ + +## Prerequisites + +- curl +- jq + +## Using + +Before starting the script, you need to generate personal access token on GitHub (**with full repo access**). +Follow this guide - [link](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) + +Afterwards, navigate to the folder, where you want to store repos: + +```bash +mkdir -p /some/path/to/folder/with/backups +cd /some/path/to/folder/with/backups +``` + +Run the script: + +```bash +bash <(curl -s https://raw.githubusercontent.com/ghaiklor/backup-my-github/master/backup.sh) +``` + +## License + +[DWTFYWT](./LICENSE) diff --git a/backup.sh b/backup.sh new file mode 100644 index 0000000..0fbc166 --- /dev/null +++ b/backup.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +set -e + +RESET_COLOR="\\033[0m" +RED_COLOR="\\033[0;31m" +GREEN_COLOR="\\033[0;32m" +BLUE_COLOR="\\033[0;34m" + +function reset_color() { + echo -e "${RESET_COLOR}\\c" +} + +function red_color() { + echo -e "${RED_COLOR}\\c" +} + +function green_color() { + echo -e "${GREEN_COLOR}\\c" +} + +function blue_color() { + echo -e "${BLUE_COLOR}\\c" +} + +function hello() { + blue_color + echo " " + echo " Backup My GitHub " + echo " " + echo " " + echo "This script will clone all your repositories from provided username to your machine" + echo "It will prompt you for your username account and personal access token" + echo "To generate token, please, refer this guide - https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line" + echo "Make sure, that your token has full access to repo scope!" + reset_color +} + +function checkForCurl() { + if ! [ "$(command -v curl)" ]; then + red_color + echo "You don't have installed curl" + exit 1 + else + green_color + echo "curl is present on your machine, continue..." + fi + + reset_color +} + +function checkForJQ() { + if ! [ "$(command -v jq)" ]; then + red_color + echo "You don't have installed jq" + exit 1 + else + green_color + echo "jq is present on your machine, continue..." + fi + + reset_color +} + +function cloneRepositories() { + green_color + echo + read -r -p "What is your username on GitHub: " username + read -r -p "What is your personal access token: " token + echo + + blue_color + repository_count=$(curl -XGET -s https://"${username}":"${token}"@api.github.com/users/"${username}" | jq -c --raw-output ".public_repos") + repositories=$(curl -XGET -s https://"${username}":"${token}"@api.github.com/users/"${username}"/repos?per_page="${repository_count}" | jq -c --raw-output ".[].ssh_url") + + for repository in ${repositories}; do + echo "Cloning ${repository}..." + git clone --quiet "${repository}" + done + + green_color + echo "All your repositories are successfully cloned in current directory" +} + +hello +checkForCurl +checkForJQ +cloneRepositories