aboutsummaryrefslogtreecommitdiffstats
path: root/slackrepo_SBo-danix.conf
blob: b789c0b1bd731ebb196cc7fb2152d68f5e5ca6db (plain)
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# slackrepo configuration file for the SBo-danix personal repository.
#
# Priority order:
# (1) Environment variables
# (2) ~/.slackreporc
# (3) /etc/slackrepo/slackrepo_SBo-danix.conf
#
# %REPO%, %SLACKVER% and %ARCH% are replaced at runtime.

#-------------------------------------------------------------------------------
# Filestore locations

# Personal SlackBuilds repo (managed as a git fork of SBo):
# Site settings (rsync target, Gotify URL and key) live outside git in a
# root-only file, see SBo-danix.local.example in slackrepo_setup.
SB_LOCAL='/etc/slackrepo/SBo-danix.local'
[ -r "$SB_LOCAL" ] && . "$SB_LOCAL"

SBREPO="/var/lib/sbopkg/SBo-danix"

# Cached sources:
SRCREPO="/var/lib/slackrepo/%REPO%/source"

# Built packages:
#PKGREPO="/var/lib/slackrepo/%REPO%/packages/%SLACKVER%/%ARCH%"
PKGREPO="/repo"

# Backups (comment out to disable):
#PKGBACKUP="/var/lib/slackrepo/%REPO%/backups/%SLACKVER%/%ARCH%"

# Local hintfiles (for overriding SBo packages without touching the SlackBuild):
HINTDIR="/etc/slackrepo/%REPO%/hintfiles"

# Default hintfiles from slackrepo-hints package (optional):
DEFAULT_HINTDIR="/etc/slackrepo/%REPO%/default_hintfiles/%SLACKVER%"

# Logs:
LOGDIR="/var/log/slackrepo/%REPO%"

# Database:
DATABASE="/var/lib/slackrepo/%REPO%/database_%REPO%_%ARCH%.sqlite3"

# Temporary build space (needs plenty of room):
TMP="/tmp/%REPO%"

#-------------------------------------------------------------------------------
# Package tag
# Using _danix instead of _SBo to identify your personal builds.
TAG='_danix'

# Package compression:
PKGTYPE='txz'

#-------------------------------------------------------------------------------
# Build control

SUBSTITUTE=""
NUMJOBS=''
ARCH=''

#-------------------------------------------------------------------------------
# Control argument defaults

VERBOSE='n'
VERY_VERBOSE='n'
DRY_RUN='n'
INSTALL='n'
CHROOT='/'
LINT='n'
KEEP_TMP='n'
COLOR='auto'
NICE='5'
NOWARNING=''

#-------------------------------------------------------------------------------
# Git branch setup
#
# INIT_GITCLONE is only used if SBREPO does not exist yet.
# INIT_GITBRANCH must match the branch you have checked out in SBREPO.
# Since we use a personal branch, gitfetch_hook is replaced below with a
# custom hook that fetches upstream and rebases your branch on top of it.

INIT_GITCLONE='https://github.com/Ponce/slackbuilds.git'
INIT_GITBRANCH='danix-current'

#-------------------------------------------------------------------------------
# Hooks

function danix_gitfetch_hook
{
  local upstream_branch='current'
  local personal_branch='danix-current'

  cd "$SR_SBREPO" || return 1

  local currbranch
  currbranch=$(git rev-parse --abbrev-ref HEAD)
  if [ "$currbranch" != "$personal_branch" ]; then
    echo "slackrepo: WARNING: SBREPO is on branch '$currbranch', expected '$personal_branch'. Skipping git update."
    return 0
  fi

  local muck
  muck=$(git status -s .)
  if [ -n "$muck" ]; then
    echo "slackrepo: WARNING: SBREPO has uncommitted changes. Skipping git update."
    return 0
  fi

  echo "slackrepo: Fetching upstream SBo..."
  git fetch origin || { echo "slackrepo: WARNING: git fetch failed."; return 1; }

  echo "slackrepo: Rebasing $personal_branch onto origin/$upstream_branch..."
  git rebase --rebase-merges -X theirs origin/"$upstream_branch" || {
    echo "slackrepo: ERROR: rebase failed. Resolve conflicts in $SR_SBREPO and run 'git rebase --continue'."
    return 1
  }

  return 0
}

