-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinstall
118 lines (103 loc) · 2.67 KB
/
install
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
---
---
{% if jekyll.environment == "production" %}
# GitHub production URL
BASE_URL="{{ site.github.url }}"
{% elsif jekyll.environment == "development" %}
# Default development URL
BASE_URL="http://abba-builder:4000"
{% else %}
# Custom development URL
BASE_URL="{{ jekyll.environment }}"
{% endif %}
{% assign css_pages = site.pages | where: "dir", "/abba/css/" %}
{% assign css_themes = "" | split: "," %}
{% for page in css_pages %}
{% assign theme = page.name | remove: ".scss" %}
{% assign css_themes = css_themes | push: theme %}
{% endfor %}
# Available themes
THEMES="{{ css_themes | join: ":" }}"
# Print all available themes
print_themes()
{
echo ${THEMES} | awk -F: '{
for (i = 1; i <= NF; i++) {
printf("%2s) %s\n", i, $i);
}
}'
}
# Check if a theme name is valid
# $1: A theme name
# return: A valid theme name or the empty string
check_theme()
{
echo ${THEMES} | awk -F: -v theme=${1:-default} '{
ltheme = tolower(theme);
for (i = 1; i <= NF; i++) {
if (ltheme == i || ltheme == $i) {
printf("%s", $i);
exit;
}
}
}'
}
# On exit handler
on_exit()
{
local status=$?
# Print a status line
if [ ${status} -eq 0 ]
then
echo "ABBA has been successfully installed"
else
echo >&2 "Failed to install ABBA"
fi
# Self remove
rm ${0}
exit ${status}
}
trap "on_exit" EXIT
# Exit on error
set -e
# Create the .abba directory tree first to handle permission denied errors asap
mkdir -p .abba
mkdir -p .abba/css
mkdir -p .abba/html
mkdir -p .abba/images
mkdir -p .abba/js
mkdir -p .abba/webfonts
# Ask the user to choose a theme if not given in argument
[ -n "${1}" ] && THEME=$(check_theme ${1})
while [ -z "${THEME}" ]
do
print_themes
read -p "What theme do you want to use? [default] " THEME
THEME=$(check_theme ${THEME})
done
# Download the needed files
curl -sL ${BASE_URL}/abba/htaccess -o .htaccess
curl -sL ${BASE_URL}/abba/css/${THEME}.css -o .abba/css/style.css
curl -sL ${BASE_URL}/abba/html/header.shtml -o .abba/html/header.shtml
curl -sL ${BASE_URL}/abba/html/footer.shtml -o .abba/html/footer.shtml
for ERROR in 401 403 404 500
do
curl -sL ${BASE_URL}/abba/html/error_${ERROR}.shtml -o .abba/html/error_${ERROR}.shtml
done
curl -sL ${BASE_URL}/abba/images/favicon.ico -o .abba/images/favicon.ico
curl -sL ${BASE_URL}/abba/images/favicon.svg -o .abba/images/favicon.svg
curl -sL ${BASE_URL}/abba/js/script.js -o .abba/js/script.js
for FONT in fa-regular-400 fa-solid-900
do
for EXT in eot svg ttf woff woff2
do
curl -sL ${BASE_URL}/abba/webfonts/${FONT}.${EXT} -o .abba/webfonts/${FONT}.${EXT}
done
done
# Generate the uninstall script
cat << EOF > .abba/uninstall
#!/bin/sh
rm -f ${PWD}/.htaccess
rm -rf ${PWD}/.abba
EOF
chmod +x .abba/uninstall