-
Notifications
You must be signed in to change notification settings - Fork 14
/
add_file.sh
68 lines (54 loc) · 1.58 KB
/
add_file.sh
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
#!/bin/bash
# Adds a new file to repo
# Params
USERNAME="$1"
BLOCKNAME="$2"
FILEPATH="$3"
# Consts
BLOCKS_FOLDER_PATH="blocks/"
CURRENTDIR=$(pwd)
if [ -z ${GITHUB_ORGANIZATION+x} ]; then
GITHUB_ACCOUNT=$USERNAME;
echo "WORKING WITH USER ACC";
echo "$USERNAME"
else
GITHUB_ACCOUNT=$GITHUB_ORGANIZATION;
echo "WORKING WITH ORGANIZATION ACC";
fi
####### PREPARATIONS #######
if [ ! -f $FILEPATH ]; then
# TODO: if FILEPATH - is not absolute, condition will pass
echo "ERROR: File $FILEPATH not found!" && exit 1
fi
# solving problem with different func names (md5 / md5sum)
if [[ "$OSTYPE" == "darwin"* ]]; then
BRANCHNAME=$((cat "$FILEPATH"; date +%s) | md5 | awk '{print $1}')
else
BRANCHNAME=$((cat "$FILEPATH"; date +%s) | md5sum | awk '{print $1}')
fi
mkdir -p $BLOCKS_FOLDER_PATH
cd $BLOCKS_FOLDER_PATH
git clone -b master --depth 1 https://$USERNAME:$GITHUB_TOKEN@github.com/$GITHUB_ACCOUNT/$BLOCKNAME.git
cd $BLOCKNAME
####### GIT STUFF #######
git config --local user.name "morejust.store"
git config --local user.email "store@morejust.store"
git checkout -b $BRANCHNAME
FILENAME=$(basename "$FILEPATH")
mv "$FILEPATH" "./$FILENAME"
git add "$FILENAME"
git commit -m "add $FILENAME to $BRANCHNAME branch"
if git push --set-upstream origin $BRANCHNAME
then
# log file link
FILELINK="https://raw.githubusercontent.com/$GITHUB_ACCOUNT/$BLOCKNAME/$BRANCHNAME/$FILENAME"
printf "\n" #Need to avoid garbage before link
echo "$FILELINK"
else
mv "./$FILENAME" "$FILEPATH"
echo "ERROR: Upload failed."
fi
# Finishing
git checkout master
git branch -D $BRANCHNAME
cd $CURRENTDIR