HOOK_START=( danix_gitfetch_hook )

function manage_packages_hook
{
  local args=()
  # --preview does not set OPT_DRY_RUN (slackrepo cmdfunctions.sh), check both
  if [ "$OPT_DRY_RUN" = 'y' ] || [ "$OPT_PREVIEW" = 'y' ]; then
    args+=( --dry-run )
  fi
  REPO="$SR_PKGREPO" /usr/local/bin/manage-packages.sh "${args[@]}"
}

#-------------------------------------------------------------------------------
# generate web files

function gen_web_hook
{
  if [ "$OPT_DRY_RUN" = 'y' ] || [ ! -s "$CHANGELOG" ]; then
    return 0
  fi
  SR_PKGREPO="$SR_PKGREPO" /usr/local/bin/gen_web_hook.sh
  local stat=$?
  [ $stat -ne 0 ] && log_warning "gen_web_hook failed, status $stat"
  return $stat
}

#-------------------------------------------------------------------------------
# dep template generator
# Writes <TEMPLATE_DIR>/<prgnam>.template for each successfully built package
# that has one or more recursive dependencies.

TEMPLATE_DIR='/repo/templates'

function dep_template_hook
{
  local template_dir="${TEMPLATE_DIR:-/repo/templates}"

  [ "$OPT_DRY_RUN" = 'y' ] && return 0
  [ ${#OKLIST[@]} -eq 0 ] && return 0

  mkdir -p "$template_dir" || return 1

  local itemid prgnam dep depname outfile
  for itemid in "${OKLIST[@]}"; do
    [ -z "${FULLDEPS[$itemid]}" ] && continue

    prgnam="${ITEMPRGNAM[$itemid]}"
    outfile="$template_dir/${prgnam}.template"

    {
      for dep in ${FULLDEPS[$itemid]}; do
        depname="${ITEMPRGNAM[$dep]}"
        printf '%s\n' "${depname:-$dep}"
      done
      printf '%s\n' "$prgnam"
    } > "$outfile"

    log_normal "dep_template_hook: wrote $outfile"
  done

  return 0
}

#-------------------------------------------------------------------------------
# rsync push config

function rsync_push_hook
{
  # SBB_PUBLISH=n (set by sb-builder for an unpublished run) holds the push
  # back; sb-publish pushes later. Unset means publish, as from a terminal.
  if [ "$OPT_DRY_RUN" = 'y' ] || [ "$OPT_PREVIEW" = 'y' ] || [ ! -s "$CHANGELOG" ] \
     || [ "${SBB_PUBLISH:-y}" = 'n' ]; then
    return 0
  fi
  /usr/local/bin/sb-publish "$SR_PKGREPO"
  local rsyncstat=$?
  if [ "$rsyncstat" != 0 ]; then
    log_warning "rsync_push_hook failed, status $rsyncstat"
    return 1
  fi
  return 0
}

function recap_hook
{
  # TODOLIST is per-item scratch (overwritten on each build_command call), so it
  # only ever holds the last item. Build the recap from the cumulative status
  # lists that slackrepo dedupes before running the finish hooks.
  local recaplist=(
    "${OKLIST[@]}" "${FAILEDLIST[@]}" "${ABORTEDLIST[@]}"
    "${SKIPPEDLIST[@]}" "${UNSUPPORTEDLIST[@]}"
  )
  recaplist=( $(printf '%s\n' "${recaplist[@]}" | sort -u) )
  [ ${#recaplist[@]} -eq 0 ] && return 0

  local col_name=4 col_ver=7 col_status=6
  local itemid prgnam ver stat
  for itemid in "${recaplist[@]}"; do
    prgnam="${ITEMPRGNAM[$itemid]}"
    ver="${HINT_VERSION[$itemid]:-${INFOVERSION[$itemid]:-?}}"
    stat="${STATUS[$itemid]:-?}"
    [ ${#prgnam} -gt $col_name ]   && col_name=${#prgnam}
    [ ${#ver}    -gt $col_ver ]    && col_ver=${#ver}
    [ ${#stat}   -gt $col_status ] && col_status=${#stat}
  done

  local sep
  sep="+-$(printf '%*s' "$col_name"   '' | tr ' ' '-')-+-$(printf '%*s' "$col_ver" '' | tr ' ' '-')-+-$(printf '%*s' "$col_status" '' | tr ' ' '-')-+"

  echo ""
  echo "Build recap:"
  echo "$sep"
  printf "| %-*s | %-*s | %-*s |\n" "$col_name" "Name" "$col_ver" "Version" "$col_status" "Status"
  echo "$sep"
  for itemid in "${recaplist[@]}"; do
    prgnam="${ITEMPRGNAM[$itemid]}"
    ver="${HINT_VERSION[$itemid]:-${INFOVERSION[$itemid]:-?}}"
    stat="${STATUS[$itemid]:-?}"
    printf "| %-*s | %-*s | %-*s |\n" "$col_name" "$prgnam" "$col_ver" "$ver" "$col_status" "$stat"
  done
  echo "$sep"
  echo ""

  return 0
}

function gotify_hook
{
  # --preview does not set OPT_DRY_RUN (slackrepo cmdfunctions.sh), check both
  if [ "$OPT_DRY_RUN" = 'y' ] || [ "$OPT_PREVIEW" = 'y' ]; then
    return 0
  fi
  if [ -z "${SB_GOTIFY_URL:-}" ] || [ -z "${SB_GOTIFY_KEY:-}" ]; then
    log_warning "SB_GOTIFY_URL/SB_GOTIFY_KEY not set in $SB_LOCAL, skipping gotify_hook"
    return 0
  fi

  local curl_bin
  curl_bin=$(which curl 2>/dev/null)
  if [ ! -x "$curl_bin" ]; then
    log_warning "curl not found, skipping gotify_hook"
    return 1
  fi

  local ok="${#OKLIST[@]}"
  local failed="${#FAILEDLIST[@]}"
  local aborted="${#ABORTEDLIST[@]}"
  local skipped="${#SKIPPEDLIST[@]}"

  local title msg priority
  if [ $(( failed + aborted )) -gt 0 ]; then
    title="slackrepo [$CMD]: FAILED"
    priority=8
  else
    title="slackrepo [$CMD]: OK"
    priority=5
  fi

  msg="OK: $ok  Failed: $failed  Aborted: $aborted  Skipped: $skipped"
  [ ${#OKLIST[@]}      -gt 0 ] && msg+=$'\nOK: '"$(printf '%s ' "${OKLIST[@]}")"
  [ ${#FAILEDLIST[@]}  -gt 0 ] && msg+=$'\nFailed: '"$(printf '%s ' "${FAILEDLIST[@]}")"
  [ ${#ABORTEDLIST[@]} -gt 0 ] && msg+=$'\nAborted: '"$(printf '%s ' "${ABORTEDLIST[@]}")"

  "$curl_bin" -s \
    -H "X-Gotify-Key: $SB_GOTIFY_KEY" \
    -F "title=$title" \
    -F "message=$msg" \
    -F "priority=$priority" \
    "$SB_GOTIFY_URL" >/dev/null
  local stat=$?
  [ $stat -ne 0 ] && log_warning "gotify_hook failed, status $stat"
  return $stat
}

function bell_hook
{
  printf '\a'
  return 0
}

HOOK_FINISH=( manage_packages_hook bell_hook genrepos_hook gen_web_hook dep_template_hook rsync_push_hook recap_hook gotify_hook )

#-------------------------------------------------------------------------------
# gen_repos_files.sh (disabled by default)

USE_GENREPOS='1'

#-------------------------------------------------------------------------------
export XZ_OPT="--threads=0"