Debian Codegraph @

crt/s2n/codebuild/bin/setup_ec2.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 # SPDX-License-Identifier: Apache-2.0
4 set -euo pipefail
5
6 display_usagescip-shell shell shell-project 0.0.0 display_usage().() {
7 catscip-shell system . . cat. <<EOF
8 Usage: $0 [OPTIONS]
9
10 Sets up an AWS EC2 instance for CodeBuild fleets by:
11 1) Installing Nix package manager on a bare EC2 instance
12 2) Configuring Nix to be usable by the root user for CodeBuild compatibility
13 (Note: This is not officially supported by Nix)
14
15 Options:
16 -h, --help Display this help message and exit
17 EOF
18 }
19
20 setup_nixscip-shell shell shell-project 0.0.0 setup_nix().() {
21 echoscip-shell system . . echo. "=== Setting up nix user, groups and permissions ==="
22 sudoscip-shell system . . sudo. groupadd nixbld
23 sudoscip-shell system . . sudo. useradd -m -g nixbld -G nixbld nix
24 # Give everyone on the system read access to the nix user homedir.
25 sudoscip-shell system . . sudo. chmod 755 /home/nixscip-shell filesystem . . `/home/nix`.
26 echoscip-shell system . . echo. "Both $HOME and $USER need to be set for the nix installer to work."
27 echoscip-shell system . . echo. "=== Installing Nix ==="
28 sudoscip-shell system . . sudo. -u nix bash -c "sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon"
29 echoscip-shell system . . echo. "=== Enabling Nix flakes ==="
30 sudoscip-shell system . . sudo. -u nix bash -c 'mkdir -p ~/.config/nix; echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf'
31 # This sidesteps the need to update PATH for every user.
32 sudoscip-shell system . . sudo. ln -s /home/nix/.nix-profile/bin/nixscip-shell filesystem . . `/home/nix/.nix-profile/bin/nix`. /usr/local/binscip-shell filesystem . . `/usr/local/bin`.
33 echoscip-shell system . . echo. "=== Setting up Nix configs for the root user ==="
34 sudoscip-shell system . . sudo. -u root bash -c "ln -s /home/nix/.nix-profile ~/"
35 sudoscip-shell system . . sudo. -u root bash -c "ln -s /home/nix/.config ~/"
36 }
37
38 setup_sudoscip-shell shell shell-project 0.0.0 setup_sudo().() {
39 echoscip-shell system . . echo. "=== Setting up sudo for the nix user, needed for installation ==="
40 # The nix installer refuses to install as root, so we need to set up sudo for the nix user.
41 sudoscip-shell system . . sudo. bash -c "echo 'nix ALL=NOPASSWD: ALL' > /etc/sudoers.d/nix"
42 }
43
44 check_gnutls_configscip-shell shell shell-project 0.0.0 check_gnutls_config().() {
45 if [[ -f "/etc/gnutls/config" ]]; then
46 echoscip-shell system . . echo. "Turning off gnuTLS overrides"
47 sudoscip-shell system . . sudo. rm -f /etc/gnutls/configscip-shell filesystem . . `/etc/gnutls/config`.
48 fi
49 }
50
51 update_ubuntu_packagesscip-shell shell shell-project 0.0.0 update_ubuntu_packages().() {
52 sudoscip-shell system . . sudo. apt update
53 sudoscip-shell system . . sudo. apt upgrade -y
54 }
55 # main
56 for arg in "$@"; do
57 case $arg in
58 -h|--help)
59 display_usagescip-shell shell shell-project 0.0.0 display_usage().
60 exit 0
61 ;;
62 esac
63 done
64 check_gnutls_configscip-shell shell shell-project 0.0.0 check_gnutls_config().
65 update_ubuntu_packagesscip-shell shell shell-project 0.0.0 update_ubuntu_packages().
66 setup_sudoscip-shell shell shell-project 0.0.0 setup_sudo().
67 setup_nixscip-shell shell shell-project 0.0.0 setup_nix().