File indexing completed on 2025-01-05 04:00:16
0001 #!/bin/bash 0002 0003 # Common methods for script to build AppImage bundle. 0004 # 0005 # SPDX-FileCopyrightText: 2013-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0006 # 0007 # SPDX-License-Identifier: BSD-3-Clause 0008 # 0009 0010 ######################################################################## 0011 # Check if run as root 0012 ChecksRunAsRoot() 0013 { 0014 0015 if [[ $EUID -ne 0 ]]; then 0016 echo "This script should be run as root using sudo command." 0017 exit 1 0018 else 0019 echo "Check run as root passed..." 0020 fi 0021 0022 } 0023 0024 ######################################################################## 0025 # Check CPU core available (Linux or MacOS) 0026 ChecksCPUCores() 0027 { 0028 0029 CPU_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) 0030 0031 if [[ $CPU_CORES -gt 1 ]]; then 0032 CPU_CORES=$((CPU_CORES-1)) 0033 fi 0034 0035 echo "CPU Cores to use : $CPU_CORES" 0036 0037 } 0038 0039 ######################################################################## 0040 # Check OS name and version. 0041 CheckSystemReleaseID() 0042 { 0043 0044 OS_NAME=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | sed 's/\"//' | sed 's/\"//' | tr '[:upper:]' '[:lower:]') 0045 0046 if [[ $OS_NAME == "" ]] ; then 0047 OS_NAME=$(lsb_release -a | grep 'Distributor ID:' | sed 's/Distributor ID://' | xargs | tr '[:upper:]' '[:lower:]') 0048 fi 0049 0050 OS_ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/') 0051 0052 OS_VERSION=$(awk '/DISTRIB_RELEASE=/' /etc/*-release | sed 's/DISTRIB_RELEASE=//' | sed 's/[.]0/./') 0053 0054 if [[ $OS_VERSION == "" ]] ; then 0055 OS_VERSION=$(lsb_release -a | grep 'Release:' | sed 's/Release://' | xargs | tr '[:upper:]' '[:lower:]') 0056 fi 0057 0058 echo "Linux: $OS_NAME - $OS_ARCH - $OS_VERSION" 0059 0060 } 0061 0062 ######################################################################## 0063 # For time execution measurement ; startup 0064 StartScript() 0065 { 0066 0067 BEGIN_SCRIPT=$(date +"%s") 0068 0069 } 0070 0071 ######################################################################## 0072 # For time execution measurement : shutdown 0073 TerminateScript() 0074 { 0075 0076 TERMIN_SCRIPT=$(date +"%s") 0077 difftimelps=$(($TERMIN_SCRIPT-$BEGIN_SCRIPT)) 0078 echo "Elaspsed time for script execution : $(($difftimelps / 3600 )) hours $((($difftimelps % 3600) / 60)) minutes $(($difftimelps % 60)) seconds" 0079 0080 } 0081 0082 ######################################################################## 0083 # Adjust devel env.for for Linux Host 0084 HostAdjustments() 0085 { 0086 0087 # That's not always set correctly in Mageia 6 at least? 0088 export LC_ALL=en_US.UTF-8 0089 export LANG=en_us.UTF-8 0090 0091 # Determine which architecture should be built 0092 if [[ "$(arch)" = "i686" || "$(arch)" = "x86_64" ]] ; then 0093 ARCH=$(arch) 0094 echo "Architecture is $ARCH" 0095 else 0096 echo "Architecture could not be determined" 0097 exit 1 0098 fi 0099 0100 # if the library path doesn't point to our usr/lib, linking will be broken and we won't find all deps either 0101 export LD_LIBRARY_PATH=/usr/lib64/:/usr/lib:/digikam.appdir/usr/lib 0102 0103 } 0104 0105 ######################################################################## 0106 # Copy dependencies with ldd analysis 0107 # arg1 : original file path to parse. 0108 # arg2 : target path to copy dependencies 0109 CopyReccursiveDependencies() 0110 { 0111 0112 echo "Scan dependencies for $1" 0113 0114 FILES=$(ldd $1 | grep "=>" | awk '{print $3}') 0115 0116 for FILE in $FILES ; do 0117 if [ -f "$FILE" ] ; then 0118 cp -u $FILE $2 2> /dev/null || true 0119 # echo " ==> $FILE" 0120 fi 0121 done 0122 0123 } 0124 0125 ######################################################################## 0126 # Automatically register the remote servers has know hosts 0127 RegisterRemoteServers() 0128 { 0129 0130 SERVER_LIST="\ 0131 invent.kde.org \ 0132 tinami.kde.org \ 0133 " 0134 0135 if [[ ! -f $HOME/.ssh/known_hosts ]] ; then 0136 touch $HOME/.ssh/known_hosts 0137 fi 0138 0139 for server in $SERVER_LIST; do 0140 0141 echo "Register $server" 0142 0143 ssh-keygen -R $server 0144 ssh-keyscan -H $server >> $HOME/.ssh/known_hosts 0145 0146 done 0147 0148 }