[Linux] Bash script: adding the modding patch to Vivaldi installations


  • Moderator

    For Linux i (me is always a lazybone) made a little script to patch the browser.html and copy custom.js and custom.css in a selected Vivaldi installation.

    The script can only be run as root. And the files custom.js and custom.css should reside in $HOME/VivaldiPatch of the current user.

    #!/bin/bash
    
    ##############################################
    # Author: GwenDragon
    # License: GPL
    ##############################################
    
    if [ $UID != 0 ] ; then
        echo "Nur root darf das!
    Bitte mit su oder sudo -i als root einloggen und dann das Skript starten."
        exit 255
    fi
    
    mod_dir=$HOME/VivaldiPatch
    if [ ! "$1" = "" ] ; then
        mod_dir=$1
    fi
    
    vivaldi_installs=$(dirname $(find /opt -name "vivaldi-bin" )) ;
    vivaldi_install_dirs=( $vivaldi_installs ) ;
    
    echo "---------------------"
    count=1
    selected=0
    echo "Gefundene Installationen:"
    for dir in $vivaldi_installs ; do    
    	echo $dir": "$count ;
    	((count++)) ;
    done
    read -p "
    Welche Installation patchen?
    Bitte Nummer eingeben und Enter drücken oder X für Abbruch
    Auswahl eingeben: " selected ;
    if [ "$selected" = "X" ] ; then 
    	exit ;
    fi
    ((selected--)) ;
    if [ $selected -ge ${#vivaldi_install_dirs[@]} ] ; then
        echo "Auswahl zu groß!"
    fi
    dir=${vivaldi_install_dirs[$selected]} ;
    echo "---------------------
    "
    echo "Patch von "${mod_dir}" für "${vivaldi_install_dirs[$selected]} ;
    
    cp "$dir/resources/vivaldi/browser.html" "$dir/resources/vivaldi/browser.html-$(date +%Y-%m-%dT%H-%M-%S)"
    
    alreadypatched=$(grep '<link rel="stylesheet" href="style/custom.css" />' $dir/resources/vivaldi/browser.html);
    if [ "$alreadypatched" = "" ] ; then
        echo Patche browser.html
    	sed -i -e 's/<\/head>/<link rel="stylesheet" href="style\/custom.css" \/> <\/head>/' "$dir/resources/vivaldi/browser.html"
    	sed -i -e 's/<\/body>/<script src="custom.js"><\/script> <\/body>/' "$dir/resources/vivaldi/browser.html"
    else
            echo "browser.html ist schon gepatcht!"
    fi
    
    if [ -f "$mod_dir/custom.css" ] ; then	
        echo Kopiere custom.css
        cp -f "$mod_dir/custom.css" "$dir/resources/vivaldi/style/custom.css"
    else 
        echo custom.css fehlt in $mod_dir
    fi
    
    if [ -f "$mod_dir/custom.js" ] ; then	
        echo Kopiere custom.js
        cp -f "$mod_dir/custom.js" "$dir/resources/vivaldi/custom.js"
    else 
        echo custom.js fehlt in $mod_dir!
    fi
    

    Feel free to change the script as you like.

    PS: the messages in bash script are in German so you have to translate yourself :P



  • I think this script is maybe also useable on Windows10 with a little coding to use it with the sublinux.


  • Moderator

    That's a handy script.


  • Moderator

    @lamarca Thanks :)


  • Moderator

    @rocknrolf I have no tested.

    But as the script uses standard tools and folders of Vivaldi all should work on every Linux. \o/ !1o1!!!


  • Moderator

    @gwen-dragon My pleasure and thanks as well:)


  • Moderator

    I hope your personal local translator tool or translation webpage works well in translating my german debug messages.


  • Moderator

    I don't have any problem with logs/debugs messages as long as they are in English :p



  • English version:

    #!/bin/bash
    
    ##############################################
    # Author: GwenDragon
    # License: GPL
    ##############################################
    
    if [ $UID != 0 ] ; then
        echo "Please use 'sudo' or log in as root."
        exit 255
    fi
    
    mod_dir=$HOME/VivaldiPatch
    if [ ! "$1" = "" ] ; then
        mod_dir=$1
    fi
    
    vivaldi_installs=$(dirname $(find /opt -name "vivaldi-bin" )) ;
    vivaldi_install_dirs=( $vivaldi_installs ) ;
    
    echo "---------------------"
    count=1
    selected=0
    echo "Installations found:"
    for dir in $vivaldi_installs ; do    
    	echo $dir": "$count ;
    	((count++)) ;
    done
    read -p "
    Select installation to patch.
    Input number and press [Enter] or [X] to cancel.
    Input selection: " selected ;
    if [ "$selected" = "X" ] ; then 
    	exit ;
    fi
    ((selected--)) ;
    if [ $selected -ge ${#vivaldi_install_dirs[@]} ] ; then
        echo "Selection too large!"
    fi
    dir=${vivaldi_install_dirs[$selected]} ;
    echo "---------------------
    "
    echo "Patch originating from "${mod_dir}" targeting "${vivaldi_install_dirs[$selected]} ;
    
    cp "$dir/resources/vivaldi/browser.html" "$dir/resources/vivaldi/browser.html-$(date +%Y-%m-%dT%H-%M-%S)"
    
    alreadypatched=$(grep '<link rel="stylesheet" href="style/custom.css" />' $dir/resources/vivaldi/browser.html);
    if [ "$alreadypatched" = "" ] ; then
        echo patching browser.html
    	sed -i -e 's/<\/head>/<link rel="stylesheet" href="style\/custom.css" \/> <\/head>/' "$dir/resources/vivaldi/browser.html"
    	sed -i -e 's/<\/body>/<script src="custom.js"><\/script> <\/body>/' "$dir/resources/vivaldi/browser.html"
    else
            echo "browser.html has already been patched!"
    fi
    
    if [ -f "$mod_dir/custom.css" ] ; then	
        echo copying custom.css
        cp -f "$mod_dir/custom.css" "$dir/resources/vivaldi/style/custom.css"
    else 
        echo custom.css missing in $mod_dir
    fi
    
    if [ -f "$mod_dir/custom.js" ] ; then	
        echo copying custom.js
        cp -f "$mod_dir/custom.js" "$dir/resources/vivaldi/custom.js"
    else 
        echo custom.js missing in $mod_dir
    fi
    


  • @rocknrolf There are multiple windows versions available for patching Vivaldi. One of them is a pinned thread on this subforum.


  • Moderator

    @luetage Job well done, Thanks:)



  • @lamarca That's no big deal, all thanks to the Dragon for finally giving us a Linux version. I just edited this again because I missed 2 translations.


  • Moderator

    @luetage said in [Linux] Bash script: adding the modding patch to Vivaldi installations:

    That's no big deal ....

    Oh yes it is .....



  • @luetage ok I'm a linux guy so I missed it.



  • @gwen-dragon said in [Linux] Bash script: adding the modding patch to Vivaldi installations:

    as the script uses standard tools and folders of Vivaldi all should work on every Linux. \o/ !1o1!!!

    Hi Lilo, this script is a wonderful gift -- thanks!

    It works perfectly for me in Maui [a Ubuntu 16.04 derivative]...

    steffie@Maui-VirtualBox:~/VivaldiPatch$ ls -l
    total 12
    -rw-rw-r-- 1 steffie vboxsf 1210 May 15 13:30 custom.css
    -rw-rw-r-- 1 steffie vboxsf  306 May 15 13:29 custom.js
    -rwxrwxr-x 1 steffie vboxsf 2365 May 14 19:20 PatchVivaldi.sh
    steffie@Maui-VirtualBox:~/VivaldiPatch$ 
    
    steffie@Maui-VirtualBox:~/VivaldiPatch$ sudo ./PatchVivaldi.sh 
    [sudo] password for steffie: 
    ---------------------
    Installations found:
    /opt/vivaldi-snapshot: 1
    
    Select installation to patch.
    Input number and press [Enter] or [X] to cancel.
    Input selection: 1
    ---------------------
    
    Patch originating from /home/steffie/VivaldiPatch targeting /opt/vivaldi-snapshot
    patching browser.html
    copying custom.css
    copying custom.js
    steffie@Maui-VirtualBox:~/VivaldiPatch$
    

    ... but surprisingly only 50% works in Manjaro [ie, Arch-based]...

    [steffie@Tower VivaldiPatch]$ ls -l
    total 12
    -rw-r--r-- 1 steffie steffie 1210 May 15 13:30 custom.css
    -rw-r--r-- 1 steffie steffie  306 May 15 13:29 custom.js
    -rwxr-xr-x 1 steffie steffie 2365 May 14 19:20 PatchVivaldi.sh
    [steffie@Tower VivaldiPatch]$ 
    
    [steffie@Tower VivaldiPatch]$ sudo ./PatchVivaldi.sh 
    [sudo] password for steffie: 
    ---------------------
    Installations found:
    /opt/vivaldi: 1
    /opt/vivaldi-snapshot: 2
    
    Select installation to patch.
    Input number and press [Enter] or [X] to cancel.
    Input selection: 1
    ---------------------
    
    Patch originating from /root/VivaldiPatch targeting /opt/vivaldi
    patching browser.html
    custom.css missing in /root/VivaldiPatch
    custom.js missing in /root/VivaldiPatch
    [steffie@Tower VivaldiPatch]$
    

    That is, despite my files definitely being correctly placed into mod_dir=$HOME/VivaldiPatch as required by your script, for some reason it cannot "see" them, though it successfully does patch "browser.html". It's the same result irrespective of me patching Stable or Snapshot.

    I do not know, but i am wondering if possibly something within this section is incompatible with Manjaro:

    if [ -f "$mod_dir/custom.css" ] ; then	
        echo copying custom.css
        cp -f "$mod_dir/custom.css" "$dir/resources/vivaldi/style/custom.css"
    else 
        echo custom.css missing in $mod_dir
    fi
    
    if [ -f "$mod_dir/custom.js" ] ; then	
        echo copying custom.js
        cp -f "$mod_dir/custom.js" "$dir/resources/vivaldi/custom.js"
    else 
        echo custom.js missing in $mod_dir
    fi
    

    This is probably very unfair of me to ask, but might you have any idea why the script has a problem in Manjaro please?

    PS: I doubt that this detail matters for your script, but fyi the patch i'm doing here is the wonderful one created by @luetage at https://forum.vivaldi.net/post/211536


  • Moderator

    @Steffie My interpretaion of this issue: sudo in Manjaro works different from Mint or Debian.
    In my Mint 18.3 sudo ./PatchVivaldi.sh uses $HOME from logged in user.



  • @gwen-dragon said in [Linux] Bash script: adding the modding patch to Vivaldi installations:

    sudo ./PatchVivaldi.sh uses $HOME from logged in user

    For those previous Konsole transcripts i provided above, I launched Konsole from the directory indicated in your script:

    0_1526374095109_20180515_001.png


  • Moderator

    Looks like sudo in Manjaro is really sudo -H which sets $HOME to targeted user root.

    in Manjaro can you please check /etc/sudoers for Defaults lines.
    May be you post your sudoers here?
    are there some env_delete env_preserve or similar settings in sudoers?

    //EDIT: Which Manjaro and Desktop do you use? I may test it myself.



  • @gwen-dragon Sorry, apparently i don't have access to either that file or directory as just my normal user, & when i tried with root privilege i got a warning that if i proceed i risk corrupting sudo... i chickened out.

    I use Manjaro [Stable branch] KDE.


  • Moderator

    @steffie said in [Linux] Bash script: adding the modding patch to Vivaldi installations:

    when i tried with root privilege i got a warning that if i proceed i risk corrupting sudo...

    sudo cat /etc/sudoers is ok to run. Will not harm your Linux.


Log in to reply
 

Looks like your connection to Vivaldi Forum was lost, please wait while we try to reconnect.