This file is indexed.

/usr/bin/cleanup_digikamdb is in digikam 4:3.5.0-0ubuntu10.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/sh

# Author: Andi Clemens, <andi dot clemens at gmail dot com>
#
# Description:
#
# This script will read in the digiKam configuration file to determine the
# database location. It will then make sure that digiKam is not running and
# call "sqlite3 DATABASE 'VACUUM;" on the database, to clean up and optimize
# the tables.
# This will often lead to great performance gain and a smaller database file
# size.

# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# FUNCTIONS
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

# $1: char
# $2: count (optional)
repeat_char()
{
    local header_offset=20
    for i in $(seq ${2:-$header_offset}); do
        echo -n "$1"
    done
}

# -----------------------------------------------------------------------------

# $*: string
pretty_header()
{
    # use an offset to center text
    local offset=$(repeat_char " ")
    local offset_length=$(expr $(expr length "${offset}") \* 2)

    # calculate length
    local str_length=$(expr length "$*")
    local length=$(expr ${str_length} + ${offset_length})

    # delimiter line
    local delimiter=$(repeat_char "-" ${length})

    # print header
    echo "${delimiter}"
    echo "${offset}$*${offset}"
    echo "${delimiter}"
}

# -----------------------------------------------------------------------------

# $1: config key
readConfigValue()
{
    local config_file="digikamrc"
    local config_group="Database Settings"
    local db_dir=$(kreadconfig --file "${config_file}" --group "${config_group}" --key "$1")
    echo "${db_dir}"
}


# -----------------------------------------------------------------------------

checkForRunningProgram()
{
    local proc=$(pgrep -u $USER -x digikam)
    if [ "${proc}" != "" ]
    then
        echo "Please shutdown ${digikam_name} before running this script."
        return 1
    fi
    return 0
}

# -----------------------------------------------------------------------------

checkDatabaseType()
{
    local db_type=$(readConfigValue "Database Type")
    if [ "${db_type}" != "QSQLITE" ]
    then
        echo "This program only handles SQLite databases."
        return 1
    fi
    return 0
}

# -----------------------------------------------------------------------------

help()
{
    cat <<EOF
Usage: $(basename $0) <options>

options:
  -t            Include thumbnail databases
  -T            Only cleanup thumbnail databases
  -p <path>     Specify a different database path.
                If the specified path is invalid, the entry from the configuration file will be used.
  -h            Show this help.
EOF
    exit 1
}

# -----------------------------------------------------------------------------

cleanupDB()
{
    cd "$1" > /dev/null 2>&1
    if [ $? = 0 ]; then
        local db_out="${output_str_database}:"
        echo "${output_str_location}:  $(pwd)"

        for db in $(eval "find . ${db_find_cmd} 2> /dev/null")
        do
            echo -n "${db_out} ${db} ... "
            sqlite3 ${db} "VACUUM;"
            if [ $? = 0 ]
            then
                echo "done!"
            else
                echo "failed!"
            fi
        done
        echo
        echo "=> Finished"
    else
        echo
        echo "I was not able to enter the database folder."
        echo
        echo "Make sure that the variable '${config_key}' in your 'digikamrc' config file"
        echo "is set correctly and that you have permissions to access the database folder."
    fi
}


# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# MAIN
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

script_name="Cleanup Databases"
script_version="1.1"

digikam_name="digiKam"
digikam_version=$(digikam -v | grep "${digikam_name}" | cut -d: -f2 | sed 's/ //g')

db_dir=$(readConfigValue "Database Name")
db_digikam="digikam[34].db"
db_thumbs="thumbnails-digikam.db"

output_str_location="Location"
output_str_database="Database"

db_find_args="-type f"
db_find_cmd="${db_find_args} -name '${db_digikam}'"

# -----------------------------------------------------------------------------

while getopts "tTp:h" Option
do
    case ${Option} in
        t)  db_find_cmd="${db_find_cmd} -or -name '${db_thumbs}'";;
        T)  db_find_cmd="${db_find_args} -name '${db_thumbs}'";;
        p)  if [ -n ${OPTARG} ]; then 
                if [ -d ${OPTARG} ]; then
                    db_dir=${OPTARG}
                fi
            fi;;
        h)  help;;
        *)  help;;
    esac
done

# -----------------------------------------------------------------------------

pretty_header "${script_name} v${script_version} (${digikam_name} ${digikam_version})"

checkForRunningProgram
if [ $? = 1 ]; then
    exit 1
fi

checkDatabaseType
if [ $? = 1 ]; then
    exit 1
fi

# -----------------------------------------------------------------------------

# backup current working dir
curdir=$(pwd)

# -----------------------------------------------------------------------------

# try to enter the database directory
cleanupDB ${db_dir}

# -----------------------------------------------------------------------------

# restore old working dir
cd ${curdir}