Skip to content

[Wiki.js] Auto Upgrade Script

General
1 1 768
  • 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
  • Cloud Storage

    General zeitkapsl europe cloud proton storage
    2
    0 Votes
    2 Posts
    49 Views
    For EU-based, end-to-end encrypted cloud storage, here are the strongest options beyond what you’re already using: Tresorit (Switzerland) : Probably the gold standard for E2EE. Zero-knowledge, Swiss/EU data residency, excellent for both file sync and secure sharing. More expensive than competitors but very polished and audited. Filen (Germany) : Zero-knowledge E2EE by default, generous free tier (10GB), very competitive pricing on paid plans, and lifetime plans available. Open-source clients. Popular on the privacy subreddits as a Proton Drive alternative. Internxt (Spain) : Open-source, zero-knowledge E2EE, GDPR-based. Offers storage plus a few extra privacy tools. Lifetime plans available. Younger company, so weigh that against the price. pCloud (Switzerland, registered in EU) : Massive caveat: E2EE is not default. It’s a paid add-on called “pCloud Crypto.” Without it your files are encrypted at rest but not zero-knowledge. The draw is genuine lifetime plans, which can be cost-effective over years if you trust their longevity.
  • 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.
  • 3 Votes
    7 Posts
    2k Views
    @phenomlab I will have to test this out in my virtual environment. I have an Arch KDE Plasma install in virtualbox that I am testing a bunch of things out before I actually wipe the hard drive and install linux. I am currently in the process of copying my Arch test web server over to virtualbox on linux to make sure that it works. This is the virtual server that I test updates on before updating the production server. I can’t remember the error I was getting but I think it had to do with the network device. That was on the virtualbox side. So the cloud storage will be the next thing that I test.
  • OKTA offering personal password manager

    General okta password manager
    31
    18 Votes
    31 Posts
    7k Views
    @Madchatthew yes, works well for us.
  • NodeBB Twitter / X embeds

    Let's Build It twitter script
    34
    21 Votes
    34 Posts
    10k Views
    @phenomlab said: @DownPW thanks for spotting (and fixing) this issue. I admittedly threw this together quickly for @jac some time ago, and it hasn’t had any love since. If OK with you, I’ll merge these changes into the github repository? No problem dude
  • 2 Votes
    4 Posts
    1k Views
    @qwinter it’s workable I think, but not perfect - then again, unless you write a specific plugin to perform such a task, what is. As you pointed out, you have versioning of sorts with the historical access to reach post.
  • Best antivirus software? (Looking to switch)

    General
    35
    19 Votes
    35 Posts
    8k Views
    @phenomlab or Challenge Accepted haha