-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·134 lines (102 loc) · 3.37 KB
/
run.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# create document to source/ from template
# insert date
# clearsign with gpg
# output to records/
# git push
# h/t https://stackoverflow.com/a/5947802/6299634
source source/progress.sh
# ANSI escape colour codes
CYAN='\033[0;36m'
NC='\033[0m' # No Color
LIGHTRED='\033[1;31m'
LIGHTGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LIGHTPURPLE='\033[1;35m'
WHITE='\033[1;37m'
printf "
${WHITE}WELCOME TO${NC}
${CYAN}
"
cat source/logo.txt
printf "
${NC}
${YELLOW}
copyright (c) aidswidjaja 2022 // github.com/aidswidjaja
${NC}
"
printf "${LIGHTPURPLE}HEADS UP: Run this script in life-canary/ on macOS/Linux with GNU coreutils${NC}\n"
# h/t https://stackoverflow.com/a/8597411/6299634
if [[ "$OSTYPE" == "linux"* ]]; then
DATE="date"
SED="sed"
elif [[ "$OSTYPE" == "darwin"* ]]; then
printf "${LIGHTPURPLE}HEADS UP: ensure you have gdate and gsed from GNU coreutils, and git for this script to work. Install with brew install coreutils gnu-sed.${NC}\n"
DATE="gdate"
SED="gsed"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
printf "${LIGHTPURPLE}HEADS UP: ensure you have gdate and gsed from GNU coreutils, and git for this script to work.${NC}\n"
DATE="gdate"
SED="gsed"
elif [[ "$OSTYPE" == "msys" ]]; then
printf "${LIGHTRED}WARNING: You're using the MinGW GNU coreutils for Windows. No guarantees this will work: use Windows Subsystem for Linux.${NC}\n"
elif [[ "$OSTYPE" == "win32" ]]; then
printf "${LIGHTRED}WARNING: You're running this bash script on Windows. This probably won't work: use Windows Subsystem for Linux.${NC}\n"
else
printf "${LIGHTRED}WARNING: Unrecognised operating system. Nani?${NC}\n"
DATE="gdate"
SED="gsed"
fi
if ${DATE} --version >/dev/null 2>&1 ; then
printf "${CYAN}INFO: Using GNU date, naisu!${NC}\n"
else
printf "${LIGHTPURPLE}WARNING: Not using GNU date. This may fail.${NC}\n"
fi
if ${SED} --version >/dev/null 2>&1 ; then
printf "${CYAN}INFO: Using GNU sed, naisu!${NC}\n"
else
printf "${LIGHTPURPLE}WARNING: Not using GNU sed. This may fail.${NC}\n"
fi
printf "
${LIGHTGREEN}===== DEPENDENCIES =====${WHITE}
- git°
- gpg^
- gsed*
- gtime*
°git (including signed commits) should be configured beforehand
^gpg should be configured. By default, Life Canary assumes the email [email protected] but you can change this by running the script with an email arg (e.g ./run.sh [email protected]).
*sed and time should be from GNU coreutils, not BSD.
\n
"
# h/t https://stackoverflow.com/a/238094/6299634
printf "${LIGHTGREEN}===== BEGINNING EXECUTION ======${WHITE}\n\n"
setup_scroll_area
if [[ ${DATE} == "date" ]]; then
DATE_NAME=$(date '+%B_%d_%Y')
DATE_REPLACE=$(date '+%B %d %Y')
else
DATE_NAME=$(gdate '+%B_%d_%Y')
DATE_REPLACE=$(gdate '+%B %d %Y')
fi
if [ "$1" == "" ] || [ $# -gt 1 ]; then
EMAIL="[email protected]"
else
EMAIL="$1"
fi
draw_progress_bar 12
cp source/template.txt unsigned/${DATE_NAME}.txt
draw_progress_bar 24
${SED} -i "s/REPLACE_ME/${DATE_REPLACE}/g" unsigned/${DATE_NAME}.txt
draw_progress_bar 36
gpg -u ${EMAIL} --output records/${DATE_NAME}.txt --clearsign unsigned/${DATE_NAME}.txt
draw_progress_bar 48
cp -f records/${DATE_NAME}.txt latest_signed.txt
draw_progress_bar 60
git add -A
draw_progress_bar 72
git commit -m "New automated entry: ${DATE_REPLACE}"
draw_progress_bar 84
git push origin main
draw_progress_bar 100
destroy_scroll_area
printf "${LIGHTGREEN}===== FINISHED ======${NC}\n"