[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.


Log in to reply
 

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