File: ci-setup

package info (click to toggle)
subnetcalc 2.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 600 kB
  • sloc: python: 1,496; cpp: 1,306; sh: 446; makefile: 23
file content (233 lines) | stat: -rwxr-xr-x 8,761 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env bash
#
# GitHub Actions Scripts
# Copyright (C) 2021-2025 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact: thomas.dreibholz@gmail.com

# Bash options:
set -eu


# ====== Check arguments ====================================================
USE_PACKAGING=0
while [ $# -gt 0 ] ; do
   if [ "$1" == "package" ] ; then
      USE_PACKAGING=1
   fi
   shift
done


# ====== Check/set environment variables ====================================
if [ ! -e /etc/os-release ] ; then
   echo >&2 "ERROR: /etc/os-release does not exist!"
   exit 1
fi
. /etc/os-release


# ====== Ubuntu/Deban =======================================================
if [ "${ID}" == "ubuntu" ] || [ "${ID}" == "debian" ] ; then
   PACKAGES="python3 python3-distro"
   if [ -v CC ] ; then
      if [[ "${CC}" =~ .*gcc.* ]] ; then
         PACKAGES="${PACKAGES} gcc"
      elif [[ "${CC}" =~ .*clang.* ]] ; then
         PACKAGES="${PACKAGES} clang"
      fi
   fi
   if [ ${USE_PACKAGING} -eq 1 ] ; then
      # Need to install pbuilder as well:
      PACKAGES="${PACKAGES} build-essential debian-archive-keyring debian-ports-archive-keyring devscripts distro-info eatmydata fakeroot pbuilder qemu-user-static sudo"
   fi

   apt-get update -qq
   # DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -qy
   # shellcheck disable=SC2086
   DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::=--force-confold -o Dpkg::Options::=--force-confdef --no-install-recommends \
      ${PACKAGES}

   if [ "${ID}" == "ubuntu" ] ; then
      # Add PPA dreibh/ppa for Ubuntu:
      DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::=--force-confold -o Dpkg::Options::=--force-confdef --no-install-recommends \
         software-properties-common
      apt-add-repository -y ppa:dreibh/ppa || true
      apt-get update -q
   fi

   if [ ${USE_PACKAGING} -eq 1 ] ; then
      # ====== pbuilder environment =========================================
      # Example for GitHub Actions:
      # https://github.com/jrl-umi3218/github-actions/tree/master/setup-pbuilder

      if [ ! -v OS ] || [ "${OS}" == "" ] ; then
         OS="${ID}"
      fi
      if [ ! -v DIST ] ||  [ "${DIST}" == "" ] ; then
         DIST="${VERSION_CODENAME}"
      fi
      if [ ! -v ARCH ] || [ "${ARCH}" == "" ] ; then
         ARCH="$(dpkg --print-architecture)"
      fi

      if [ "${OS}" == "ubuntu" ] ; then
         COMPONENTS="main universe"
         MIRRORSITE=http://dk.archive.ubuntu.com/ubuntu/
         KEYRING="/usr/share/keyrings/ubuntu-archive-keyring.gpg"
      elif [ "${OS}" == "debian" ] ; then
         COMPONENTS="main"
         if [ "${ARCH}" == "m68k" ] || [ "${ARCH}" == "riscv64" ] ; then
            # Debian Ports (special architectures)
            MIRRORSITE="http://ftp.ports.debian.org/debian-ports/"
            KEYRING="/usr/share/keyrings/debian-ports-archive-keyring.gpg"
         else
            # Debian (supported architectures)
            MIRRORSITE="http://ftp.dk.debian.org/debian/"
            KEYRING="/usr/share/keyrings/debian-archive-keyring.gpg"
         fi
      else
         echo >&2 "ERROR: Unknown distribution ${ID}!"
         exit 1
      fi

      cores=$(getconf _NPROCESSORS_ONLN 2>/dev/null || true)
      cat >/etc/pbuilderrc <<EOF
#!/bin/bash -e

# ====== Settings ===========================================================
DISTRIBUTION="${DIST}"
COMPONENTS="${COMPONENTS}"
MIRRORSITE="${MIRRORSITE}"
DEBOOTSTRAPOPTS=("\${DEBOOTSTRAPOPTS[@]}" "--keyring=${KEYRING}")
DEBOOTSTRAPOPTS=("\${DEBOOTSTRAPOPTS[@]}" "--variant=buildd")
ARCHITECTURE="${ARCH}"

APTCACHEHARDLINK=no

USECOLORS=yes
COMPRESSPROG=cat
EXTRAPACKAGES=eatmydata
EATMYDATA=yes

# Multi-core: set concurrency level. The packaging scripts will handle it properly:
export CONCURRENCY_LEVEL=${cores}
export DEB_BUILD_OPTIONS="parallel=${cores}"

# ====== Directories ========================================================
NAME="\${OS}-\${DISTRIBUTION}-\${ARCHITECTURE}"
BASETGZ="/var/cache/pbuilder/\${NAME}-base.tgz"
APTCACHE="/var/cache/pbuilder/aptcache/\${NAME}/"
BUILDPLACE="/var/cache/pbuilder/build/\${NAME}/"
BUILDRESULT="/var/cache/pbuilder/result/\${NAME}/"
HOOKDIR="/var/cache/pbuilder/hook.d/"

mkdir -p \${APTCACHE}
mkdir -p \${BUILDRESULT}
mkdir -p \${HOOKDIR}
EOF
      echo "----- /etc/pbuilderrc: ------------------------------------------------------"
      cat /etc/pbuilderrc
      echo "-----------------------------------------------------------------------------"

      OS="${OS}" DISTRIBUTION="${DIST}" ARCHITECTURE="${ARCH}" pbuilder create \
         --debootstrapopts --variant=buildd \
         | grep -v "^I: Retrieving\|^I: Validating\|^I: Unpacking\|^I: Extracting\|^I: Configuring\|^I: new cache content"
         # --debootstrapopts --keyring=/etc/apt/trusted.gpg

      # Speed up pbuilder:
      echo "echo \"force-unsafe-io\" > /etc/dpkg/dpkg.cfg.d/02apt-speedup" | \
         OS="${OS}" DISTRIBUTION="${DIST}" ARCHITECTURE="${ARCH}" pbuilder login --save-after-exec

      # ====== Add ppa:dreibh/ppa, updates and backports =================
      if [ "${OS}" == "ubuntu" ] ; then
         # Add PPA dreibh/ppa for Ubuntu:
         OS="${OS}" DISTRIBUTION="${DIST}" ARCHITECTURE="${ARCH}" pbuilder login --save-after-login <<EOF
DEBIAN_FRONTEND=noninteractive apt-get install -qqy -o Dpkg::Options::=--force-confold -o Dpkg::Options::=--force-confdef --no-install-recommends \
software-properties-common
apt-add-repository -y ppa:dreibh/ppa
apt-get update -q
EOF
      fi
   fi


# ====== Fedora =============================================================
elif [ "${ID}" == "fedora" ] ; then
   PACKAGES="clang make python3 python3-distro"
   if [ ${USE_PACKAGING} -eq 1 ] ; then
      # Need to install mock as well:
      PACKAGES="${PACKAGES} fedora-release findutils mock nosync rpmdevtools   which strace sudo"
   fi

   # dnf upgrade -qy
   # shellcheck disable=SC2086
   dnf install -qy ${PACKAGES}

   if [ ${USE_PACKAGING} -eq 1 ] ; then
      # ====== Mock environment =============================================
      groupadd -f mock

      if [ ! -v OS ] || [ "${OS}" == "" ] ; then
         OS="${ID}"
      fi
      if [ ! -v DIST ] ||  [ "${DIST}" == "" ] ; then
         DIST="${VERSION_ID}"
      fi
      if [ ! -v ARCH ] || [ "${ARCH}" == "" ] ; then
         ARCH="$(uname -m)"
      fi

      if ! grep "^\[copr-dreibh-ppa\]" "/etc/mock/${OS}-${DIST}-${ARCH}.cfg" ; then
         shopt -s extglob
         ppa="config_opts['dnf.conf'] += \"\"\"\n[copr-dreibh-ppa]\nname=Copr repo for ppa owned by dreibh\nbaseurl=https://copr-be.cloud.fedoraproject.org/results/dreibh/ppa/fedora-\$releasever-\$basearch/\ntype=rpm-md\nskip_if_unavailable=True\ngpgcheck=1\ngpgkey=https://copr-be.cloud.fedoraproject.org/results/dreibh/ppa/pubkey.gpg\nrepo_gpgcheck=0\nenabled=1\n\"\"\""
         ppa="${ppa//+( )$/\\n}"
         echo -e "${ppa}" | tee -a "/etc/mock/${OS}-${DIST}-${ARCH}.cfg"
         if ! grep "^\[copr-dreibh-ppa\]" "/etc/mock/${OS}-${DIST}-${ARCH}.cfg" ; then
            echo >&2 "ERROR: Unable to inject PPA configuration into Mock configuration file /etc/mock/${OS}-${DIST}-${ARCH}.cfg!"
            exit 1
         fi
      fi
   fi


# ====== FreeBSD ============================================================
elif [ "${ID}" == "freebsd" ] ; then
   PACKAGES="autoconf automake bash gcc libtool git python3 py311-distro"

   # shellcheck disable=SC2086
   ASSUME_ALWAYS_YES=yes pkg install -y ${PACKAGES}

   if [ ! -e /usr/ports/.git ] ; then
      rm -rf /usr/ports/* /usr/ports/.??* || true
      mkdir -p /usr/ports
      cd /usr/ports
      git init -b main
      git remote add freebsd https://git.freebsd.org/ports.git
      git remote set-url --push freebsd ssh://git@gitrepo.freebsd.org/ports.git
      git config --add remote.freebsd.fetch "+refs/notes/*:refs/notes/*"
      git config pull.rebase true
      git pull --depth=1 freebsd main
      git branch --set-upstream-to=freebsd/main main
   fi

# ====== Unknown ============================================================
else

   echo >&2 "ERROR: Unknown distribution ${ID}!"
   exit 1

fi