#!/bin/sh # SPDX-FileCopyrightText: © 2009 Oprea Dan # SPDX-FileCopyrightText: © 2013 Germar Reitze # SPDX-FileCopyrightText: © 2022 Jürgen Altfeld # SPDX-FileCopyrightText: © 2022 Christian Buhtz # 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 # . # # 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-qt backintime-qt_polkit" DBUS_SERVICE_FILES="net.launchpad.backintime.serviceHelper.service" 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" } 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 () { file=$(basename "$1") dest=$2 printf "\trm -f \$(DEST)$dest/$file\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} } # 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 if [ ! -f "$PYTHON" ]; then echo "Warning: \"${PYTHON}\" not found on this computer" fi # patch python command # use 'python' or 'python3' to start Python Version 3.x if [ -n "$(sed -e "s#^/usr/bin/python3\? #${PYTHON} #gw /dev/stdout" -i $USR_BIN_FILES)" ] \ && [ -n "$(sed -e "s#^Exec=/usr/bin/python3\? #Exec=${PYTHON} #gw /dev/stdout" -i $DBUS_SERVICE_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 # Start Makefile printf ".PHONY: test test-v unitest unittest-v\n" >> ${MAKEFILE} printf "PREFIX=/usr\n" >> ${MAKEFILE} printf "DEST=\$(DESTDIR)\$(PREFIX)\n\n" >> ${MAKEFILE} printf "all:\tbuild\n\n" >> ${MAKEFILE} printf "build:\tcompress\n\n" >> ${MAKEFILE} printf "clean:\n" >> ${MAKEFILE} printf "\trm -f po/*.mo\n" >> ${MAKEFILE} printf "\trm -f ../doc/manpages/*.gz\n\n" >> ${MAKEFILE} # Create install and uninstall target printf "install:\n" >> ${MAKEFILE} # Migration printf "\t# Clean-up installed old files that were renamed or moved in later BiT versions\n" >> ${MAKEFILE} printf "\trm -f \$(DEST)/etc/dbus-1/system.d/net.launchpad.backintime.serviceHelper.conf\n" >> ${MAKEFILE} printf "\trm -f \$(DEST)/share/backintime/plugins/qt4plugin.py\n" >> ${MAKEFILE} addNewline printf "\t# Inject version string into source files\n" >> ${MAKEFILE} printf "\t(cd .. && ./updateversion.sh)\n" >> ${MAKEFILE} addNewline addComment "python" addUninstallDir "/share/backintime/qt/__pycache__" addUninstallFile "*.pyc" "/share/backintime/qt/__pycache__" addInstallDir "/share/backintime/qt" addInstallFiles "*.py" "/share/backintime/qt" addInstallDir "/share/backintime/qt/manageprofiles" addInstallFiles "manageprofiles/*.py" "/share/backintime/qt/manageprofiles" addNewline addComment "plugin" 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 "application" addInstallDir "/bin" addInstallFile "backintime-qt" "/bin" "755" addInstallFile "backintime-qt_polkit" "/bin" "755" addInstallDir "/share/metainfo" addInstallFile "io.github.bit_team.back_in_time.gui.metainfo.xml" "/share/metainfo" addNewline addComment "dbus service" addInstallDir "/share/dbus-1/system-services" addInstallFiles "net.launchpad.backintime*.service" "/share/dbus-1/system-services" addUninstallDir "/share/dbus-1" addNewline addComment "dbus conf" addInstallDir "/share/dbus-1/system.d" addInstallFiles "net.launchpad.backintime*.conf" "/share/dbus-1/system.d" addUninstallDir "/share/dbus-1" addUninstallDir "/share" addNewline addComment "polkit action" addInstallDir "/share/polkit-1/actions" addInstallFiles "net.launchpad.backintime*.policy" "/share/polkit-1/actions" addUninstallDir "/share/polkit-1" addNewline addComment "documentation" addInstallDir "/share/doc/backintime-qt" addInstallFile "../AUTHORS" "/share/doc/backintime-qt" addInstallFile "../README.md" "/share/doc/backintime-qt" addInstallFile "../FAQ.md" "/share/doc/backintime-qt" addInstallFile "../CHANGES" "/share/doc/backintime-qt" addInstallFile "../LICENSES.md" "/share/doc/backintime-qt" addInstallDir "/share/doc/backintime-qt/LICENSES" addInstallFiles "../LICENSES/*" "/share/doc/backintime-qt/LICENSES" addNewline addComment ".desktop" addInstallDir "/share/applications" addInstallFiles "*.desktop" "/share/applications" addNewline addComment "man" addInstallDir "/share/man/man1" addInstallFile "../doc/manpages/backintime-qt.1.gz" "/share/man/man1" addUninstallDir "/share/man" addNewline addComment "icons" # application logo (scalable SVG) addInstallDir "/share/icons/hicolor/scalable/apps" addInstallFile "icons/scalable/apps/backintime.svg" "/share/icons/hicolor/scalable/apps" # addInstallFile "icons/scalable/apps/backintime-symbolic.svg" "/share/icons/hicolor/scalable/apps" # icon: show-hidden (scalable SVG) addInstallDir "/share/icons/hicolor/scalable/actions" addInstallFile "icons/scalable/actions/show-hidden.svg" "/share/icons/hicolor/scalable/actions" # # rasterized versions of the logo # for s in 16 22 24 48 64 128 256 512; do # # application logo (PNG) # addInstallDir "/share/icons/hicolor/${s}x${s}/apps" # addInstallFile "icons/${s}x${s}/apps/backintime.png" "/share/icons/hicolor/${s}x${s}/apps" # addInstallFile "icons/${s}x${s}/apps/backintime-symbolic.png" "/share/icons/hicolor/${s}x${s}/apps" # # # icon: show-hidden (PNG # addInstallDir "/share/icons/hicolor/${s}x${s}/actions" # addInstallFile "icons/${s}x${s}/actions/show-hidden.png" "/share/icons/hicolor/${s}x${s}/actions" # done # # printf "\tgtk-update-icon-cache -f /usr/share/icons/hicolor\n" >> ${MAKEFILE} addNewline # compress printf "compress:\n" >> ${MAKEFILE} printf "\t# Man pages\n" >> ${MAKEFILE} printf "\t@cd ./../doc/manpages && ./build_manpages.sh backintime-qt.1.adoc\n" >> ${MAKEFILE} # Uninstall printf "uninstall: uninstall_files uninstall_dirs\n\n" >> ${MAKEFILE} printf "uninstall_files:\n" >> ${MAKEFILE} cat ${UNINSTALL_FILES} >> ${MAKEFILE} printf "uninstall_dirs:\n" >> ${MAKEFILE} cat ${UNINSTALL_DIRS} >> ${MAKEFILE} for target in test test-v unittest unittest-v; do printf "\n\n%s:\n" "$target" >> ${MAKEFILE} printf "\t@echo \"Target '%s' not available anymore. " "$target">> ${MAKEFILE} printf "Use a test runner of your own choice " >> ${MAKEFILE} printf "(e.g. 'unittest' or 'pytest').\"" >> ${MAKEFILE} printf "\n\t@false" >> ${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"