Skip to content

[Wiki.js] Auto Upgrade Script

General
1 1 736
  • Hi 🙂

    Sorry if I’m not in the right category.

    It’s nothing compared to @phenomlab and for all that he gives us but here’s a small contribution.

    I use the excellent software Wiki.js for my Wiki and I wrote this script and I share it with you


    Informations


    – The script allows you to automatically upgrade Wiki.js.

    – It pre-checks the installed version and compares it with the latest available on GitHub.

    – A backup of Wiki.js is made before the version upgrade in a defined directory.

    – The script has a –rollback option which allows you to return to the version installed before the execution of the script thanks to the backup if a problem occurs. (This does not prevent having another backup on hand 🙂 )


    Use


    – Copy and adapt the code below and paste it into a file named upgrade-wikijs.sh :

    nano upgrade-wikijs.sh
    

    – Make the script executable :

    chmod +x upgrade-wikijs.sh
    

    – Use it :

    ./upgrade-wikijs.sh
    
    ./upgrade-wikijs.sh --rollback
    

    CODE


    – I consider postgreSQL database engine is installed for Wiki.js
    This is the best possible choice for the future.

    – Adapt the code below :

    #!/bin/bash
    #####################################################
    #### Auteur: DownPW
    #### Date: 06.12.2021
    #####################################################
    ################ Upgrade wiki.js ####################
    #####################################################
    ###
    
    ### Definition of variables
    WIKIDIR=/pathtoyourwiki
    PACKAGE_VERSION_OLD=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' $WIKIDIR/package.json)
    CURRENT_WIKI=$(curl -s https://api.github.com/repos/Requarks/wiki/releases/latest | grep tag_name | head -n 1 | cut -d '"' -f 4)
    CURRENT_WIKI_DOWNLOAD="https://github.com/Requarks/wiki/releases/download/$CURRENT_WIKI/wiki-js.tar.gz"
    
    ### Script option: Rollback to old version
    if [[ $1 == "--rollback" ]]
    then
     if [[ -d /home/XXXX/wiki.bak ]]
     then
      PACKAGE_VERSION_BACKUP=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' /home/XXXX/wiki.bak/wikipw/package.json)
      echo "Stop wiki.js ..."
      systemctl stop wiki
      echo "Stop wiki.js OK..."
      
      echo "Stop postgresql ..."
      systemctl stop postgresql
      echo "Stop postgresql OK..."
      
      echo "Rollback to $PACKAGE_VERSION_BACKUP ..."
      rm -rf $WIKIDIR/* && cp -r /home/XXXX/wiki.bak/wikipw/* $WIKIDIR
      echo "Rollback to $PACKAGE_VERSION_BACKUP OK"
      
      echo "Reload and restart necessary services ..."
      systemctl daemon-reload
      systemctl enable wiki
      systemctl reload nginx.service
      nginx -t
      systemctl restart nginx.service
      systemctl start postgresql
      echo "Reload and restart necessary services OK"
      
      echo "Starting Wiki.js. It may take a few seconds ..."
      systemctl start wiki
      echo "Starting Wiki.js OK"
      
      exit 0
     else
      echo "No backups found :("
      exit 1
     fi
    fi
    
    ### Backup of the old version and Upgrade to the new one
    if [[ $CURRENT_WIKI != $PACKAGE_VERSION_OLD ]]
    then
     read -r -p "Do you want to update Wiki.js $PACKAGE_VERSION_OLD to the version $CURRENT_WIKI? [Y/n] " response
     if [[ $response =~ ^([yY]|"")$ ]]
     then
      echo "Stop wiki.js ..."
      systemctl stop wiki
      echo "Stop wiki.js OK"
      
      echo "Stop postgresql ..."
      systemctl stop postgresql
      echo "Stop postgresql OK"
      
      echo "Wiki.js update ..."
      
      echo "version download $CURRENT_WIKI ..."
      (cd /home/XXXX/ && curl --progress-bar -LO $CURRENT_WIKI_DOWNLOAD)
      echo "version download $CURRENT_WIKI OK"
      
      echo "Removed old residue from this script ..."
      rm -rf /home/XXXX/wiki.bak
      echo "Removed old residue from this script OK"
      
      echo "Creating the working directory ..."
      mkdir /home/XXXX/wiki.bak/
      echo "Creating the working directory OK"
      
      echo "Configuration backup $PACKAGE_VERSION_OLD ..."
      cp $WIKIDIR/config.yml /home/XXXX/config.yml.bak
      cp -r $WIKIDIR /home/XXXX/wiki.bak
      echo "Configuration backup $PACKAGE_VERSION_OLD OK"
      
      echo "Version deletion $PACKAGE_VERSION_OLD ..."
      rm -rf $WIKIDIR/*
      echo "Version deletion $PACKAGE_VERSION_OLD OK"
      
      echo "Extraction and installation of the version $CURRENT_WIKI ..."
      tar xzf /home/XXXX/wiki-js.tar.gz -C $WIKIDIR && rm /home/XXXX/wiki-js.tar.gz
      cp /home/XXXX/config.yml.bak $WIKIDIR/config.yml && rm /home/XXXX/config.yml.bak
      echo "Extraction and installation of the version $CURRENT_WIKI OK"
    
      echo "Reload and restart necessary services :"
      systemctl daemon-reload
      systemctl enable wiki
      systemctl reload nginx.service
      nginx -t
      systemctl restart nginx.service
      systemctl start postgresql
      echo "Reload and restart necessary services OK"
      
      echo "################"
      PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' $WIKIDIR/package.json)
      echo "Wiki.js $PACKAGE_VERSION_OLD has been updated to version $PACKAGE_VERSION"
      echo "################"
      
      echo "Start Wiki.js. It may take a few seconds ..."
      systemctl start wiki
      echo "Start Wiki.js OK"
      
      echo "----------------"
      echo "Status of necessary services ..."
      systemctl status nginx
      echo "----------------"
      systemctl status postgresql
      echo "----------------"
      systemctl status wiki
      echo "----------------"
      echo "If something is wrong, please check the logs: 'journalctl -u wiki.service --since today'"
      echo "To undo the update to the latest version, use the option '--rollback'"
      echo "----------------"
     fi
    else
    ### Wiki.js UP TO DATE
     echo "################"
     echo "Wiki.js $PACKAGE_VERSION_OLD is already up to date. No update needed"
     echo "################"
    fi
    

    Sorry if the traduction is not excellent 🙂


Related Topics
  • What’s going on with NodeBB?

    Performance nodebb script die
    20
    8 Votes
    20 Posts
    2k Views
    @cagatay The most reliable way to upgrade Node.js on Ubuntu depends on how you originally installed it. Method 1: Using NVM (Recommended) If you already use Node Version Manager (NVM), upgrading is simple. NVM allows you to keep both versions and switch between them if needed. Install Node 22: nvm install 22 Switch to Node 22: nvm use 22 Set it as your default: nvm alias default 22 Verify the change: node -v Method 2: Using NodeSource (PPA) If you installed Node.js via apt using the NodeSource repository, you need to update the repository script to point to the new version. Remove the old NodeSource list (optional but cleaner): sudo rm /etc/apt/sources.list.d/nodesource.list Download and run the NodeSource setup script for Node 22: curl -fsSL [https://deb.nodesource.com/setup_22.x](https://deb.nodesource.com/setup_22.x) | sudo -E bash - Install/Upgrade Node.js: sudo apt-get install -y nodejs Verify the installation: node -v Method 3: Using the ‘n’ Package If you have npm installed, you can use the n interactive manager. Clear the npm cache: sudo npm cache clean -f Install the ‘n’ helper: sudo npm install -g n Install Node 22: sudo n 22 Update your shell: hash -r Troubleshooting Permission Denied: If you see permission errors using Method 2 or 3, ensure you are using sudo. Path Issues: If node -v still shows version 20 after upgrading via NVM, restart your terminal or run source ~/.bashrc. Conflicts: Avoid mixing these methods. If you switch from apt to nvm, it is best to sudo apt remove nodejs first to avoid path conflicts.
  • Infrared the new WiFi?

    General wifi infrared
    4
    2 Votes
    4 Posts
    2k Views
    @JAC those speeds are indeed possible over light as a transport medium (if you consider the speed) but I can’t comprehend the distance quoted. If you happen to encounter a solid obstacle, the beam is either absorbed, or deflected meaning the data never arrives.
  • Email Provider

    General email gmail proton
    9
    5 Votes
    9 Posts
    2k Views
    @phenomlab lol it is a great excuse and sometimes a combination of both haha
  • Virgin Media Pricing

    General virgin media sky
    11
    9 Votes
    11 Posts
    2k Views
    @phenomlab some good savings there Mark. I’ll post mine once my new deal changes over.
  • Windows 10 End of Life

    General windows linux arch end of life
    10
    2 Votes
    10 Posts
    2k Views
    @phenomlab this looks very nice as well. It is nice that they keep the KDE Neon a rolling release so you will get those updated apps even though Ubuntu isn’t a rolling release. Is it a rolling distro? KDE neon is rolling for KDE software. The Ubuntu base OS is not, but certain packages will be updated as needed to support KDE software requiring newer library versions than what is provided by Ubuntu. Apps from the main repositories are not rolling either, and therefore can be up to two years old. Users are encouraged not to use them, and to instead get apps from Snap or Flatpak using KDE’s Discover app store. In neon, Discover is set up to only show apps from these sources, filtering out apps from the repositories.
  • OKTA offering personal password manager

    General okta password manager
    31
    18 Votes
    31 Posts
    6k Views
    @Madchatthew yes, works well for us.
  • NodeBB v4.0.0

    General nodebb sudonix version 4
    28
    4 Votes
    28 Posts
    4k Views
    @Panda said in NodeBB v4.0.0: the workings of World aren’t intuitive Its not easy to get World populating when a forum is new to it This is a good point and one I’ve considered also. It’s a little confusing to be honest.
  • [NODEBB] Stats

    Unsolved Customisation plugin stats script
    20
    1
    2 Votes
    20 Posts
    4k Views
    @phenomlab said in [NODEBB] Stats: @jac or I land up fixing it I wouldn’t put it past you