| 1 |
#!/bin/sh |
| 2 |
# SPDX-FileCopyrightText: © 2009 Oprea Dan |
| 3 |
# SPDX-FileCopyrightText: © 2013 Germar Reitze |
| 4 |
# SPDX-FileCopyrightText: © 2022 Jürgen Altfeld |
| 5 |
# SPDX-FileCopyrightText: © 2022 Christian Buhtz <[email protected]> |
| 6 |
# SPDX-FileCopyrightText: © 2023 Kian-Meng Ang |
| 7 |
# SPDX-FileCopyrightText: © 2023 Fabio Fantoni |
| 8 |
# SPDX-FileCopyrightText: © 2024 Tejas Guruswamy |
| 9 |
# |
| 10 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 11 |
# |
| 12 |
# This file is part of the program "Back In Time" which is released under GNU |
| 13 |
# General Public License v2 (GPLv2). See LICENSES directory or go to |
| 14 |
# <https://spdx.org/licenses/GPL-2.0-or-later.html>. |
| 15 |
# |
| 16 |
# This is the configuration file for the Read the Docs service. |
| 17 |
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details. |
| 18 |
|
| 19 |
# Clean up |
| 20 |
if [ -e Makefile ]; then |
| 21 |
rm Makefile; |
| 22 |
fi |
| 23 |
|
| 24 |
# Tmp files |
| 25 |
MAKEFILE="$(mktemp)" |
| 26 |
UNINSTALL_FILES="$(mktemp)" |
| 27 |
UNINSTALL_DIRS="$(mktemp)" |
| 28 |
|
| 29 |
# set default options |
| 30 |
PYTHON="/usr/bin/python3" |
| 31 |
|
| 32 |
USR_BIN_FILES="backintime backintime-askpass" |
| 33 |
|
| 34 |
usage () { |
| 35 |
echo "Usage:" |
| 36 |
echo "$0 [--python | --python3 | --python=PYTHON_BINARY]" |
| 37 |
echo "" |
| 38 |
echo "--python" |
| 39 |
echo "\tuse 'python' to start Python3" |
| 40 |
echo "--python3" |
| 41 |
echo "\tuse 'python3' to start Python3" |
| 42 |
echo "--python=PYTHON_BINARY" |
| 43 |
echo "\tuse PYTHON_BINARY to start Python3" |
| 44 |
} |
| 45 |
|
| 46 |
addInstallFiles () { |
| 47 |
file=$1 |
| 48 |
dest=$2 |
| 49 |
mode=$3 |
| 50 |
if [ -z "$mode" ]; then |
| 51 |
mode=644 |
| 52 |
fi |
| 53 |
for i in $(ls $file); do |
| 54 |
addInstallFile "$i" "$dest" "$mode" |
| 55 |
done |
| 56 |
} |
| 57 |
|
| 58 |
addInstallFile () { |
| 59 |
file=$1 |
| 60 |
dest=$2 |
| 61 |
mode=$3 |
| 62 |
if [ -z "$mode" ]; then |
| 63 |
mode=644 |
| 64 |
fi |
| 65 |
printf "\tinstall --mode=$mode $file \$(DEST)$dest\n" >> ${MAKEFILE} |
| 66 |
addUninstallFile "$file" "$dest" |
| 67 |
} |
| 68 |
|
| 69 |
addSymlink () { |
| 70 |
dst=$1 |
| 71 |
src=$2 |
| 72 |
printf "\tln --symbolic --force $dst \$(DEST)$src\n" >> ${MAKEFILE} |
| 73 |
addUninstallFile "$src" |
| 74 |
} |
| 75 |
|
| 76 |
addInstallFileRename () { |
| 77 |
file=$1 |
| 78 |
dest=$2 |
| 79 |
mode=$3 |
| 80 |
if [ -z "$mode" ]; then |
| 81 |
mode=644 |
| 82 |
fi |
| 83 |
printf "\tinstall --mode=$mode $file \$(DEST)$dest\n" >> ${MAKEFILE} |
| 84 |
addUninstallFileRename "$dest" |
| 85 |
} |
| 86 |
|
| 87 |
addUninstallFile () { |
| 88 |
if [ $# -eq 2 ]; then |
| 89 |
file=$(basename "$1") |
| 90 |
dest=$2 |
| 91 |
path="\$(DEST)$dest/$file" |
| 92 |
else |
| 93 |
path="\$(DEST)$1" |
| 94 |
fi |
| 95 |
printf "\trm -f $path\n" >> ${UNINSTALL_FILES} |
| 96 |
} |
| 97 |
|
| 98 |
addUninstallFileRename () { |
| 99 |
file=$1 |
| 100 |
printf "\trm -f \$(DEST)$file\n" >> ${UNINSTALL_FILES} |
| 101 |
} |
| 102 |
|
| 103 |
addInstallDir () { |
| 104 |
dest=$1 |
| 105 |
printf "\tinstall -d \$(DEST)$dest\n" >> ${MAKEFILE} |
| 106 |
addUninstallDir "$dest" |
| 107 |
} |
| 108 |
|
| 109 |
addUninstallDir () { |
| 110 |
dest=$1 |
| 111 |
printf "\tif [ -d \$(DEST)$dest ]; then rmdir --ignore-fail-on-non-empty \$(DEST)$dest; fi\n" >> ${UNINSTALL_DIRS} |
| 112 |
} |
| 113 |
|
| 114 |
addComment () { |
| 115 |
printf "\t# Install $1\n" >> ${MAKEFILE} |
| 116 |
printf "\t# Uninstall files $1\n" >> ${UNINSTALL_FILES} |
| 117 |
printf "\t# Uninstall directory $1\n" >> ${UNINSTALL_DIRS} |
| 118 |
} |
| 119 |
|
| 120 |
addNewline () { |
| 121 |
printf "\n" >> ${MAKEFILE} |
| 122 |
printf "\n" >> ${UNINSTALL_FILES} |
| 123 |
printf "\n" >> ${UNINSTALL_DIRS} |
| 124 |
} |
| 125 |
|
| 126 |
onTravis () { |
| 127 |
[ "${TRAVIS}" = "true" ] |
| 128 |
} |
| 129 |
|
| 130 |
# Get commandline arguments |
| 131 |
unknown_args="" |
| 132 |
for arg in $*; do |
| 133 |
case $arg in |
| 134 |
--python=*) |
| 135 |
PYTHON=$(echo $arg | cut -f2 -d'=') |
| 136 |
;; |
| 137 |
--python3) |
| 138 |
PYTHON="/usr/bin/python3" |
| 139 |
;; |
| 140 |
--python) |
| 141 |
PYTHON="/usr/bin/python" |
| 142 |
;; |
| 143 |
--help | -h) usage; exit 0;; |
| 144 |
*) unknown_args="$unknown_args $arg";; |
| 145 |
esac |
| 146 |
done |
| 147 |
|
| 148 |
if [ -n "$unknown_args" ]; then |
| 149 |
echo "Unknown Arguments: $unknown_args" |
| 150 |
fi |
| 151 |
|
| 152 |
# Check if the python binary file exists |
| 153 |
if [ ! -f "$PYTHON" ]; then |
| 154 |
echo "Warning: \"${PYTHON}\" not found on this computer" |
| 155 |
fi |
| 156 |
|
| 157 |
if [ -n "$(sed -e "s#^/usr/bin/python3\? #${PYTHON} #gw /dev/stdout" -i $USR_BIN_FILES)" ] |
| 158 |
then |
| 159 |
echo "Replacement of python path with \"${PYTHON}\" successful." |
| 160 |
else |
| 161 |
echo "WARNING: Replacement of python path with \"${PYTHON}\" FAILED. Maybe you ran configure more than once?" |
| 162 |
fi |
| 163 |
|
| 164 |
# Check languages |
| 165 |
mos="" |
| 166 |
langs="" |
| 167 |
for langfile in `ls po/*.po`; do |
| 168 |
lang=`echo $langfile | cut -d/ -f2 | cut -d. -f1` |
| 169 |
mos="po/$lang.mo $mos" |
| 170 |
langs="$lang $langs" |
| 171 |
done |
| 172 |
|
| 173 |
# Start Makefile |
| 174 |
printf ".PHONY: test test-v unittest unittest-v\n" >> ${MAKEFILE} |
| 175 |
|
| 176 |
printf "LANGS=$langs\n\n" >> ${MAKEFILE} |
| 177 |
|
| 178 |
printf "PREFIX=/usr\n" >> ${MAKEFILE} |
| 179 |
printf "DEST=\$(DESTDIR)\$(PREFIX)\n\n" >> ${MAKEFILE} |
| 180 |
|
| 181 |
printf "all:\tbuild\n\n" >> ${MAKEFILE} |
| 182 |
|
| 183 |
printf "build:\ttranslate compress\n" >> ${MAKEFILE} |
| 184 |
|
| 185 |
printf "clean:\n" >> ${MAKEFILE} |
| 186 |
printf "\trm -f po/*.mo\n" >> ${MAKEFILE} |
| 187 |
printf "\trm -f ../doc/manpages/*.gz\n" >> ${MAKEFILE} |
| 188 |
printf "\trm -f config-example-*.gz\n" >> ${MAKEFILE} |
| 189 |
printf "\trm -rf doc-dev/_build/*\n" >> ${MAKEFILE} |
| 190 |
printf "\n" >> ${MAKEFILE} |
| 191 |
|
| 192 |
# Create install and uninstall target |
| 193 |
printf "install:\tinstall_translations\n" >> ${MAKEFILE} |
| 194 |
printf "\n\t# Inject version string into source files\n" >> ${MAKEFILE} |
| 195 |
printf "\t(cd .. && ./updateversion.sh)\n\n" >> ${MAKEFILE} |
| 196 |
|
| 197 |
addComment "python" |
| 198 |
addUninstallDir "/share/backintime/common/__pycache__" |
| 199 |
addUninstallFile "*.pyc" "/share/backintime/common/__pycache__" |
| 200 |
addInstallDir "/share/backintime/common" |
| 201 |
addInstallFiles "*.py" "/share/backintime/common" |
| 202 |
addNewline |
| 203 |
|
| 204 |
addComment "plugins" |
| 205 |
addUninstallDir "/share/backintime/plugins/__pycache__" |
| 206 |
addUninstallFile "*.pyc" "/share/backintime/plugins/__pycache__" |
| 207 |
addInstallDir "/share/backintime/plugins" |
| 208 |
addInstallFiles "plugins/*.py" "/share/backintime/plugins" |
| 209 |
addUninstallDir "/share/backintime" |
| 210 |
addNewline |
| 211 |
|
| 212 |
addComment "documentation" |
| 213 |
addInstallDir "/share/doc/backintime-common" |
| 214 |
addInstallFile "../AUTHORS" "/share/doc/backintime-common" |
| 215 |
addInstallFile "../README.md" "/share/doc/backintime-common" |
| 216 |
addInstallFile "../FAQ.md" "/share/doc/backintime-common" |
| 217 |
addInstallFile "../CHANGES" "/share/doc/backintime-common" |
| 218 |
addInstallFile "../LICENSES.md" "/share/doc/backintime-common" |
| 219 |
addInstallDir "/share/doc/backintime-common/LICENSES" |
| 220 |
addInstallFiles "../LICENSES/*" "/share/doc/backintime-common/LICENSES" |
| 221 |
addNewline |
| 222 |
|
| 223 |
addComment "config and user-callback examples" |
| 224 |
addInstallDir "/share/doc/backintime-common/examples" |
| 225 |
addInstallFile "config-example-local.gz" "/share/doc/backintime-common/examples" |
| 226 |
addInstallFile "config-example-ssh.gz" "/share/doc/backintime-common/examples" |
| 227 |
addInstallDir "/share/doc/backintime-common/user-callback-examples" |
| 228 |
addInstallFiles "../doc/user-callback-examples/user-callback.*" "/share/doc/backintime-common/user-callback-examples" |
| 229 |
addUninstallDir "/share/doc/backintime-common" |
| 230 |
addUninstallDir "/share/doc" |
| 231 |
addNewline |
| 232 |
|
| 233 |
addComment "man" |
| 234 |
addInstallDir "/share/man/man1" |
| 235 |
addInstallFile "../doc/manpages/backintime.1.gz" "/share/man/man1" |
| 236 |
addInstallFile "../doc/manpages/backintime-askpass.1.gz" "/share/man/man1" |
| •237 |
addInstallDir "/share/man/man5" |
| 238 |
addInstallFile "../doc/manpages/backintime-config.5.gz" "/share/man/man5" |
| 239 |
addUninstallDir "/share/man" |
| 240 |
addNewline |
| 241 |
|
| 242 |
addComment "application" |
| 243 |
addInstallDir "/bin" |
| 244 |
addInstallFile "backintime" "/bin" "755" |
| 245 |
addInstallFile "backintime-askpass" "/bin" "755" |
| 246 |
addNewline |
| 247 |
|
| 248 |
addComment "autostart" |
| 249 |
addInstallDir "/../etc/xdg/autostart" |
| 250 |
addInstallFile "backintime.desktop" "/../etc/xdg/autostart" |
| 251 |
addUninstallDir "/../etc/xdg" |
| 252 |
addUninstallDir "/../etc" |
| 253 |
addNewline |
| 254 |
|
| 255 |
addComment "bash-completion" |
| 256 |
addInstallDir "/share/bash-completion/completions" |
| 257 |
addInstallFiles "bash-completion/*" "/share/bash-completion/completions" |
| 258 |
addSymlink "backintime" "/share/bash-completion/completions/backintime-qt" |
| 259 |
addUninstallDir "/share/bash-completion" |
| 260 |
addNewline |
| 261 |
|
| 262 |
# compress |
| 263 |
printf "compress:\n" >> ${MAKEFILE} |
| 264 |
printf "\t# Man pages\n" >> ${MAKEFILE} |
| 265 |
printf "\t@cd ./../doc/manpages && ./build_manpages.sh backintime.1.adoc\n" >> ${MAKEFILE} |
| 266 |
printf "\t@cd ./../doc/manpages && ./build_manpages.sh backintime-askpass.1.adoc\n" >> ${MAKEFILE} |
| 267 |
printf "\t@cd ./../doc/manpages && gzip --best --stdout backintime-config.5 > backintime-config.5.gz\n" >> ${MAKEFILE} |
| 268 |
printf "\t@echo \"Compressed backintime-config.5 into backintime-config.5.gz\"\n" >> ${MAKEFILE} |
| 269 |
|
| 270 |
printf "\t# Config-examples\n" >> ${MAKEFILE} |
| 271 |
printf "\tgzip -n --best -c config-example-local > config-example-local.gz\n" >> ${MAKEFILE} |
| 272 |
printf "\tgzip -n --best -c config-example-ssh > config-example-ssh.gz\n\n" >> ${MAKEFILE} |
| 273 |
|
| 274 |
# translate |
| 275 |
printf "translate:\t$mos\n\n" >> ${MAKEFILE} |
| 276 |
|
| 277 |
for lang in $langs; do |
| 278 |
printf "po/$lang.mo: po/$lang.po\n" >> ${MAKEFILE} |
| 279 |
printf "\tmsgfmt -o po/$lang.mo po/$lang.po\n\n" >> ${MAKEFILE} |
| 280 |
done |
| 281 |
|
| 282 |
# common langs |
| 283 |
printf "install_translations:\n" >> ${MAKEFILE} |
| 284 |
addComment "translations" |
| 285 |
for lang in $langs; do |
| 286 |
addInstallDir "/share/locale/$lang/LC_MESSAGES" |
| 287 |
addInstallFileRename "po/$lang.mo" "/share/locale/$lang/LC_MESSAGES/backintime.mo" |
| 288 |
addUninstallDir "/share/locale/$lang" |
| 289 |
done |
| 290 |
addUninstallDir "/share/locale" |
| 291 |
addUninstallDir "/share" |
| 292 |
addNewline |
| 293 |
|
| 294 |
# uninstall |
| 295 |
printf "uninstall:\tuninstall_files uninstall_dirs\n\n" >> ${MAKEFILE} |
| 296 |
printf "uninstall_files:\n" >> ${MAKEFILE} |
| 297 |
cat ${UNINSTALL_FILES} >> ${MAKEFILE} |
| 298 |
|
| 299 |
printf "uninstall_dirs:\n" >> ${MAKEFILE} |
| 300 |
cat ${UNINSTALL_DIRS} >> ${MAKEFILE} |
| 301 |
|
| 302 |
for target in test test-v unittest unittest-v; do |
| 303 |
printf "\n\n%s:\n" "$target" >> ${MAKEFILE} |
| 304 |
printf "\t@echo \"Target '%s' not available anymore. " "$target">> ${MAKEFILE} |
| 305 |
printf "Use a test runner of your own choice " >> ${MAKEFILE} |
| 306 |
printf "(e.g. 'unittest' or 'pytest').\"" >> ${MAKEFILE} |
| 307 |
printf "\n\t@false" >> ${MAKEFILE} |
| 308 |
done |
| 309 |
|
| 310 |
# Copy Makefile |
| 311 |
mv ${MAKEFILE} Makefile |
| 312 |
chmod 644 Makefile |
| 313 |
|
| 314 |
# Clean up |
| 315 |
for i in "${UNINSTALL_FILES}" "${UNINSTALL_DIRS}"; do |
| 316 |
if [ -e "$i" ]; then |
| 317 |
rm "$i" |
| 318 |
fi |
| 319 |
done |
| 320 |
|
| 321 |
# check python version |
| 322 |
PYTHON_VERSION_REQUIRED="3.9" |
| 323 |
PYTHON_VERSION_CURRENT=$(${PYTHON} --version | tr --delete 'Python ') |
| 324 |
|
| 325 |
# Credits: https://unix.stackexchange.com/a/285928/136851 |
| 326 |
if [ "$(printf '%s\n' "$PYTHON_VERSION_REQUIRED" "$PYTHON_VERSION_CURRENT" | sort -V | head -n1)" != "$PYTHON_VERSION_REQUIRED" ]; then |
| 327 |
printf "Error: Wrong Python version ${PYTHON_VERSION_CURRENT}. " |
| 328 |
printf "But minimal version ${PYTHON_VERSION_REQUIRED} required.\n" |
| 329 |
exit 1 |
| 330 |
fi |
| 331 |
|
| 332 |
|
| 333 |
printf "All OK. Now run:\n" |
| 334 |
printf " make\n" |
| 335 |
printf " sudo make install\n" |