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!"
71 hugo_book_url="github.com/alex-shpak/hugo-book"
72 hugo_book_version="v0.0.0-20230424134111-d86d5e70c7c0"
73 hugo_book_link="${hugo_book_url}@${hugo_book_version}"
74 pushd "${CSIT_DIR}"/docs || die "Pushd failed!"
75 export PATH=$PATH:/usr/local/go/bin
76 hugo mod get "${hugo_book_link}" || die "Failed to run Hugo mod!"
77 popd || die "Popd failed!"
81 function hugo_install () {
83 # Install Hugo Extended.
85 OS_ARCH=$(uname -m) || die "Failed to get arch."
87 x86_64) architecture="amd64" ;;
88 aarch64) architecture="arm64" ;;
91 hugo_version="v0.111.3/hugo_extended_0.111.3_linux-${architecture}.deb"
92 hugo_url="https://github.com/gohugoio/hugo/releases/download"
93 hugo_link="${hugo_url}/${hugo_version}"
94 wget -O "hugo.deb" "${hugo_link}" || die "Failed to install Hugo!"
95 dpkg -i "hugo.deb" || die "Failed to install Hugo!"
96 rm "hugo.deb" || die "Failed to install Hugo!"
100 function installed () {
102 # Check if the given utility is installed. Fail if not installed.
105 # - ${1} - Utility to check.
106 # Returns (implicitly):
107 # - 0 - If command is installed.
108 # - 1 - If command is not installed.