#!/bin/sh # # This script lets you setup a local woofce repo just to get started. # You have to learn to manage, synchronize and troubleshoot git/github repos. # # It can also be used for other repos, by adding a repo URL as an argument # or by exporting REPO_URL=. # # If you don't plan to contribute to woofce or use your fork (github) # for your own purposes then it's not advised that you use this script. # # If you feel git is too complicated to master and it's a waste of time # trying to learn the ins and outs.. it's not advised that you use this script. # # links: # https://git-scm.com/docs/user-manual.html # https://help.github.com/articles/fork-a-repo/ # https://help.github.com/articles/about-pull-requests/ # https://help.github.com/articles/creating-a-pull-request/ # http://stackoverflow.com/questions/5480069/autosetuprebase-vs-autosetupmerge ## Export these variables and run the script ## to create the repo dir automatically. Ex: #export GITHUB_USER=wdlkmpx #export USER_NAME=wdlkmpx #export USER_EMAIL=zzzzzz@yourmail.com #export REPO_TYPE=fork #main = you have write access to upstream #export REPO_URL=https://github.com/puppylinux-woof-CE/woof-CE #export DEFAULT_BRANCH=testing if ! which git &>/dev/null ; then echo "ERROR: Install Git" exit 1 fi #----------------------------------------------------------- # send patches to mailing lists # this requires a special setup.. and has several dependencies # only gmail is supported function set_email() { if [ ! -d .git ] ; then echo "No .git directory found" exit 1 fi echo -n "Enter gmail user: "; read guser [ ! "$guser" ] && exit 1 git config --global sendemail.smtpuser ${guser}@gmail.com git config --global sendemail.smtpserver smtp.gmail.com git config --global sendemail.smtpencryption tls git config --global sendemail.smtpserverport 587 git config --global sendemail.confirm #git config --global sendemail.smtppass git config --global sendemail.smtpsslcertpath /etc/ssl/certs/ca-bundle.crt echo "Ok, git is ready to send emails through ${guser}@gmail.com" } #----------------------------------------------------------- function get_repo() { if [ ! "$REPO_URL" ] ; then REPO_URL="https://github.com/puppylinux-woof-CE/woof-CE" #echo -e "\nEnter the full git repo http REPO_URLess:" #read REPO_URL ; echo #[ ! "$REPO_URL" ] && echo 'No URL, exiting...' && exit 1 fi REPO_NAME=${REPO_URL##*/} REPO_NAME=${REPO_NAME%.git} } function get_variables() { get_repo if [ ! "$REPO_TYPE" ] ; then echo echo "Is this a fork or the main repo?" echo "1. Fork [default] (origin=fork upstream=main) " echo "2. Main Repo (origin=upstream)" echo -n "Enter option: " read REPO_TYPE case $REPO_TYPE in 2) REPO_TYPE=main ;; *) REPO_TYPE=fork ;; esac echo "Repo Type = $REPO_TYPE"; echo fi if [ ! "$GITHUB_USER" ] ; then echo -n 'Enter github user: ' ; read GITHUB_USER [ ! "$GITHUB_USER" ] && echo 'No user, exiting...' && exit 1 fi if [ ! "$USER_NAME" ] ; then echo -n 'Enter name [optional]: ' ; read USER_NAME [ ! "$USER_NAME" ] && USER_NAME="${GITHUB_USER}" fi if [ ! "$USER_EMAIL" ] ; then echo -n 'Enter github email: ' ; read USER_EMAIL [ ! "$USER_EMAIL" ] && echo 'No email, exiting...' && exit 1 [ "$USER_EMAIL" = "user" ] && USER_EMAIL="${GITHUB_USER}@gmail.com" #for me fi if [ ! "$CORE_EDITOR" ] ; then which mp &>/dev/null && CORE_EDITOR=mp which nano &>/dev/null && CORE_EDITOR=nano fi if [ ! "$DEFAULT_BRANCH" ] ; then DEFAULT_BRANCH=master [ "$REPO_NAME" = "woof-CE" ] && DEFAULT_BRANCH=testing echo -n "Enter default branch [leave empty for ${DEFAULT_BRANCH}]: " read branch [ "$branch" = "" ] && branch=${DEFAULT_BRANCH} echo "Branch = $branch" echo fi } function basic_settings() { if [ ! -d .git ] ; then echo "No .git directory found" exit 1 fi get_variables git config --global branch.autosetupmerge always git config --global color.diff auto git config --global color.grep auto git config --global color.interactive auto git config --global color.ui true git config --global http.sslverify false git config --global core.pager less git config --global core.editor "${CORE_EDITOR}" git config --global user.name "${USER_NAME}" git config --global user.email "${USER_EMAIL}" git config --global push.default simple #------- git remote remove upstream 2>/dev/null git remote remove origin 2>/dev/null if [ "$REPO_TYPE" = "main" ] ; then # if Repo Type "main": origin (fork) = upstream (main) git remote add origin ${REPO_URL} git remote add upstream ${REPO_URL} else echo "-----------------------------------------" echo "Your fork must be accesible through" echo " https://github.com/${GITHUB_USER}/${REPO_NAME}" echo "Otherwise you should albort now" echo "-----------------------------------------" git remote add origin https://github.com/${GITHUB_USER}/${REPO_NAME} git remote add upstream ${REPO_URL} fi #------- git pull for i in $(git branch -a | grep remote | sed 's|.*/||' | sort -u) do echo "Branch '$i'" git checkout ${i} git pull upstream ${i} git branch --set-upstream-to=upstream/${i} ${i} [ "$REPO_TYPE" != "main" ] && git pull origin ${i} done git checkout ${branch} git status } function report() { echo echo "GITHUB_USER : $GITHUB_USER" echo "USER_NAME : $USER_NAME" echo "USER_EMAIL : $USER_EMAIL" echo "REPO_TYPE : $REPO_TYPE" echo "REPO_URL : $REPO_URL" echo "DEFAULT_BRANCH: $DEFAULT_BRANCH" echo } #----------------------------------------------------------- script=${0##*/} case $1 in email) set_email; exit ;; #inside git dir basic) basic_settings; report ; exit;; #inside git dir https*) REPO_URL="$1" ;; esac #----------------------------------------------------------- get_repo if [ -d ${REPO_NAME}-git ] ; then echo echo "*** '${REPO_NAME}-git' already exists" echo "If you want to setup that existing dir:" echo " - cd ${REPO_NAME}-git" echo " - $script basic" echo "Press CTRL-C to cancel or Enter to continue" read zzz fi case "$PWD" in *"/${REPO_NAME}-git") if [ -d .git ] ; then echo echo "*** It looks like we're inside ${REPO_NAME}" echo "If you want to setup this dir, REPO_TYPE:" echo " - $script basic" exit fi ;; esac if [ -d .git ] ; then echo "There is a .git directory in this location" echo "Press CTRL-C to cancel or Enter to continue.." fi if [ ! "$REPO_TYPE" ] ; then echo echo "We're going to create a local ${REPO_NAME^^} repo" echo echo "Is this a fork or the main repo?" echo echo "Fork: you already forked the repo through the github web interface" echo " you push to your fork and open a pull request afterwards.." echo "Main: you own/have write access to the main repo" echo " you intend to push commits directly to the main repo" echo "" echo " ***** Read github/git tutorials *****" echo echo "1. Fork [default] (origin=fork upstream=main) " echo "2. Main Repo (origin=upstream)" echo echo -n "Enter option: " read REPO_TYPE case $REPO_TYPE in 2) REPO_TYPE=main ;; *) REPO_TYPE=fork ;; esac fi echo "Repo Type = $REPO_TYPE" echo #----------------------------------------------------------- gitdir=${REPO_NAME}-git mkdir -p ${gitdir} cd ${gitdir} git init get_variables basic_settings report echo echo " ***** Read github/git tutorials *****" echo echo "Ok, you can now start/continue your work" echo "- cd $gitdir" ################################################################ exit ################################################################ #*** this is junk / some random commands i pasted here. ### if Repo Type is "main": origin (fork) = upstream (main) ### change to a specific branch git checkout ### in case of conflicts revert to some previous commit and pull again git reset --hard git pull ### verify real status - in master branch git checkout master git pull upstream master git pull origin master git status ### verify and commit git status git commit -a ### push to fork - testing branch git push origin testing ### revert pushed commits to fork git reset --hard git status git push -f origin master # more branches branch=testz9 git checkout -b ${branch} #git push origin ${branch} git branch --set-upstream-to upstream/master git pull git push origin ${branch} # delete branch branch=testz9 git branch -d ${branch} #local git push origin :${branch} #remote