-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·165 lines (163 loc) · 7.99 KB
/
install.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env sh
# shellcheck shell=sh
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202308271918-git
# @@Author : Jason Hempstead
# @@Contact : [email protected]
# @@License : LICENSE.md
# @@ReadME : install.sh --help
# @@Copyright : Copyright: (c) 2023 Jason Hempstead, Casjays Developments
# @@Created : Sunday, Aug 27, 2023 19:18 EDT
# @@File : install.sh
# @@Description :
# @@Changelog : New script
# @@TODO : Better documentation
# @@Other :
# @@Resource :
# @@Terminal App : no
# @@sudo/root : no
# @@Template : shell/bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck disable=SC2016
# shellcheck disable=SC2031
# shellcheck disable=SC2120
# shellcheck disable=SC2155
# shellcheck disable=SC2199
# shellcheck disable=SC2317
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# BASH_SET_SAVED_OPTIONS=$(set +o)
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set default exit code
INSTALL_SH_EXIT_STATUS=0
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check for command
__cmd_exists() { command "$1" >/dev/null 2>&1 || return 1; }
__function_exists() { command -v "$1" 2>&1 | grep -q "is a function" || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Relative find functions
__find_file_relative() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type f 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '^' || false; }
__find_directory_relative() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '^' || false; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# get and compare versions
__get_version() { printf '%s\n' "${1:-$(cat "/dev/stdin")}" | awk -F. '{ printf("%d%03d\n", $1,$2); }'; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# custom functions
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define Variables
EXPECTED_OS="alpine"
TEMPLATE_NAME="jekyll"
CONFIG_CHECK_FILE="nginx/nginx.conf"
OVER_WRITE_INIT="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TMP_DIR="/tmp/config-$TEMPLATE_NAME"
CONFIG_DIR="/usr/local/share/template-files/config"
INIT_DIR="/usr/local/etc/docker/init.d"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GIT_REPO="https://github.com/templatemgr/$TEMPLATE_NAME"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OS_RELEASE="$(grep -si "$EXPECTED_OS" /etc/*-release* | sed 's|.*=||g;s|"||g' | head -n1)"
[ -n "$OS_RELEASE" ] || { echo "Unexpected OS: ${OS_RELEASE:-N/A}" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ "$TEMPLATE_NAME" != "sample-template" ] || { echo "Please set TEMPLATE_NAME" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -d "$TMP_DIR" ] && rm -Rf "$TMP_DIR"
git clone -q "$GIT_REPO" "$TMP_DIR" || { echo "Failed to clone the repo" exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main application
mkdir -p "$CONFIG_DIR" "$INIT_DIR"
find "$TMP_DIR/" -iname '.gitkeep' -exec rm -f {} \;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# custom pre execution commands
[ -n "$WWW_ROOT_DIR" ] || WWW_ROOT_DIR="/usr/share/webapps/jekyll"
ruby_version="$(command ruby --version 2>/dev/null | sed 's|[(].*||g;s|[a-zAZ]||g;s|^ ||g' | __get_version | grep '^' || true)"
[ -n "$ruby_version" ] && [ "$ruby_version" = "2007" ] || { echo "This requires ruby version 2.7" && exit 1; }
[ "$(command -v gem 2>/dev/null)" ] || { echo "Missing ruby-dev package" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
get_dir_list="$(__find_directory_relative "$TMP_DIR/config" || false)"
if [ -n "$get_dir_list" ]; then
for dir in $get_dir_list; do
mkdir -p "$CONFIG_DIR/$dir" /etc/$dir
done
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
get_file_list="$(__find_file_relative "$TMP_DIR/config" || false)"
if [ -n "$get_file_list" ]; then
for conf in $get_file_list; do
if [ -f "/etc/$conf" ]; then
rm -Rf /etc/${conf:?}
fi
if [ -d "$TMP_DIR/config/$conf" ]; then
cp -Rf "$TMP_DIR/config/$conf/." "/etc/$conf/"
cp -Rf "$TMP_DIR/config/$conf/." "$CONFIG_DIR/$conf/"
elif [ -e "$TMP_DIR/config/$config" ]; then
cp -Rf "$TMP_DIR/config/$conf" "/etc/$conf"
cp -Rf "$TMP_DIR/config/$conf" "$CONFIG_DIR/$conf"
fi
done
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "$TMP_DIR/init-scripts" ]; then
init_scripts="$(ls -A "$TMP_DIR/init-scripts/" | grep '^' || false)"
if [ -n "$init_scripts" ]; then
mkdir -p "$INIT_DIR"
for init_script in $init_scripts; do
if [ "$OVER_WRITE_INIT" = "yes" ] || [ ! -f "$INIT_DIR/$init_script" ]; then
echo "Installing $INIT_DIR/$init_script"
cp -Rf "$TMP_DIR/init-scripts/$init_script" "$INIT_DIR/$init_script" &&
chmod -Rf 755 "$INIT_DIR/$init_script" || true
fi
done
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -d "$TMP_DIR/bin" ] && chmod -Rf 755 "$TMP_DIR/bin/" && cp -Rf "$TMP_DIR/bin/." "/usr/local/bin/"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -d "$INIT_DIR" ] && chmod -Rf 755 "$INIT_DIR"/*.sh || true
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Other files to copy to system
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -d "$TMP_DIR" ] && rm -Rf "$TMP_DIR"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -n "$CONFIG_CHECK_FILE" ]; then
if [ ! -f "$CONFIG_DIR/$CONFIG_CHECK_FILE" ]; then
echo "Can not find a config file: $CONFIG_DIR$CONFIG_CHECK_FILE"
INSTALL_SH_EXIT_STATUS=1
fi
else
echo "CONFIG_CHECK_FILE not enabled"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# custom operations
export RUBYOPT=-W0
export BUNDLE_DISABLE_PLATFORM_WARNINGS=true
export BUNDLE_HOME=/usr/local/share/bundler
export BUNDLE_APP_CONFIG=/usr/local/share/bundler
export BUNDLE_BIN=/usr/local/bin
export GEM_BIN=/usr/local/bin
export GEM_HOME=/usr/local/share/gem
export JEKYLL_VAR_DIR=/var/jekyll
export JEKYLL_DATA_DIR=/usr/local/share/jekyll
export JEKYLL_BIN=/usr/local/bin
export JEKYLL_ENV=development
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "gem: --no-ri --no-rdoc" >"$HOME/.gemrc"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
mkdir -p "$BUNDLE_HOME" "$JEKYLL_VAR_DIR" "$JEKYLL_DATA_DIR"
chown -R ${USER}:${USER} "$JEKYLL_DATA_DIR" "$JEKYLL_VAR_DIR" "$BUNDLE_HOME"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
yes | gem install jekyll -v 3.9.3 -- --use-system-libraries &&
yes | gem install html-proofer jekyll-reload jekyll-mentions jekyll-coffeescript jekyll-sass-converter jekyll-commonmark \
jekyll-paginate jekyll-compose jekyll-assets RedCloth kramdown jemoji s3_website jekyll-sitemap jekyll-redirect-from \
jekyll-feed jekyll-docs minima jekyll-github-metadata github-pages casjaysdev-jekyll-theme -- --use-system-libraries
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
git -q "https://github.com/casjaysdevdocker/jekyll" "$WWW_ROOT_DIR"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# End application
# eval "$BASH_SET_SAVED_OPTIONS"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# lets exit with code
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exit $INSTALL_SH_EXIT_STATUS
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# ex: ts=2 sw=2 et filetype=sh