Advertisement
renix1

script github

May 31st, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.83 KB | None | 0 0
  1. function git_install() {
  2.     : INSTALL GIT :
  3.     installed=$(which git)
  4.     if [ $installed = "/usr/bin/git" ];then
  5.         echo 'Installed'
  6.     else
  7.         sudo apt install -y git
  8.         echo 'Installed'
  9.     fi
  10. }
  11.  
  12. function jq_install() {
  13.     : INSTALL JQ :
  14.     installed=$(which jq)
  15.     if [ $installed = "/usr/bin/jq" ];then
  16.         echo "Installed"
  17.     else
  18.         sudo apt install -y jq
  19.         echo "Installed"
  20.     fi
  21. }
  22.  
  23. function check_username() {
  24.     : DISPLAY USERNAME :
  25.     user=$(echo $USERNAME)
  26.     if [ -e "/home/$user/gitsync" ];then
  27.         username=$(cat /home/$user/gitsync/user_data)
  28.         echo $username
  29.     else
  30.         echo "None"
  31.     fi
  32. }
  33.  
  34. function git_configure() {
  35.     : DEFINE NAME AND EMAIL IN GITHUB OR ONLY SHOW :
  36.     name=$(git config --global user.name)
  37.     email=$(git config --global user.email)
  38.     name_s=$(echo $name | wc -c)
  39.     if [ $name_s -lt 1 ];then
  40.         echo "Type your name: "
  41.         read name
  42.         git config --global user.name "$name"
  43.         echo "Type your email: "
  44.         read email
  45.         git config --global user.email $email
  46.         git_configure
  47.     else
  48.         echo "$name, $email"
  49.     fi
  50. }
  51.  
  52. function define_username() {
  53.     : GET CURRENT USER AND DEFINE USERNAME OF GITHUB :
  54.     user=$(echo $USERNAME) # get current user
  55.     echo "Type your username of github: "
  56.     read username
  57.     username_s=$(echo $username | wc -c)
  58.     if [ $username_s -gt 1 ];then
  59.         mkdir /home/$user/gitsync
  60.         echo "$username" > /home/$user/gitsync/user_data # stores username on this file
  61.         echo "Username defined"
  62.     fi
  63. }
  64.  
  65. function cloning() {
  66.     : CLONING ALL REPOS :
  67.     user=$(echo $USERNAME)
  68.     echo "Clone all repos? (S/n): "
  69.     read response
  70.     response="${response^^}"
  71.     if [ $response = 'S' ];then
  72.         if [ ! -e 'repos/' ];then
  73.             mkdir repos/
  74.         fi
  75.         cd repos/
  76.         if [ ! -e "/home/$user/gitsync" ];then
  77.             define_username
  78.         fi
  79.         username=$(cat /home/$user/gitsync/user_data)
  80.         if [ ! -e "repos" ];then
  81.             resp=$(wget https://api.github.com/users/$username/repos)
  82.         fi
  83.         n_repos=$(cat repos | jq '. | length')
  84.         ((n_repos = n_repos - 1))
  85.         for i in  `seq 0 1 $n_repos`; do
  86.             name=$(cat repos | jq ".[$i].name")
  87.             repo=$(cat repos | jq ".[$i].clone_url")
  88.             repo=$(echo $repo | xargs)
  89.             echo $name
  90.             echo "[NOW] Cloning $name..."
  91.             git clone $repo
  92.         done
  93.     else
  94.         echo "Okay..."
  95.     fi
  96. }
  97.  
  98. function main() {
  99.     : CALL ALL THE FUNCTIONS :
  100.     echo
  101.     echo "Git stats ---~> $(git_install)"
  102.     echo "Jq stats  ---~> $(jq_install)"
  103.     echo "Username  ---~> $(check_username)"
  104.     echo "Git infos ---~> $(git_configure)"
  105.     echo ""
  106.     cloning
  107. }
  108.  
  109. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement