3 # Copyright (c) 2023 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 function go_install () {
23 go_version="go1.20.2.linux-arm64.tar.gz"
24 go_url="https://go.dev/dl"
25 wget "${go_url}/${go_version}"
26 rm -rf "/usr/local/go"
27 tar -C "/usr/local" -xzf "go1.20.2.linux-arm64.tar.gz"
28 rm "go1.20.2.linux-arm64.tar.gz"
29 export PATH=$PATH:/usr/local/go/bin
33 function hugo_build_site () {
35 # Build site via Hugo.
38 # - ${CSIT_DIR} - CSIT main directory.
40 # - die - Print to stderr and exit.
42 if ! installed hugo; then
43 die "Please install Hugo!"
46 pushd "${CSIT_DIR}"/docs || die "Pushd failed!"
47 hugo || die "Failed to run Hugo build!"
48 popd || die "Popd failed!"
52 function hugo_init_modules () {
54 # Initialize Hugo modules.
57 # - ${CSIT_DIR} - CSIT main directory.
59 # - die - Print to stderr and exit.
61 if ! installed hugo; then
62 #die "Please install Hugo!"
63 go_install || die "Failed to install Go!"
64 hugo_install || die "Failed to install Hugo!"
65 terraform_install || die "Failed to install Terraform!"
68 pushd "${CSIT_DIR}"/docs || die "Pushd failed!"
69 hugo mod get -u || die "Failed to run Hugo mod!"
70 popd || die "Popd failed!"
74 function hugo_install () {
76 # Install Hugo Extended.
78 hugo_version="v0.111.3/hugo_extended_0.111.3_linux-arm64.deb"
79 hugo_url="https://github.com/gohugoio/hugo/releases/download"
80 hugo_link="${hugo_url}/${hugo_version}"
81 wget -O "hugo.deb" "${hugo_link}" || die "Failed to install Hugo!"
82 dpkg -i "hugo.deb" || die "Failed to install Hugo!"
83 rm "hugo.deb" || die "Failed to install Hugo!"
87 function installed () {
89 # Check if the given utility is installed. Fail if not installed.
92 # - ${1} - Utility to check.
93 # Returns (implicitly):
94 # - 0 - If command is installed.
95 # - 1 - If command is not installed.