Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 197 lines (160 sloc) 5.85 kb
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
#!/bin/bash

# This script prepares rpm files from the GIT/base tree
# It uses some env variables that may be set before it is run
# If they are not set it autodetects them from main CMakeLists.txt

color_ok="\\033[1;32m"
color_error="\\033[1;31m"
color_normal="\\033[0;39m"
color_warn="\\033[1;33m"

prog_ok(){
echo
echo -e "${color_ok}$@${color_normal}"
}

prog_err(){
echo
echo -e "${color_error}ERROR: $@${color_normal}\n"
}

prog_warn(){
echo -e "${color_warn}$@${color_normal}"
}

check_app_version() {
_APP_NAME="$( grep -e '\W*SET\W*(\W*APPLICATION_EXE_NAME' ${GIT_DIR}/CMakeLists.txt | sed -r 's/^\W*SET\W*APPLICATION_EXE_NAME\W*(\w*)\W*\)/\1/' )"

_APP_VERSION_MAJOR="$( grep -e '\W*SET\W*(\W*LIB_MAJOR' ${GIT_DIR}/CMakeLists.txt | sed -r 's/^\W*SET\W*LIB_MAJOR\W*(\w*)\W*\)/\1/' )"
_APP_VERSION_MINOR="$( grep -e '\W*SET\W*(\W*LIB_MINOR' ${GIT_DIR}/CMakeLists.txt | sed -r 's/^\W*SET\W*LIB_MINOR\W*(\w*)\W*\)/\1/' )"
_APP_VERSION_RELEASE="$( grep -e '\W*SET\W*(\W*LIB_RELEASE' ${GIT_DIR}/CMakeLists.txt | sed -r 's/^\W*SET\W*LIB_RELEASE\W*(\w*)\W*\)/\1/' )"
_APP_VERSION="${_APP_VERSION_MAJOR}.${_APP_VERSION_MINOR}.${_APP_VERSION_RELEASE}"
}

create_rpm_structures(){
cd "${BUILD_DIR}"

cleanup_rpmrc_additions

if [ -d 'rpm' ]; then
prog_ok "Cleaning up the whole $(pwd)/rpm folder..."
rm -fR rpm
fi

prog_ok "Creating the necessary folder structure under the $(pwd)/rpm folder..."
mkdir rpm
mkdir rpm/BUILD
mkdir rpm/RPMS
mkdir rpm/RPMS/i586
mkdir rpm/RPMS/x86_64
mkdir rpm/RPMS/noarch
mkdir rpm/SOURCES
mkdir rpm/SPECS
mkdir rpm/SRPMS
mkdir rpm/tmp

prog_ok "Adding the necessary rpm resources to ${HOME}/.rpmrc..."

cat <<END >>"${HOME}/.rpmrc"
###plexydesk rpmbuild additions###
# These will be autoremoved when rpmbuild is ready
# Please do not modify the lines starting with ###
buildarchtranslate: i386: i586
buildarchtranslate: i486: i586
buildarchtranslate: i586: i586
buildarchtranslate: i686: i586
###plexydesk rpmbuild additions###
END

prog_ok "Adding the necessary rpm resources to ${HOME}/.rpmmacros..."

cat <<END >>"${HOME}/.rpmmacros"
###plexydesk rpmbuild additions###
# These will be autoremoved when rpmbuild is ready
# Please do not modify the lines starting with ###
%_topdir $(pwd)/rpm
%_tmppath $(pwd)/rpm/tmp

# Add your name and e-mail into the %packager field below. You may also want to
# replace vendor with yourself.
%packager PlexyDesk Team <webmaster@plexyplanet.org>
%vendor PlexyDesk Team
###plexydesk rpmbuild additions###
END

# Ensure we go back to base GIT folder
cd "${GIT_DIR}"
}

cleanup_rpmrc_additions(){
if [ -f "${HOME}/.rpmrc" ]; then
prog_ok "Removing the added rpm resources from ${HOME}/.rpmrc..."
sed -i '/###plexydesk rpmbuild/,/additions###/d' "${HOME}/.rpmrc"
fi
if [ -f "${HOME}/.rpmmacros" ]; then
prog_ok "Removing the added rpm resources from ${HOME}/.rpmmacros..."
sed -i '/###plexydesk rpmbuild/,/additions###/d' "${HOME}/.rpmmacros"
fi
}

