devsetup1-10 Exercise 2: Run the Provisioning Script Twice =========================================================== STEP 1: SAVE AND SYNTAX-CHECK ----------------------------- Save the script from the chapter as ~/machine-setup/bootstrap.sh. cd ~/machine-setup chmod +x bootstrap.sh bash -n bootstrap.sh # no output means the syntax is valid # optional, if you install it: sudo apt install shellcheck ; shellcheck bootstrap.sh STEP 2: RUN IT TWICE -------------------- ./bootstrap.sh 2>&1 | tee run1.log ./bootstrap.sh 2>&1 | tee run2.log Run it as your normal user, from the desktop session, not with sudo in front. WHAT THE SECOND RUN SHOULD SHOW ------------------------------- grep -c 'already installed' run2.log # one line per apt_install section grep -E 'Setting up|Unpacking|Get:' run2.log # should print nothing Every apt_install line reads "already installed: ...", the sources step does not edit the file again (the grep finds non-free), the nvm directory exists so nothing is cloned, and VS Code is already installed so its section is skipped. Two things still happen by design: "apt-get update" runs, and "nvm install --lts" reports the version is already installed. The extension loop re-checks extensions and reports they are already installed. If the second run installs anything, a check is wrong. Read the log to see which package name the script asked about, and compare it with dpkg-query -W -f='${Status}' NAME (the name may differ from the command). STEP 3: ADD A NEW TOOL, CORRECTLY --------------------------------- Example: add tmux. Insert a new section before the final echo lines: echo "== 8. Extra tools ==" apt_install tmux Rules for a correct addition: - use apt_install for anything from apt, so it is skipped when present - keep the section number and a one-line heading, so the log reads well - for a tool NOT from apt, guard it with have TOOL or a directory test, as the nvm section does, and never run an installer unconditionally - never write a password or token into the script Run it again: only the new section does any work. WHY THIS WORKS AS AN ANSWER --------------------------- Idempotence (safe to repeat) is the property that makes a provisioning script trustworthy, and running it twice is the direct test. Logging both runs gives evidence to compare rather than a feeling that it "looked fine".