summaryrefslogtreecommitdiffstats
path: root/src/at/local.at
blob: 1def6842022707cc64b8f7535bdf81aef5009ddf (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
# Dpkg helper macros

m4_pattern_forbid([^DPKG_])
m4_pattern_allow([^DPKG_DEBUG$])
m4_pattern_allow([^DPKG_ROOT$])
m4_pattern_allow([^DPKG_ADMINDIR$])
m4_pattern_allow([^DPKG_DATADIR$])

#
# Options.
#

m4_define([DPKG_DIR_INST], [dpkginst])
m4_define([DPKG_DIR_ADMIN], [dpkgdb])

# DPKG_OPTIONS_COMMON
m4_define([DPKG_OPTIONS_COMMON], [dnl
  --admindir=DPKG_DIR_ADMIN dnl
])

# DPKG_DIVERT_OPTIONS
m4_define([DPKG_DIVERT_OPTIONS], [dnl
  --instdir=DPKG_DIR_INST dnl
])

# DPKG_DIVERT(...)
m4_define([DPKG_DIVERT],
  [dpkg-divert DPKG_OPTIONS_COMMON DPKG_DIVERT_OPTIONS])

# DPKG_DIVERT_ADD(...)
m4_define([DPKG_DIVERT_ADD], [DPKG_DIVERT --add])

# DPKG_DIVERT_DEL(...)
m4_define([DPKG_DIVERT_DEL], [DPKG_DIVERT --remove])

#
# Macros.
#

# DPKG_FILE_SIZE()
m4_define([DPKG_FILE_SIZE], [
  $PERL -E 'say -s shift' "$1" dnl
])

# DPKG_GEN_FSYS()
m4_define([DPKG_GEN_DB], [
  mkdir -p DPKG_DIR_INST
])

# DPKG_GEN_FSYS_DIR([$dirname])
m4_define([DPKG_GEN_FSYS_DIR], [
  mkdir -p "DPKG_DIR_INST/$1"
])

# DPKG_GEN_FSYS_FILE([$filename], [$contents])
m4_define([DPKG_GEN_FSYS_FILE], [
  mkdir -p "DPKG_DIR_INST/$(dirname '$1')"
  AT_DATA([DPKG_DIR_INST/$1], [$2])
])

# DPKG_GEN_FSYS_LINK([$pathname], [$target])
m4_define([DPKG_GEN_FSYS_LINK], [
  ln "DPKG_DIR_INST/$1" "DPKG_DIR_INST/$2"
])

# DPKG_CHECK_FSYS_PATH_EXISTS([$pathname])
m4_define([DPKG_CHECK_FSYS_PATH_EXISTS], [
  AT_CHECK([test -e "DPKG_DIR_INST/$1"])
])

# DPKG_CHECK_FSYS_PATH_MISSING([$pathname])
m4_define([DPKG_CHECK_FSYS_PATH_MISSING], [
  AT_CHECK([test -e "DPKG_DIR_INST/$1"], [1])
])

# DPKG_MOD_FSYS_MODE([$mode], [$pathname])
m4_define([DPKG_MOD_FSYS_MODE], [
  chmod $1 "DPKG_DIR_INST/$2"
])

# DPKG_TMPL_CONTROL([$pkgname])
m4_define([DPKG_TMPL_CONTROL],
[Package: $1
Version: 0.0-1
Section: test
Priority: extra
Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
Architecture: all
Description: test package])

# DPKG_GEN_DB_STATUS([$contents])
m4_define([DPKG_GEN_DB_STATUS], [
  mkdir -p "DPKG_DIR_ADMIN"
  AT_DATA([DPKG_DIR_ADMIN/status], [$1])
])

# DPKG_GEN_DB_DIVERSIONS([$contents])
m4_define([DPKG_GEN_DB_DIVERSIONS], [
  mkdir -p "DPKG_DIR_ADMIN"
  AT_DATA([DPKG_DIR_ADMIN/diversions], [$1])
])

# DPKG_GEN_DB_INFO_FILE([$pkg], [$file], [$contents])
m4_define([DPKG_GEN_DB_INFO_FILE], [
  mkdir -p "DPKG_DIR_ADMIN/info"
  AT_DATA([DPKG_DIR_ADMIN/info/$1.$2], [$3])
])

# DPKG_MOD_DB_MODE([$mode], [$pathname])
m4_define([DPKG_MOD_DB_MODE], [
  chmod $1 "DPKG_DIR_ADMIN/$2"
])

# DPKG_GEN_CTRL_FILE([$pkgname], [$file], [$contents])
m4_define([DPKG_GEN_CTRL_FILE], [
  mkdir -p '$1/DEBIAN'

  cat >'$1/DEBIAN/$2' <<CTRL_TEMPL
$3
CTRL_TEMPL
])

# DPKG_GEN_CONTROL([$pkgname])
m4_define([DPKG_GEN_CONTROL], [
  DPKG_GEN_CTRL_FILE([$1], [control], [DPKG_TMPL_CONTROL([$1])])
])

# DPKG_MOD_CONTROL([$pkgname], [$sedexpr])
m4_define([DPKG_MOD_CONTROL], [
  $SED -e '$2' <'$1/DEBIAN/control' >'$1/DEBIAN/control.new'
  mv '$1/DEBIAN/control.new' '$1/DEBIAN/control'
])