# Ensure we have the rpmbuild binary
if ! eval "which rpmbuild > /dev/null 2>&1"; then
prog_err "It seems that you do not have the 'rpmbuild' binary in your PATH. ABORTING..."
exit 1
fi

CUR_DIR=`pwd`
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
GIT_DIR="$( dirname "${SCRIPT_DIR}" )"

_BUILD_DIR="${GIT_DIR}/build"
_READY_DIR="${GIT_DIR}/INSTALLERS"
check_app_version

if [ -z "${BUILD_DIR}" ] ; then
prog_warn "The shell variable BUILD_DIR is not set. Using the built-in one... (${_BUILD_DIR})"
export BUILD_DIR="${_BUILD_DIR}"
fi
if [ -z "${READY_DIR}" ] ; then
prog_warn "The shell variable READY_DIR is not set. Using the built-in one... (${_READY_DIR})"
export READY_DIR="${_READY_DIR}"
fi
if [ -z "${APP_NAME}" ] ; then
prog_warn "The shell variable APP_NAME is not set. Using the built-in one... (${_APP_NAME})"
export APP_NAME="${_APP_NAME}"
fi
if [ -z "${APP_VERSION}" ] ; then
prog_warn "The shell variable APP_VERSION is not set. Using the built-in one... (${_APP_VERSION})"
export APP_VERSION="${_APP_VERSION}"
fi

# We will work from the base GIT folder
cd "${GIT_DIR}"

# Ensure we are in the base folder
if ! [ -f 'AUTHORS' ]; then
prog_err "The $(pwd) is not the base ${APP_NAME} folder. ABORTING..."
cd "${CUR_DIR}"
exit 1
fi

# Ensure we have all folders created
if ! [ -d "${READY_DIR}/rpm" ]; then
prog_ok "Creating ${READY_DIR}/rpm folder..."
mkdir -p "${READY_DIR}/rpm"
fi
if ! [ -d "${BUILD_DIR}" ]; then
prog_ok "Creating ${BUILD_DIR} folder..."
mkdir -p "${BUILD_DIR}"
fi

create_rpm_structures

# Check if source tarball exists and copy it to the rpm structure
if ! [ -f "${READY_DIR}/${APP_NAME}-${APP_VERSION}.tar.bz2" ]; then
dist/make_dist_source.sh

if [ $? -ne 0 ]; then
prog_err "Creating the dist RPM files at stage: dist source tarball prepare..."
cleanup_rpmrc_additions
cd "${CUR_DIR}"
exit 1
fi
fi

prog_ok "Copying the dist source tarball to $(pwd)/build/rpm/SOURCES folder..."
cp "${READY_DIR}/${APP_NAME}-${APP_VERSION}.tar.bz2" "${BUILD_DIR}/rpm/SOURCES"

prog_ok "Building the dist RPM files with rpmbuild..."
rpmbuild -ba dist/plexydesk.spec

if [ $? -ne 0 ]; then
    prog_err "Creating the dist RPM files..."
    cleanup_rpmrc_additions
cd "${CUR_DIR}"
exit 1
fi

cleanup_rpmrc_additions

prog_ok "Copying the dist RPM files to ${READY_DIR}/rpm folder..."
find "${BUILD_DIR}/rpm" -name "*.rpm" -exec cp "{}" "${READY_DIR}/rpm" \;

if ! [ -z "${GPGKEY}" ] ; then
prog_ok "Signing the RPM packages with the GPG key ${GPGKEY}..."
rpm --resign ${READY_DIR}/rpm/*.rpm
fi

prog_ok "Dist RPM files are ready."
if [ -z "${GPGKEY}" ] ; then
prog_warn "Don't forget to sign them with 'rpm --resign *.rpm' if they will be distributed."
fi
prog_warn "You can find the dist RPM files here:\n ${READY_DIR}/rpm\n"

ls -la "${READY_DIR}/rpm"

cd "${CUR_DIR}"
Something went wrong with that request. Please try again.