aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/usr/bin/drive-version
blob: 6bfa96067537be96e440fc09fa2b9377ecbe41f6 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
###################################################################################################
# drive-version
###################################################################################################
# Copyright 2017-2022 Jean-Christophe Manciot <jcmanciot@sdxlive.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 
# in compliance with the License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# This script is using a project hosted at https://github.com/odeke-em/drive, originally developed 
# by Burcu Dogan while working on the Google Drive team and now maintained by Emmanuel T Odeke.
#
# Attribution — You must give appropriate credit, provide a link to the license, and indicate if 
#               changes were made. You may do so in any reasonable manner, but not in any way that 
#               suggests the licensor endorses you or your use.
###################################################################################################

###################################################################################################
#
# Showing current versions of drive, drive-google scripts and all main related packages.
#
###################################################################################################
#
# Requirements:
# ------------
#
# - We assume that:
#       + drive-google package is already installed.
#       + apt, coreutils, sed & zenity packages are already installed.
#
# - This command must be called from within your local Google drive folder(s).
#
###################################################################################################
#
# Parameters:
# ----------
#
# - <anything> will display this help message
#
###################################################################################################
#
# Usage example:
# -------------
#
# cd ~/<google_drive_folder>
# drive-version
#
###################################################################################################
if [[ $LOG_DRIVE_VERSION == ON ]]; then
        # Getting the last existing file descriptor of ~/.drive-google/logs/drive-google.log
        fd=$(ls -al /proc/$$/fd | grep ~/.drive-google/logs/drive-google.log | sed -E 's|^.* ([0-9]+) -> .*$|\1|g' | sort -V | tail -n 1)

        # Case where fd is unset, i.e the file ~/.drive-google/logs/drive-google.log has not yet been opened
        if [[ -z $fd ]]; then
                lowest_unused_fd () 
                {
                        local fd=0
                        while [ -e /proc/$$/fd/${fd} ]; do
                                fd=$((fd+1))
                        done
                        echo $fd
                }
                fd=$(lowest_unused_fd)

                # Opening ~/.drive-google/logs/drive-google.log as file descriptor $fd for appending
                eval "exec $fd>> ~/.drive-google/logs/drive-google.log"
        fi

        # Writing the trace output generated when set -x is enabled to file descriptor $fd 
        eval "BASH_XTRACEFD=$fd"
        # Logging line numbers - We could also use ${0} for ${BASH_SOURCE}
        BASH_SOURCE_BASENAME=$(basename ${BASH_SOURCE})
        export PS4='${BASH_SOURCE_BASENAME}.${LINENO}+ '
        # Expanding all variables and prints the full commands before output of the command
        set -x
fi

# Preventing globbing (pathname expansion)
set -o noglob
# Allowing extended globbing
shopt -s extglob
# Expanding aliases
shopt -s expand_aliases

# Including alias definitions to sed/grep/awk/perl commands for readability sake
. /usr/include/drive-google/aliases

# Checking for no parameter
if [[ $# -eq 0 ]]; then
        > .driveoutput.log
        printf '%b\n' "-----" >> .driveoutput.log
        printf '%b\n' "drive" >> .driveoutput.log
        printf '%b\n' "-----" >> .driveoutput.log

        output=$(drive version 2>&1)
        # Saving $output in temporary .driveoutput.log file after having escaped all "escape sequences"
        printf '%b\n' "$output" | escape_escape_sequences >> .driveoutput.log

        printf '%b\n' "--------------------" >> .driveoutput.log
        printf '%b\n' "drive-google scripts" >> .driveoutput.log
        printf '%b\n' "--------------------" >> .driveoutput.log

        drive_google_version=$(apt-cache -q=0 2>&1 policy drive-google | grep Installed | sed -E 's|^.*?: (.*)$|\1|g' | cut -d ':' -f 2)
        output="drive-google version:\t${drive_google_version}"
        # Saving $output in temporary .driveoutput.log file after having escaped all "escape sequences"
        printf '%b\n' "$output" | escape_escape_sequences >> .driveoutput.log

        bash_version=$(bash --version | head -n 1)
        output="bash version:\t\t${bash_version}"
        # Saving $output in temporary .driveoutput.log file after having escaped all "escape sequences"
        printf '%b\n' "$output" | escape_escape_sequences >> .driveoutput.log

        cat .driveoutput.log | zenity --text-info --title "Showing current drive & drive-google versions" --width 950 --height 450
        rm .driveoutput.log
        exit 0
else
        # Any parameter
        end_of_help_message_line_number=$(awk '/^if \[\[ \$LOG_/{ print NR; exit }' $(which drive-version))
        ((end_of_help_message_line_number--))
        awk -v var=$end_of_help_message_line_number 'NR >= 20 && NR <= var' $(which drive-version) | zenity --text-info --title "drive-version help" --width 1150 --height 1000
        exit 1
fi