-
-
Save ugly95/eeba94a5e1422c4d49725ac328fd553c to your computer and use it in GitHub Desktop.
Run this to run the latest Vivaldi snapshot debug, or download and setup Vivaldi debug for the currently installed Vivaldi snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Start with option to reset debug-version file with -r switch | |
#RESET determines whether to clear the debug-version file | |
RESET='false' | |
usage() | |
{ | |
echo "Usage: vivaldi-snapshot-debug [ -r | --reset ] [ -h | --help ]" | |
exit 2 | |
} | |
#Use getopt to parse switches. | |
PARSED_ARGUMENTS=$(getopt -a -n vivaldi-snapshot-debug -o rh --long reset,help -- "$@") | |
VALID_ARGUMENTS=$? | |
if [ "$VALID_ARGUMENTS" != "0" ]; then | |
usage | |
fi | |
#echo "PARSED_ARGUMENTS is $PARSED_ARGUMENTS" | |
eval set -- "$PARSED_ARGUMENTS" | |
while : | |
do | |
case "$1" in | |
-h | --help) | |
#A basic help description of this script | |
echo "This script essentially automates the instructions for installing the debug binary for a vivaldi-snapshot found here: https://help.vivaldi.com/article/reporting-crashes-on-linux/" | |
echo "" | |
echo "This script will:" | |
echo "1 - Detect the version of vivaldi-snapshot that you are using" | |
echo "2 - Check if you already have a debug file installed for the current version of vivaldi-snapshot" | |
echo "3 - Download the appropriate debug file only if you do not have the current debug file installed. The debug file will be downloaded to your ~/Downloads folder and then unzipped and placed in /opt/vivaldi-snapshot. If the appropriate debug file is already installed then no download will be performed" | |
echo "4 - Run vivaldi-snapshot with gdb when the appropriate debug file is available" | |
echo "" | |
echo "This script assumes vivaldi-snapshot is installed in /opt/vivaldi-snapshot/" | |
echo "This script will create a file to record the current version number of the debug file in /opt/vivaldi-snapshot/vivaldi-snapshot-debug-version" | |
echo "" | |
echo "Use the switch -r or --reset to clear the version of the debug file that is stored in /opt/vivaldi-snapshot/vivaldi-snapshot-debug-version. This will force a download of the appropriate debug file the next time this script is used" | |
echo "" | |
usage | |
shift | |
;; | |
-r | --reset) | |
#Set the RESET variable to true to enable clearing the debug file | |
RESET='true' | |
shift | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
echo "Unexpected option: $1." | |
usage | |
;; | |
esac | |
done | |
#End of getopt parsing | |
#Allow the -r flag to be used to clear record of current debug version number by setting RESET to true | |
#Clear the record of the current debug version when RESET is true | |
if [ $RESET = 'true' ]; then | |
echo "Clearing record of debug version" | |
sudo echo "" | sudo tee /opt/vivaldi-snapshot/vivaldi-snapshot-debug-version > /dev/null | |
#For now just exit after resetting. User can re-reun script without -r to install again. Maybe use UPDATEDEBUG here to get current debug file after resetting. | |
exit 0 | |
fi | |
#Get vivaldi snapshot version - expected format of 'vivaldi-snapshot --version' is: Vivaldi X.X.XXXX.XX snapshot | |
SNAPSHOTVERSION=$(vivaldi-snapshot --version | awk '{print $2}') | |
#Get system architecture | |
ARCH=$(arch) | |
#Format filename with version and architecture for downloading file | |
VERSION=$SNAPSHOTVERSION-$ARCH | |
#Set Download directory | |
DLOAD="$HOME"/Downloads | |
#Initialize a flag for updating the debug file | |
UPDATEDEBUG="0" | |
#Initialize debug version | |
DVERSION="0" | |
echo "Current version of Vivaldi snapshot is: " "$VERSION" | |
echo "Checking if the debug file is currently installed..." | |
#Check if a debug file exists and a file exists that provides the snapshot debug version | |
if [ -f /opt/vivaldi-snapshot/vivaldi-snapshot-debug ] && [ -f /opt/vivaldi-snapshot/vivaldi-snapshot-debug-version ] ; then | |
#Read the first line of /opt/vivaldi-snapshot/vivaldi-snapshot-debug-version to get the current version of the debug file | |
echo "Debug file found. Checking version..." | |
read -r DVERSION < /opt/vivaldi-snapshot/vivaldi-snapshot-debug-version | |
echo "Current version of debug file is " "$DVERSION" | |
else | |
#If there isn't already a vivaldi-snapshot-debug-version, then set a flag to download the current debug version | |
UPDATEDEBUG="1" | |
fi | |
#Check if the current debug file is already in /opt/vivaldi-snapshot by checking the value of the vivaldi-snapshot-debug-version file or if the update flag is set | |
#if [ -f /opt/vivaldi-snapshot/vivaldi-"$VERSION"-debug ] ; then | |
if [ "$DVERSION" != "$VERSION" ] || [ "$UPDATEDEBUG" == "1" ] ; then | |
#If debug not found or update flag is set then ask to download. | |
#Prompt accepts one keystroke. Script ends unless input is y, Y or Enter. | |
read -p "Current version of debug file not found. Download now? [Y/n]" -n 1 -r | |
echo | |
if [[ ! $REPLY =~ ^(y|Y|"")$ ]]; then | |
#Exit if user doesn't want to download | |
exit 0 | |
fi | |
#Download debug file for current version of vivald-snapshot to ~/Downloads | |
echo "Downloading debug file and unzipping to ~/Downloads ..." | |
echo "" | |
wget -c -P"$DLOAD" https://vivaldi.com/download/vivaldi-$VERSION-debug.zip | |
#Check for failed download | |
WGETRETURN=$? | |
if [[ $WGETRETURN -ne 0 ]]; then | |
#If the download fails give a basic message then exit | |
echo "There was an error downloading vivaldi-"$VERSION"-debug.zip" | |
echo "Perhaps the debug binary has not been made available." | |
echo "Press any key to exit..." | |
read EXITVAR | |
exit 1 | |
fi | |
#Check that the zip file is downloaded where expected | |
if [ ! -f "$DLOAD"/vivaldi-"$VERSION"-debug.zip ]; then | |
echo "The zip file " "$DLOAD"/vivaldi-"$VERSION"-debug.zip "was not found." | |
echo "Press any key to exit..." | |
read EXITVAR | |
exit 2 | |
fi | |
echo "Unzipping..." | |
gzip -dS.zip "$DLOAD"/vivaldi-"$VERSION"-debug.zip | |
echo "Debug file will be installed to Vivaldi snapshot install location /opt/vivaldi-snapshot/vivaldi-snapshot-debug" | |
if [ ! -f "$DLOAD"/vivaldi-"$VERSION"-debug ]; then | |
echo "The debug file " "$DLOAD"/vivaldi-"$VERSION"-debug.zip "did not unzip properly." | |
echo "Press any key to exit..." | |
read EXITVAR | |
exit 3 | |
fi | |
sudo install -m755 $(ls -t "$DLOAD"/vivaldi-"$VERSION"-debug | head -1) /opt/vivaldi-snapshot/vivaldi-snapshot-debug | |
#Add the current version of the vivaldi-debug file to /opt/vivaldi-snapshot/vivaldi-snapshot-debug-version to check next time this script is run | |
echo "$VERSION" | sudo tee /opt/vivaldi-snapshot/vivaldi-snapshot-debug-version > /dev/null | |
#Run vivaldi with debug | |
echo "Debug file is at current version for vivaldi-snapshot. Starting vivaldi-snapshot. If Vivaldi crashes enter 'bt' to run a backtrace. After closing Vivaldi enter 'quit' to exit" | |
gdb -ex run --args /opt/vivaldi-snapshot/vivaldi-snapshot-debug --user-data-dir="$HOME"/.config/vivaldi-snapshot | |
else | |
echo "" | |
#Run vivaldi with debug | |
echo "Debug file is at current version for vivaldi-snapshot. Starting vivaldi-snapshot. If Vivaldi crashes enter 'bt' to run a backtrace. After closing Vivaldi enter 'quit' to exit" | |
echo "" | |
gdb -ex run --args /opt/vivaldi-snapshot/vivaldi-snapshot-debug --user-data-dir="$HOME"/.config/vivaldi-snapshot | |
fi | |
$SHELL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment