Skip to content

[Wiki.js] Auto Upgrade Script

General
1 1 651
  • 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
    8
    2 Votes
    8 Posts
    768 Views
    @cagatay That is quite the jump as importers from one forum platform to another are notoriously unreliable and could land up being quite costly if it requires managed services.
  • Infrared the new WiFi?

    General wifi infrared
    4
    2 Votes
    4 Posts
    1k 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
    1k 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.
  • 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
  • Windows 10 End of Life

    General windows linux arch end of life
    10
    2 Votes
    10 Posts
    1k 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.
  • NodeBB v4.0.0

    General nodebb sudonix version 4
    28
    4 Votes
    28 Posts
    3k 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 Twitter / X embeds

    Let's Build It twitter script
    34
    21 Votes
    34 Posts
    6k 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.