|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -# Display available updates to Academic. |
| 3 | +# Source Themes Academic: Theme updater |
| 4 | +# Checks for available updates and then asks to install any updates. |
| 5 | +# https://sourcethemes.com/academic/ |
| 6 | +# |
| 7 | +# Command: bash ./update_academic.sh |
| 8 | + |
| 9 | +# Check for prerequisites. |
| 10 | +if [ ! -d .git ]; then |
| 11 | + echo "ERROR: This tool is for Git repositories only." |
| 12 | + exit 1; |
| 13 | +fi |
| 14 | + |
| 15 | +# Function to update Academic |
| 16 | +function install_update () { |
| 17 | + # Apply any updates |
| 18 | + git submodule update --remote --merge |
| 19 | + |
| 20 | + # - Update Netlify.toml with required Hugo version |
| 21 | + if [ -f ./netlify.toml ]; then |
| 22 | + version=$(sed -n 's/^min_version = //p' themes/academic/theme.toml) |
| 23 | + sed -i '' -e "s/HUGO_VERSION = .*/HUGO_VERSION = $version/g" ./netlify.toml |
| 24 | + fi |
| 25 | + |
| 26 | + echo |
| 27 | + echo "View the release notes at: https://sourcethemes.com/academic/updates" |
| 28 | + echo "If there are breaking changes, the config and/or front matter of content" \ |
| 29 | + "may need upgrading by following the steps in the release notes." |
| 30 | +} |
| 31 | + |
| 32 | +# Display currently installed version (although could be between versions if updated to master rather than tag) |
| 33 | +version=$(sed -n 's/^version = "//p' themes/academic/data/academic.toml) |
| 34 | +echo -e "Source Themes Academic v$version\n" |
| 35 | + |
| 36 | +# Display available updates |
| 37 | +echo -e "Checking for updates...\n" |
4 | 38 | cd themes/academic
|
5 | 39 | git fetch
|
6 | 40 | git log --pretty=oneline --abbrev-commit --decorate HEAD..origin/master
|
7 | 41 | cd ../../
|
8 | 42 |
|
9 |
| -# Update Academic. |
10 |
| -git submodule update --remote --merge |
| 43 | +title="Do you wish to install the above updates?" |
| 44 | +prompt="Choose an option and press Enter:" |
| 45 | +options=("Yes" "No") |
| 46 | + |
| 47 | +echo "$title" |
| 48 | +PS3="$prompt " |
| 49 | +select opt in "${options[@]}"; do |
| 50 | + case $opt in |
| 51 | + Yes ) install_update; break;; |
| 52 | + No ) break;; |
| 53 | + * ) break;; |
| 54 | + esac |
| 55 | +done |
0 commit comments