acedanger revised this gist 1 year ago. Go to revision
1 file changed, 37 insertions
import-github-gist-oauth.sh(file created)
| @@ -0,0 +1,37 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | # GitHub Gist import script using GitHub token for authentication | |
| 3 | + | # This script works by first logging in via GitHub OAuth and then importing | |
| 4 | + | ||
| 5 | + | github_user=acedanger | |
| 6 | + | opengist_url="https://gist.ptrwd.com" | |
| 7 | + | ||
| 8 | + | echo "This script requires you to first log in to OpenGist via GitHub OAuth." | |
| 9 | + | echo "Please visit: $opengist_url" | |
| 10 | + | echo "Log in with your GitHub account, then return here and press Enter to continue..." | |
| 11 | + | read -p "Press Enter when you've logged in via GitHub OAuth: " | |
| 12 | + | ||
| 13 | + | echo "Starting GitHub Gist import..." | |
| 14 | + | ||
| 15 | + | curl -s https://api.github.com/users/"$github_user"/gists?per_page=100 | jq '.[] | .git_pull_url' -r | while read url; do | |
| 16 | + | echo "Processing gist: $url" | |
| 17 | + | git clone "$url" | |
| 18 | + | repo_dir=$(basename "$url" .git) | |
| 19 | + | ||
| 20 | + | if [ -d "$repo_dir" ]; then | |
| 21 | + | cd "$repo_dir" | |
| 22 | + | ||
| 23 | + | # Use the web-based authentication by prompting the user | |
| 24 | + | echo "For repository $repo_dir, you'll need to authenticate via browser..." | |
| 25 | + | echo "When prompted, use your GitHub credentials that you used to log in to OpenGist" | |
| 26 | + | ||
| 27 | + | # Add remote and push | |
| 28 | + | git remote add gist "$opengist_url/init" | |
| 29 | + | git push -u gist --all | |
| 30 | + | ||
| 31 | + | cd .. | |
| 32 | + | rm -rf "$repo_dir" | |
| 33 | + | echo "Completed import of $repo_dir" | |
| 34 | + | fi | |
| 35 | + | done | |
| 36 | + | ||
| 37 | + | echo "Import process completed!" | |
Newer
Older