Skip to content

[Wiki.js] Auto Upgrade Script

General
  • 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 🙂


  • 4 Votes
    4 Posts
    56 Views

    @Norrad Are you looking for anything in particular? I only ask because Sudonix uses a number of custom functions which I wrote, but all are available on GitHub and fully supported here.

  • 13 Votes
    27 Posts
    2k Views

    yuuuuu.png

  • 4 Votes
    11 Posts
    362 Views

    @Hari Really? Can you elaborate a bit more here?

  • Embeds

    General
    4
    4 Votes
    4 Posts
    176 Views

    @OT Are you testing embeds, or did you insert this link for another purpose? For clarity, this isn’t a testing category 🙂

  • Nodebb design

    Solved General
    2
    1 Votes
    2 Posts
    144 Views

    @Panda said in Nodebb design:

    One negative is not being so good for SEO as more Server side rendered forums, if web crawlers dont run the JS to read the forum.

    From recollection, Google and Bing have the capability to read and process JS, although it’s not in the same manner as a physical person will consume content on a page. It will be seen as plain text, but will be indexed. However, it’s important to note that Yandex and Baidu will not render JS, although seeing as Google has a 90% share of the content available on the web in terms of indexing, this isn’t something you’ll likely lose sleep over.

    @Panda said in Nodebb design:

    The “write api” is preferred for server-to-server interactions.

    This is mostly based around overall security - you won’t typically want a client machine changing database elements or altering data. This is why you have “client-side” which could be DOM manipulation etc, and “server-side” which performs more complex operations as it can communicate directly with the database whereas the client cannot (and if it can, then you have a serious security flaw). Reading from the API is perfectly acceptable on the client-side, but not being able to write.

    A paradigm here would be something like SNMP. This protocol exists as a UDP (UDP is very efficient, as it is “fire and forget” and does not wait for a response like TCP does) based service which reads performance data from a remote source, thus enabling an application to parse that data for use in a monitoring application. In all cases, SNMP access should be “RO” (Read Only) and not RW (Read Write). It is completely feasible to assume complete control over a firewall for example by having RW access to SNMP and then exposing it to the entire internet with a weak passphrase.

    You wouldn’t do it (at least, I hope you wouldn’t) and the same ethic applies to server-side rendering and the execution of commands.

  • 1 Votes
    4 Posts
    164 Views

    @Vijay-Kumavat-0 I think you’d be better off customising the plugin above to be honest. It seems like you’d be reinventing the wheel otherwise.

    I’d modify

    /nodebb/node_modules/nodebb-rewards-essentials/lib/conditions.js
    /nodebb/node_modules/nodebb-rewards-essentials/lib/rewards.js

    These seem to be the two files that control what is in the dropdown lists.

  • 2 Votes
    4 Posts
    172 Views

    @Panda said in Sidebar Widget is no longer on the side!:

    Ah, so sidebar wont work on mobile?

    Correct. If you review the docs on bootstrap, you’ll notice that it is designed on a grid system

    https://getbootstrap.com/docs/5.0/layout/grid/

    What I mean by changing the category is moving it on here to general as you posted it in bugs, when it isn’t.

  • 15 Votes
    26 Posts
    1k Views

    @JAC ALWAYS shop around. Bitdefender, despite being a great product, have a habit of charging more for a renewal than they do a new subscription!