What you will build
Step 1: Link every dotfile
Create install.sh in /workspace. It takes a source directory and a destination directory, and it links every dotfile from the source into the destination:
cat > /workspace/install.sh <<'EOF'
#!/bin/bash
set -eu
src=$1
dest=$2
mkdir -p "$dest"
for f in "$src"/.[!.]*; do
name=$(basename "$f")
ln -sfn "$(readlink -f "$f")" "$dest/$name"
echo "linked $name"
done
EOFRun bash install.sh /workspace/src /workspace/home. Then /workspace/home/.bashrc and /workspace/home/.vimrc should be symbolic links.
Step 2: Move conflicting files into a backup
Replace install.sh with a version that moves any existing entry that does not already link to the source into .dotfiles-backup, and then creates the link. Rerunning must leave correct links alone:
cat > /workspace/install.sh <<'EOF'
#!/bin/bash
set -eu
src=$1
dest=$2
backup="$dest/.dotfiles-backup"
mkdir -p "$dest"
for f in "$src"/.[!.]*; do
[ -e "$f" ] || continue
name=$(basename "$f")
target="$dest/$name"
if [ -L "$target" ] && [ "$(readlink -f "$target")" = "$(readlink -f "$f")" ]; then continue; fi
if [ -e "$target" ] || [ -L "$target" ]; then mkdir -p "$backup"; mv "$target" "$backup/$name"; fi
ln -s "$(readlink -f "$f")" "$target"
echo "linked $name"
done
EOFThe setup creates a real /workspace/home/.bashrc that holds export OLD=1. After you run the script, the backup should hold that original file, and .bashrc should be a link to the source.
Step 3: Refuse a missing source directory
Replace install.sh with the final version. It stops with a message and a non-zero status when the source directory does not exist, and it creates nothing in that case:
cat > /workspace/install.sh <<'EOF'
#!/bin/bash
# usage: install.sh SRC_DIR DEST_DIR
set -eu
src=${1:?usage: install.sh SRC_DIR DEST_DIR}
dest=${2:?usage: install.sh SRC_DIR DEST_DIR}
[ -d "$src" ] || { echo "no such source directory: $src" >&2; exit 1; }
backup="$dest/.dotfiles-backup"
mkdir -p "$dest"
for f in "$src"/.[!.]*; do
[ -e "$f" ] || continue
name=$(basename "$f")
target="$dest/$name"
if [ -L "$target" ] && [ "$(readlink -f "$target")" = "$(readlink -f "$f")" ]; then continue; fi
if [ -e "$target" ] || [ -L "$target" ]; then mkdir -p "$backup"; mv "$target" "$backup/$name"; fi
ln -s "$(readlink -f "$f")" "$target"
echo "linked $name"
done
EOFRun bash install.sh /workspace/nope /workspace/home-x. It should fail and leave no /workspace/home-x directory.
Files
install.sh: the finished script.walkthrough.sh: every step of the reference solution, in order.
How it is checked
Each step in the guided lab has a check script that runs on the lab machine after you finish. It passes only when the files and output it expects are there, so the lab cannot be completed by reading alone.