-
Notifications
You must be signed in to change notification settings - Fork 1
/
kommit.sh
executable file
·66 lines (55 loc) · 1.62 KB
/
kommit.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
#!/bin/bash
# # Grab input variables
while getopts u:e:t: flag
do
case "${flag}" in
u) GITHUB_USERNAME=${OPTARG};;
e) GITHUB_EMAIL=${OPTARG};;
t) GITHUB_TOKEN=${OPTARG};;
esac
done
echo "Github Username: $GITHUB_USERNAME"
echo "Github Email: $GITHUB_EMAIL"
echo "Github Token: $GITHUB_TOKEN"
git config --global user.email ${GITHUB_EMAIL}
git config --global user.name ${GITHUB_USERNAME}
# # Set variables for the script
GITHUB_ORIGIN="https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${GITHUB_USERNAME}/kommit-king.git"
SCRIPT_DIR=$( dirname -- "$( readlink -f -- "$0"; )"; )
FILE_PATH="$SCRIPT_DIR/kommit.sh"
RUN_EVERY='*/10 * * * *'
CRONJOB="$RUN_EVERY $FILE_PATH -u ${GITHUB_USERNAME} -t ${GITHUB_TOKEN}"
NOW=$(date +"%Y%m%d%H%M%S")
CRONTAB=$(crontab -l)
cd $SCRIPT_DIR
if [[ "$CRONTAB" == *"$CRONJOB"* ]];
then
echo "Doing nothing (:"
else
# # Cron has not been set. First run
##### ##### ##### ##### ##### #####
# # Grant permissions to the script
sudo chmod +x $FILE_PATH
# Create the privatre repo
gh repo create kommit-king --private
git init
# # Add cronjob to crontab
crontab -l > mycron
echo "$CRONJOB">> mycron
crontab mycron
rm mycron
fi
# # Delete the line with the time
sed -i '' -e '$ d' kommit.sh
# # Add the current time to the bottom
sh -c "echo '# $NOW' >> kommit.sh"
# # Just incase a seperate origin was set
git remote remove origin
git remote add origin "${GITHUB_ORIGIN}"
# # Add new changes & commit them & push them
git add .
git commit -m $NOW
git branch -M main
git push -u origin main --force
# 20220927203000
# 20240609031001