Skip to content

Instantly share code, notes, and snippets.

@dbeley
Last active December 27, 2022 20:20

Revisions

  1. dbeley revised this gist Jan 31, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion archive_github_user_repos.sh
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ mkdir -p "$USER_DIR"
    [ -f "$USER_DIR/$USER.txt" ] && printf "##### $USER_DIR/$USER.txt file detected.\nDelete it if you want to update the repository list.\n"
    if [ ! -f "$USER_DIR/$USER.txt" ]; then
    printf "##### Extracting repos for $USER.\n"
    PAGE_NUMBER=`curl -sI "https://api.github.com/users/"$USER"/repos" | awk "/^Link/" | cut -d? -f3`
    PAGE_NUMBER=`curl -sI "https://api.github.com/users/"$USER"/repos" | awk "/^link/" | cut -d? -f3`
    for PAGE in `seq 1 ${PAGE_NUMBER//[!0-9]/}`; do
    printf "##### Extracting starred repos from page $PAGE\n"
    URL="https://api.github.com/users/$USER/repos?page=$PAGE"
  2. dbeley revised this gist Jan 20, 2021. 1 changed file with 20 additions and 15 deletions.
    35 changes: 20 additions & 15 deletions archive_github_user_repos.sh
    Original file line number Diff line number Diff line change
    @@ -8,29 +8,34 @@ Usage: ./archive_github_user.sh [-h] USER
    }

    if [ "$1" == "-h" ]; then
    usage
    usage
    fi
    USER=$1
    USER_DIR="$DIR/repos/$USER"

    mkdir -p "$USER_DIR"
    [ -f "$USER_DIR/$USER.txt" ] && printf "##### $USER_DIR/$USER.txt file detected.\nDelete it if you want to update the repository list.\n"
    if [ ! -f "$USER_DIR/$USER.txt" ]; then
    printf "##### Extracting repos for $USER.\n"
    curl -s https://api.github.com/users/"$USER"/repos | jq -r '.[]|.html_url' > "$USER_DIR/$USER".txt
    printf "##### Extracting repos for $USER.\n"
    PAGE_NUMBER=`curl -sI "https://api.github.com/users/"$USER"/repos" | awk "/^Link/" | cut -d? -f3`
    for PAGE in `seq 1 ${PAGE_NUMBER//[!0-9]/}`; do
    printf "##### Extracting starred repos from page $PAGE\n"
    URL="https://api.github.com/users/$USER/repos?page=$PAGE"
    curl -s "$URL" | jq -r '.[]|.html_url' >> "$USER_DIR/$USER.txt"
    done
    fi

    for URL in `cat "$USER_DIR/$USER".txt`; do
    REPO=`basename -s ".git" "$URL"`
    FOLDER="$USER_DIR/$REPO"
    if [ ! -d "$FOLDER" ] ; then
    printf "##### Cloning $URL in $FOLDER.\n"
    mkdir -p "$FOLDER"
    git clone $URL "$FOLDER"
    else
    printf "##### Updating $URL in $FOLDER.\n"
    cd "$FOLDER"
    git pull $URL
    cd "$DIR"
    fi
    REPO=`basename -s ".git" "$URL"`
    FOLDER="$USER_DIR/$REPO"
    if [ ! -d "$FOLDER" ] ; then
    printf "##### Cloning $URL in $FOLDER.\n"
    mkdir -p "$FOLDER"
    git clone $URL "$FOLDER"
    else
    printf "##### Updating $URL in $FOLDER.\n"
    cd "$FOLDER"
    git pull $URL
    cd "$DIR"
    fi
    done
  3. dbeley revised this gist Jan 20, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion archive_github_user_repos.sh
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ USER_DIR="$DIR/repos/$USER"

    mkdir -p "$USER_DIR"
    [ -f "$USER_DIR/$USER.txt" ] && printf "##### $USER_DIR/$USER.txt file detected.\nDelete it if you want to update the repository list.\n"
    if [! -f "$USER_DIR/$USER.txt" ]; then
    if [ ! -f "$USER_DIR/$USER.txt" ]; then
    printf "##### Extracting repos for $USER.\n"
    curl -s https://api.github.com/users/"$USER"/repos | jq -r '.[]|.html_url' > "$USER_DIR/$USER".txt
    fi
  4. dbeley revised this gist Jan 18, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion archive_github_user_repos.sh
    Original file line number Diff line number Diff line change
    @@ -33,4 +33,4 @@ for URL in `cat "$USER_DIR/$USER".txt`; do
    git pull $URL
    cd "$DIR"
    fi
    done
    done
  5. dbeley revised this gist Jan 18, 2021. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions archive_github_user_repos.sh
    Original file line number Diff line number Diff line change
    @@ -8,29 +8,29 @@ Usage: ./archive_github_user.sh [-h] USER
    }

    if [ "$1" == "-h" ]; then
    usage
    usage
    fi
    USER=$1
    USER_DIR="$DIR/repos/$USER"

    mkdir -p "$USER_DIR"
    [ -f "$USER_DIR/$USER.txt" ] && printf "##### $USER_DIR/$USER.txt file detected.\nDelete it if you want to update the repository list.\n"
    if [! -f "$USER_DIR/$USER.txt" ]; then
    printf "##### Extracting repos for $USER.\n"
    curl -s https://api.github.com/users/"$USER"/repos | jq -r '.[]|.html_url' > "$USER_DIR/$USER".txt
    printf "##### Extracting repos for $USER.\n"
    curl -s https://api.github.com/users/"$USER"/repos | jq -r '.[]|.html_url' > "$USER_DIR/$USER".txt
    fi

    for URL in `cat "$USER_DIR/$USER".txt`; do
    REPO=`basename -s ".git" "$URL"`
    FOLDER="$USER_DIR/$REPO"
    if [ ! -d "$FOLDER" ] ; then
    printf "##### Cloning $URL in $FOLDER.\n"
    mkdir -p "$FOLDER"
    git clone $URL "$FOLDER"
    else
    printf "##### Updating $URL in $FOLDER.\n"
    cd "$FOLDER"
    git pull $URL
    cd "$DIR"
    fi
    REPO=`basename -s ".git" "$URL"`
    FOLDER="$USER_DIR/$REPO"
    if [ ! -d "$FOLDER" ] ; then
    printf "##### Cloning $URL in $FOLDER.\n"
    mkdir -p "$FOLDER"
    git clone $URL "$FOLDER"
    else
    printf "##### Updating $URL in $FOLDER.\n"
    cd "$FOLDER"
    git pull $URL
    cd "$DIR"
    fi
    done
  6. dbeley renamed this gist Jan 18, 2021. 1 changed file with 0 additions and 0 deletions.
  7. dbeley created this gist Jan 18, 2021.
    36 changes: 36 additions & 0 deletions archive_github_repos_user.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/usr/bin/env bash
    set -eEu -o pipefail
    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P)"

    usage() { printf "%s" "\
    Usage: ./archive_github_user.sh [-h] USER
    "; exit 0;
    }

    if [ "$1" == "-h" ]; then
    usage
    fi
    USER=$1
    USER_DIR="$DIR/repos/$USER"

    mkdir -p "$USER_DIR"
    [ -f "$USER_DIR/$USER.txt" ] && printf "##### $USER_DIR/$USER.txt file detected.\nDelete it if you want to update the repository list.\n"
    if [! -f "$USER_DIR/$USER.txt" ]; then
    printf "##### Extracting repos for $USER.\n"
    curl -s https://api.github.com/users/"$USER"/repos | jq -r '.[]|.html_url' > "$USER_DIR/$USER".txt
    fi

    for URL in `cat "$USER_DIR/$USER".txt`; do
    REPO=`basename -s ".git" "$URL"`
    FOLDER="$USER_DIR/$REPO"
    if [ ! -d "$FOLDER" ] ; then
    printf "##### Cloning $URL in $FOLDER.\n"
    mkdir -p "$FOLDER"
    git clone $URL "$FOLDER"
    else
    printf "##### Updating $URL in $FOLDER.\n"
    cd "$FOLDER"
    git pull $URL
    cd "$DIR"
    fi
    done