|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Generate a unique directory name based on timestamp |
| 4 | +timestamp=$(date +%Y%m%d%H%M%S) |
| 5 | +temp_directory="temp-starter-pack-$timestamp" |
| 6 | + |
| 7 | +# Ask the user for the installation directory |
| 8 | +read -p "Enter the installation directory (e.g., '.' or 'docs'): " install_directory |
| 9 | + |
| 10 | +# Clone the starter pack repository to the temporary directory |
| 11 | +echo "Cloning the starter pack repository..." |
| 12 | +git clone --depth 1 -b use-canonical-sphinx-extension --single-branch https://github.com/canonical/starter-pack "$temp_directory" |
| 13 | +#git clone --depth 1 https://github.com/canonical/sphinx-docs-starter-pack "$temp_directory" |
| 14 | +rm -rf "$temp_directory/.git" |
| 15 | + |
| 16 | +# Update file contents for the install directory |
| 17 | +echo "Updating working directory in workflow files..." |
| 18 | +sed -i "s|working-directory:\s*'\.'|working-directory: '$install_directory'|g" "$temp_directory/sp-files/.github/workflows"/* |
| 19 | +echo "Updating .readthedocs.yaml configuration..." |
| 20 | +sed -i "s|configuration:\s*sp-docs/conf\.py|configuration: $install_directory/conf.py|g" "$temp_directory/sp-files/.readthedocs.yaml" |
| 21 | +sed -i "s|requirements:\s*sp-docs/\.sphinx/requirements\.txt|requirements: $install_directory/.sphinx/requirements.txt|g" "$temp_directory/.readthedocs.yaml" |
| 22 | +echo "Updating conf.py configuration..." |
| 23 | +if [ "$install_directory" == "." ]; then |
| 24 | + sed -i "s|'github_folder':\s*'/sp-docs/'|'github_folder': '/'|g" "$temp_directory/sp-files/conf.py" |
| 25 | +else |
| 26 | + sed -i "s|'github_folder':\s*'/sp-docs/'|'github_folder': '/$install_directory/'|g" "$temp_directory/sp-files/conf.py" |
| 27 | +fi |
| 28 | + |
| 29 | +# Create the specified installation directory if it doesn't exist |
| 30 | +if [ ! -d "$install_directory" ]; then |
| 31 | + echo "Creating the installation directory: $install_directory" |
| 32 | + mkdir -p "$install_directory" |
| 33 | +fi |
| 34 | + |
| 35 | +# Copy the contents of the starter pack repository to the installation directory |
| 36 | +echo "Copying contents to the installation directory..." |
| 37 | +cp -R "$temp_directory"/sp-files/* "$temp_directory"/sp-files/.??* "$install_directory" |
| 38 | + |
| 39 | +# Move workflow files and configuration |
| 40 | +if [ "$install_directory" != "." ]; then |
| 41 | + echo "Moving workflow files and configuration..." |
| 42 | + if [ ! -d .github/workflows ]; then |
| 43 | + mkdir -p .github/workflows |
| 44 | + fi |
| 45 | + mv "$install_directory/.github/workflows"/* .github/workflows |
| 46 | + rmdir -p --ignore-fail-on-non-empty "$install_directory/.github/workflows" |
| 47 | + if [ ! -f .wokeignore ]; then |
| 48 | + ln -s "$install_directory/.wokeignore" |
| 49 | + else |
| 50 | + echo "ACTION REQUIRED: Found a .wokeignore file in the root directory. Include the contents from $install_directory/.wokeignore in this file!" |
| 51 | + fi |
| 52 | +fi |
| 53 | + |
| 54 | +# Clean up |
| 55 | +echo "Cleaning up..." |
| 56 | +rm -rf "$temp_directory" |
| 57 | + |
| 58 | +echo "Setup completed!" |
0 commit comments