-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitExportRepoTag.sh
More file actions
executable file
·104 lines (93 loc) · 2.8 KB
/
gitExportRepoTag.sh
File metadata and controls
executable file
·104 lines (93 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
#This script exports tags from both public and private repositories
#
# Assumption:
# 1) User has credentials to connect to the private repo
# 2) User has generated personal token key (GTOKEN) for their github account
# 3) User has added GTOKEN environment variable to their .cshrc or .bashrc file
#
# Input:
# 1) Owner/Organization name
# 2) Repository name
# 3) Tag
#
# What it does:
# 1) Set path to git tag
# 2) wget private tag using GTOKEN authentication
# 3) Create local directory for the new tag
# 4) Untar new tag tar
# 5) Remove the downloaded tar file
#
# Author: lnh
# Date : 7/22/2016
#
#setup the log file
SCRIPT_NAME=`basename $0`
LOG=$SCRIPT_NAME.log
rm -f $LOG
touch $LOG
#Check the number of
if [ $# -lt 3 ]
then
echo ""
echo "***********************************************"
echo ""
echo "Usage: ./$SCRIPT_NAME ORGANIZATION/OWNER REPO_NAME GIT_TAG"
echo "Example1: ./$SCRIPT_NAME mgijax pgdbutilities 6-0-4-3"
echo "Example1: ./$SCRIPT_NAME mgijax ei master"
echo ""
echo "Assumption:
1) User has credentials to connect to the private repo
2) User has generated personal token key (GTOKEN) for their github account
3) User has added GTOKEN environment variable to their .cshrc or .bashrc file
"
echo "***********************************************"
echo ""
exit 1
fi
##
ORG=$1
WGET=`which wget`
TAR=`which tar`
REPO=$2
TAG=$3
#Url to private repository
GIT_URL=https://api.github.com/repos/$ORG/$REPO/tarball/$TAG
#Local tag directory
TAG_DIR=$REPO-$TAG
#Results tar file
TAG_TAR_FILE=$TAG_DIR.tar.gz
date | tee -a $LOG
echo "wget path: $WGET" | tee -a $LOG
echo "tar path: $TAR"| tee -a $LOG
echo "Tag: $TAG"| tee -a $LOG
echo "Repository: $REPO"| tee -a $LOG
echo "Organization: $ORG"| tee -a $LOG
echo "Git url: $GIT_URL"| tee -a $LOG
echo "My Github personal token: $GTOKEN" | tee -a $LOG
date | tee -a $LOG
if [ "$GTOKEN" == "" ]
then
echo "Your personal token used to authenticate to github is not set" | tee -a $LOG
echo "You must first generate a valid personal token for your github account"| tee -a $LOG
echo " and add it to your environment variables (in your .cshrc or .bashrc )"| tee -a $LOG
exit 1
fi
#execute the commande
echo Cammand: $WGET -O $TAG_TAR_FILE --header="Authorization: token $GTOKEN" "$GIT_URL" | tee -a $LOG
$WGET -O $TAG_TAR_FILE --header="Authorization: token $GTOKEN" "$GIT_URL" | tee -a $LOG
#clean previous download of this tag
if [ -d $TAG_DIR ]
then
rm -rf $TAG_DIR
fi
#Create local directory for this tag
mkdir $TAG_DIR
#Untar the new archive
echo "Untar $TAG_TAR_FILE" | tee -a $LOG
echo "Command: $TAR -xzvf $TAG_TAR_FILE -C $TAG_DIR --strip-components 1"
$TAR -xzvf $TAG_TAR_FILE -C $TAG_DIR --strip-components 1
#Remove the tar file
rm -f $TAG_TAR_FILE
date
echo "Program complete"