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 OS_ARCH=$(uname -m) || die "Failed to get arch."
25 x86_64) architecture="amd64" ;;
26 aarch64) architecture="arm64" ;;
29 go_version="go1.20.2.linux-${architecture}.tar.gz"
30 go_url="https://go.dev/dl"
31 wget "${go_url}/${go_version}"
32 rm -rf "/usr/local/go"
33 tar -C "/usr/local" -xzf "go1.20.2.linux-${architecture}.tar.gz"
34 rm "go1.20.2.linux-${architecture}.tar.gz"
35 export PATH=$PATH:/usr/local/go/bin
39 function hugo_build_site () {
41 # Build site via Hugo.
44 # - ${CSIT_DIR} - CSIT main directory.
46 # - die - Print to stderr and exit.
48 if ! installed hugo; then
49 die "Please install Hugo!"
52 pushd "${CSIT_DIR}"/docs || die "Pushd failed!"
53 hugo || die "Failed to run Hugo build!"
54 popd || die "Popd failed!"
58 function hugo_init_modules () {
60 # Initialize Hugo modules.
63 # - ${CSIT_DIR} - CSIT main directory.
65 # - die - Print to stderr and exit.
67 if ! installed hugo; then
68 #die "Please install Hugo!"
69 go_install || die "Failed to install Go!"
70 hugo_install || die "Failed to install Hugo!"
71 terraform_install || die "Failed to install Terraform!"
74 pushd "${CSIT_DIR}"/docs || die "Pushd failed!"
75 hugo mod get -u || die "Failed to run Hugo mod!"
76 popd || die "Popd failed!"
80 function hugo_install () {
82 # Install Hugo Extended.
84 OS_ARCH=$(uname -m) || die "Failed to get arch."
86 x86_64) architecture="amd64" ;;
87 aarch64) architecture="arm64" ;;
90 hugo_version="v0.111.3/hugo_extended_0.111.3_linux-${architecture}.deb"
91 hugo_url="https://github.com/gohugoio/hugo/releases/download"
92 hugo_link="${hugo_url}/${hugo_version}"
93 wget -O "hugo.deb" "${hugo_link}" || die "Failed to install Hugo!"
94 dpkg -i "hugo.deb" || die "Failed to install Hugo!"
95 rm "hugo.deb" || die "Failed to install Hugo!"
99 function installed () {
101 # Check if the given utility is installed. Fail if not installed.
104 # - ${1} - Utility to check.
105 # Returns (implicitly):
106 # - 0 - If command is installed.
107 # - 1 - If command is not installed.