diff --git a/scripts/helpers/eosio.sh b/scripts/helpers/eosio.sh index 95d33743b22..fdf42d22ec2 100755 --- a/scripts/helpers/eosio.sh +++ b/scripts/helpers/eosio.sh @@ -312,29 +312,32 @@ function ensure-libpq-and-libpqxx() { fi if [[ $ARCH == "Linux" ]]; then + if [[ $CURRENT_USER != "root" ]] ; then + LIBPQ_SUDO="$SUDO_LOCATION" + fi if [[ $NAME == "Amazon Linux" ]]; then #install libpq if [ ! -d /usr/include/libpq ]; then - amazon-linux-extras enable postgresql11 && \ - yum install -y libpq-devel + $LIBPQ_SUDO amazon-linux-extras enable postgresql11 && \ + $LIBPQ_SUDO yum install -y libpq-devel fi EXTRA_CMAKE_FLAGS="-DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/libpq" elif [[ $NAME == "CentOS Linux" ]]; then #install libpq if [ ! -d /usr/pgsql-13 ]; then CENTOS_VERSION=$(rpm -E %{rhel}) - yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$CENTOS_VERSION-x86_64/pgdg-redhat-repo-latest.noarch.rpm - [ $CENTOS_VERSION -lt 8 ] || dnf -qy module disable postgresql - yum install -y postgresql13-devel + $LIBPQ_SUDO yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$CENTOS_VERSION-x86_64/pgdg-redhat-repo-latest.noarch.rpm + [ $CENTOS_VERSION -lt 8 ] || $LIBPQ_SUDO dnf -qy module disable postgresql + $LIBPQ_SUDO yum install -y postgresql13-devel fi export PostgreSQL_ROOT=/usr/pgsql-13 export PKG_CONFIG_PATH=/usr/pgsql-13/lib/pkgconfig elif [[ $NAME == "Ubuntu" ]]; then # install libpq - if [ ! -d /usr/include/postgresql ]; then - echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ + if [ ! -d /usr/include/postgresql ]; then + $LIBPQ_SUDO bash -c 'source /etc/os-release; echo "deb http://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \ - apt-get update && apt-get -y install libpq-dev + apt-get update && apt-get -y install libpq-dev' fi EXTRA_CMAKE_FLAGS="-DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql" fi