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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
#!/bin/sh
# SPDX-FileCopyrightText: © 2009 Oprea Dan
# SPDX-FileCopyrightText: © 2013 Germar Reitze
# SPDX-FileCopyrightText: © 2022 Jürgen Altfeld
# SPDX-FileCopyrightText: © 2022 Christian Buhtz <c.buhtz@posteo.jp>
# SPDX-FileCopyrightText: © 2023 Kian-Meng Ang
# SPDX-FileCopyrightText: © 2023 Fabio Fantoni
# SPDX-FileCopyrightText: © 2024 Tejas Guruswamy
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This file is part of the program "Back In Time" which is released under GNU
# General Public License v2 (GPLv2). See LICENSES directory or go to
# <https://spdx.org/licenses/GPL-2.0-or-later.html>.
#
# This is the configuration file for the Read the Docs service.
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details.
# Clean up
if [ -e Makefile ]; then
rm Makefile;
fi
# Tmp files
MAKEFILE="$(mktemp)"
UNINSTALL_FILES="$(mktemp)"
UNINSTALL_DIRS="$(mktemp)"
# set default options
PYTHON="/usr/bin/python3"
USR_BIN_FILES="backintime backintime-askpass"
usage () {
echo "Usage:"
echo "$0 [--python | --python3 | --python=PYTHON_BINARY]"
echo ""
echo "--python"
echo "\tuse 'python' to start Python3"
echo "--python3"
echo "\tuse 'python3' to start Python3"
echo "--python=PYTHON_BINARY"
echo "\tuse PYTHON_BINARY to start Python3"
}
addInstallFiles () {
file=$1
dest=$2
mode=$3
if [ -z "$mode" ]; then
mode=644
fi
for i in $(ls $file); do
addInstallFile "$i" "$dest" "$mode"
done
}
addInstallFile () {
file=$1
dest=$2
mode=$3
if [ -z "$mode" ]; then
mode=644
fi
printf "\tinstall --mode=$mode $file \$(DEST)$dest\n" >> ${MAKEFILE}
addUninstallFile "$file" "$dest"
}
addSymlink () {
dst=$1
src=$2
printf "\tln --symbolic --force $dst \$(DEST)$src\n" >> ${MAKEFILE}
addUninstallFile "$src"
}
addInstallFileRename () {
file=$1
dest=$2
mode=$3
if [ -z "$mode" ]; then
mode=644
fi
printf "\tinstall --mode=$mode $file \$(DEST)$dest\n" >> ${MAKEFILE}
addUninstallFileRename "$dest"
}
addUninstallFile () {
if [ $# -eq 2 ]; then
file=$(basename "$1")
dest=$2
path="\$(DEST)$dest/$file"
else
path="\$(DEST)$1"
fi
printf "\trm -f $path\n" >> ${UNINSTALL_FILES}
}
addUninstallFileRename () {
file=$1
printf "\trm -f \$(DEST)$file\n" >> ${UNINSTALL_FILES}
}
addInstallDir () {
dest=$1
printf "\tinstall -d \$(DEST)$dest\n" >> ${MAKEFILE}
addUninstallDir "$dest"
}
addUninstallDir () {
dest=$1
printf "\tif [ -d \$(DEST)$dest ]; then rmdir --ignore-fail-on-non-empty \$(DEST)$dest; fi\n" >> ${UNINSTALL_DIRS}
}
addComment () {
printf "\t# Install $1\n" >> ${MAKEFILE}
printf "\t# Uninstall files $1\n" >> ${UNINSTALL_FILES}
printf "\t# Uninstall directory $1\n" >> ${UNINSTALL_DIRS}
}
addNewline () {
printf "\n" >> ${MAKEFILE}
printf "\n" >> ${UNINSTALL_FILES}
printf "\n" >> ${UNINSTALL_DIRS}
}
onTravis () {
[ "${TRAVIS}" = "true" ]
}
# Get commandline arguments
unknown_args=""
for arg in $*; do
case $arg in
--python=*)
PYTHON=$(echo $arg | cut -f2 -d'=')
;;
--python3)
PYTHON="/usr/bin/python3"
;;
--python)
PYTHON="/usr/bin/python"
;;
--help | -h) usage; exit 0;;
*) unknown_args="$unknown_args $arg";;
esac
done
if [ -n "$unknown_args" ]; then
echo "Unknown Arguments: $unknown_args"
fi
# Check if the python binary file exists
if [ ! -f "$PYTHON" ]; then
echo "Warning: \"${PYTHON}\" not found on this computer"
fi
if [ -n "$(sed -e "s#^/usr/bin/python3\? #${PYTHON} #gw /dev/stdout" -i $USR_BIN_FILES)" ]
then
echo "Replacement of python path with \"${PYTHON}\" successful."
else
echo "WARNING: Replacement of python path with \"${PYTHON}\" FAILED. Maybe you ran configure more than once?"
fi
# Check languages
mos=""
langs=""
for langfile in `ls po/*.po`; do
lang=`echo $langfile | cut -d/ -f2 | cut -d. -f1`
mos="po/$lang.mo $mos"
langs="$lang $langs"
done
# Start Makefile
printf "LANGS=$langs\n\n" >> ${MAKEFILE}
printf "PREFIX=/usr\n" >> ${MAKEFILE}
printf "DEST=\$(DESTDIR)\$(PREFIX)\n\n" >> ${MAKEFILE}
printf "all:\tbuild\n\n" >> ${MAKEFILE}
printf "build:\ttranslate compress\n" >> ${MAKEFILE}
printf "clean:\n" >> ${MAKEFILE}
printf "\trm -f po/*.mo\n" >> ${MAKEFILE}
printf "\trm -f man/C/*.gz\n" >> ${MAKEFILE}
printf "\trm -f config-example-*.gz\n" >> ${MAKEFILE}
printf "\trm -rf doc-dev/_build/*\n" >> ${MAKEFILE}
printf "\n" >> ${MAKEFILE}
# Create install and uninstall target
printf "install:\tinstall_translations\n" >> ${MAKEFILE}
printf "\n\t# Inject version string into source files\n" >> ${MAKEFILE}
printf "\t(cd .. && ./updateversion.sh)\n\n" >> ${MAKEFILE}
addComment "python"
addUninstallDir "/share/backintime/common/__pycache__"
addUninstallFile "*.pyc" "/share/backintime/common/__pycache__"
addInstallDir "/share/backintime/common"
addInstallFiles "*.py" "/share/backintime/common"
addNewline
addComment "plugins"
addUninstallDir "/share/backintime/plugins/__pycache__"
addUninstallFile "*.pyc" "/share/backintime/plugins/__pycache__"
addInstallDir "/share/backintime/plugins"
addInstallFiles "plugins/*.py" "/share/backintime/plugins"
addUninstallDir "/share/backintime"
addNewline
addComment "documentation"
addInstallDir "/share/doc/backintime-common"
addInstallFile "../AUTHORS" "/share/doc/backintime-common"
addInstallFile "../README.md" "/share/doc/backintime-common"
addInstallFile "../FAQ.md" "/share/doc/backintime-common"
addInstallFile "../TRANSLATIONS" "/share/doc/backintime-common"
addInstallFile "../CHANGES" "/share/doc/backintime-common"
addInstallFile "../LICENSE" "/share/doc/backintime-common"
addInstallDir "/share/doc/backintime-common/LICENSES"
addInstallFiles "../LICENSES/*" "/share/doc/backintime-common/LICENSES"
addNewline
addComment "config and user-callback examples"
addInstallDir "/share/doc/backintime-common/examples"
addInstallFile "config-example-local.gz" "/share/doc/backintime-common/examples"
addInstallFile "config-example-ssh.gz" "/share/doc/backintime-common/examples"
addInstallDir "/share/doc/backintime-common/user-callback-examples"
addInstallFiles "../doc/user-callback-examples/user-callback.*" "/share/doc/backintime-common/user-callback-examples"
addUninstallDir "/share/doc/backintime-common"
addUninstallDir "/share/doc"
addNewline
addComment "man"
addInstallDir "/share/man/man1"
addInstallFile "man/C/backintime.1.gz" "/share/man/man1"
addInstallFile "man/C/backintime-askpass.1.gz" "/share/man/man1"
addInstallFile "man/C/backintime-config.1.gz" "/share/man/man1"
addUninstallDir "/share/man"
addNewline
addComment "application"
addInstallDir "/bin"
addInstallFile "backintime" "/bin" "755"
addInstallFile "backintime-askpass" "/bin" "755"
addNewline
addComment "autostart"
addInstallDir "/../etc/xdg/autostart"
addInstallFile "backintime.desktop" "/../etc/xdg/autostart"
addUninstallDir "/../etc/xdg"
addUninstallDir "/../etc"
addNewline
addComment "bash-completion"
addInstallDir "/share/bash-completion/completions"
addInstallFiles "bash-completion/*" "/share/bash-completion/completions"
addSymlink "backintime" "/share/bash-completion/completions/backintime-qt"
addUninstallDir "/share/bash-completion"
addNewline
# compress
printf "compress:\n" >> ${MAKEFILE}
printf "\t# Man pages\n" >> ${MAKEFILE}
printf "\tfor i in \$\$(ls -1 man/C/); do case \$\$i in *.gz|*~) continue;; *) gzip -n --best -c man/C/\$\$i > man/C/\$\${i}.gz;; esac; done\n\n" >> ${MAKEFILE}
printf "\t# Config-examples\n" >> ${MAKEFILE}
printf "\tgzip -n --best -c config-example-local > config-example-local.gz\n" >> ${MAKEFILE}
printf "\tgzip -n --best -c config-example-ssh > config-example-ssh.gz\n\n" >> ${MAKEFILE}
# translate
printf "translate:\t$mos\n\n" >> ${MAKEFILE}
for lang in $langs; do
printf "po/$lang.mo: po/$lang.po\n" >> ${MAKEFILE}
printf "\tmsgfmt -o po/$lang.mo po/$lang.po\n\n" >> ${MAKEFILE}
done
# common langs
printf "install_translations:\n" >> ${MAKEFILE}
addComment "translations"
for lang in $langs; do
addInstallDir "/share/locale/$lang/LC_MESSAGES"
addInstallFileRename "po/$lang.mo" "/share/locale/$lang/LC_MESSAGES/backintime.mo"
addUninstallDir "/share/locale/$lang"
done
addUninstallDir "/share/locale"
addUninstallDir "/share"
addNewline
# uninstall
printf "uninstall:\tuninstall_files uninstall_dirs\n\n" >> ${MAKEFILE}
printf "uninstall_files:\n" >> ${MAKEFILE}
cat ${UNINSTALL_FILES} >> ${MAKEFILE}
printf "uninstall_dirs:\n" >> ${MAKEFILE}
cat ${UNINSTALL_DIRS} >> ${MAKEFILE}
# test
for i in "pytest" "py.test-3" "py.test-3.6" "py.test-3.5" "py.test-3.4"; do
PYTEST=$(which $i 2>/dev/null)
if [ -n "${PYTEST}" ]; then
break
fi
done
# Use "python", "python3" or if available "py.test-3"
CMD="${PYTHON}"
printf "test:\tunittest\n\n" >> ${MAKEFILE}
printf "test-v:\tunittest-v\n\n" >> ${MAKEFILE}
for v in "" "-v"; do
# Provide unittests with and without verbosity -v
printf "unittest${v}:\n" >> ${MAKEFILE}
# Use pytest if available
if [ -n "${PYTEST}" ]; then
printf "\t${PYTEST} ${v}\n" >> ${MAKEFILE}
# Fallback to unittest module
else
for i in $(ls -1 test/test_*.py); do
printf "\t${CMD} -m unittest ${v} -b $i\n" >> ${MAKEFILE}
done
fi
printf "\n" >> ${MAKEFILE}
done
# Copy Makefile
mv ${MAKEFILE} Makefile
chmod 644 Makefile
# Clean up
for i in "${UNINSTALL_FILES}" "${UNINSTALL_DIRS}"; do
if [ -e "$i" ]; then
rm "$i"
fi
done
# check python version
PYTHON_VERSION_REQUIRED="3.9"
PYTHON_VERSION_CURRENT=$(${PYTHON} --version | tr --delete 'Python ')
# Credits: https://unix.stackexchange.com/a/285928/136851
if [ "$(printf '%s\n' "$PYTHON_VERSION_REQUIRED" "$PYTHON_VERSION_CURRENT" | sort -V | head -n1)" != "$PYTHON_VERSION_REQUIRED" ]; then
printf "Error: Wrong Python version ${PYTHON_VERSION_CURRENT}. "
printf "But minimal version ${PYTHON_VERSION_REQUIRED} required.\n"
exit 1
fi
printf "All OK. Now run:\n"
printf " make\n"
printf " sudo make install\n"
|