summaryrefslogtreecommitdiff
path: root/move.sh
blob: a175eb2dfa59b3ff3723292d49d5c9b118e18fd0 (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
#!/usr/bin/env bash

in_array() {
	local needle=$1; shift
	local item
	for item in "$@"; do
		[[ $item = $needle ]] && return 0 # Found
	done
	return 1 # Not Found
}

move_files() (
	for d in libsystemd libudev; do
		mkdir src/$d-new
		mv -T src/$d src/$d-new/src
		mv -T src/$d-new src/$d
	done

	for d in basic core shared; do
		mv -T src/{,lib}$d
	done

	pfix=(
		dbus1-generator
		debug-generator
		fstab-generator
		getty-generator
		gpt-auto-generator
		rc-local-generator
		system-update-generator
		sysv-generator

		ac-power
		activate
		analyze
		ask-password
		backlight
		binfmt
		cgls
		cgroups-agent
		cgtop
		coredump
		cryptsetup
		delta
		detect-virt
		escape
		firstboot
		fsck
		hibernate-resume
		hwdb
		initctl
		machine-id-setup
		modules-load
		notify
		nspawn
		path
		quotacheck
		random-seed
		remount-fs
		reply-password
		rfkill
		run
		sleep
		socket-proxy
		stdio-bridge
		sysctl
		sysusers
		timesync
		tmpfiles
		tty-ask-password-agent
		update-done
		update-utmp
		user-sessions
		vconsole
	)
	for d in "${pfix[@]}"; do
		mv -T src/{,systemd-}$d
	done

	mv -T src/systemd-socket-proxy{,d}

	mv -T {shell-completion/bash/,src/kernel-install/bash-completion_}kernel-install
	mv -T {shell-completion/zsh/_,src/kernel-install/zsh-completion_}kernel-install
	mv -T {man,src/kernel-install}/kernel-install.xml

	mv -T src/lib{shared,core}/linux

	mkdir src/libsystemd/include
	mv -T src/{,libsystemd/include}/systemd

	mkdir src/grp-machine
	mv -T src/machine src/grp-machine/libmachine-core
	mkdir src/grp-machine/systemd-machined
	mv -T src/grp-machine/{libmachine-core,systemd-machined}/machined.c
	mkdir src/grp-machine/machinectl
	mv -T src/grp-machine/{libmachine-core,machinectl}/machinectl.c
	mv -T src/{,grp-machine}/nss-mymachines

	mkdir src/grp-resolve
	mv -T src/{resolve,grp-resolve/systemd-resolved}
	mv -T src/{,grp-resolve}/nss-resolve

	mkdir src/grp-system
	mv -T src/{,grp-system}/systemctl

	mkdir src/libfirewall
	mv -T src/lib{shared,firewall}/firewall-util.c
	mv -T src/lib{shared,firewall}/firewall-util.h

	mkdir src/grp-system/systemd
	mv -T src/{libcore,grp-system/systemd}/main.c
	mv -T src/{libcore,grp-system/systemd}/macros.systemd.in
	mv -T src/{libcore,grp-system/systemd}/org.freedesktop.systemd1.conf
	mv -T src/{libcore,grp-system/systemd}/org.freedesktop.systemd1.policy.in.in
	mv -T src/{libcore,grp-system/systemd}/org.freedesktop.systemd1.service
	mv -T src/{libcore,grp-system/systemd}/system.conf
	mv -T src/{libcore,grp-system/systemd}/systemd.pc.in
	mv -T src/{libcore,grp-system/systemd}/triggers.systemd.in
	mv -T src/{libcore,grp-system/systemd}/user.conf

	mkdir src/libudev/include
	mv -T src/libudev/{src,include}/libudev.h

	mv -T src/libsystemd/{src,}/libsystemd.pc.in
	mv -T src/libsystemd/{src,}/libsystemd.sym
	mv -T src/libsystemd/{src,}/.gitignore
	mv -T src/libsystemd/{src,libsystemd-internal}

	mkdir src/systemd-shutdown

	mkdir src/grp-coredump
	mv -T src/{,grp-coredump}/systemd-coredump
	mkdir src/grp-coredump/coredumpctl
	mv -T src/grp-coredump/{systemd-coredump,coredumpctl}/coredumpctl.c

	mkdir src/grp-boot
	mv -T src/boot/efi src/grp-boot/systemd-boot
	mv -T src/boot src/grp-boot/bootctl
	mv -T {test,src/grp-boot/systemd-boot}/test-efi-create-disk.sh

	mkdir build-aux
	mkdir build-aux/Makefile.{once,each}.{head,tail}
	touch build-aux/Makefile.{once,each}.{head,tail}/.gitignore

	mkdir src/libsystemd/libsystemd-journal-internal

	libsystemd_journal_files=(
		audit-type.c
		audit-type.h
		catalog.c
		catalog.h
		compress.c
		compress.h
		fsprg.c
		fsprg.h
		journal-authenticate.c
		journal-authenticate.h
		journal-def.h
		journal-file.c
		journal-file.h
		journal-internal.h
		journal-send.c
		journal-vacuum.c
		journal-vacuum.h
		journal-verify.c
		journal-verify.h
		lookup3.c
		lookup3.h
		mmap-cache.c
		mmap-cache.h
		sd-journal.c
	)
	for file in "${libsystemd_journal_files[@]}"; do
		mv -T src/{journal,libsystemd/libsystemd-journal-internal}/$file
	done

	mkdir src/busctl
	mv src/libsystemd/libsystemd-internal/sd-bus/busctl* src/busctl

	mv -T src/{udev,libudev/src}/udev.h

	mkdir src/grp-timedate
	mv -T src/timedate src/grp-timedate/systemd-timedated
	mkdir src/grp-timedate/timedatectl
	mv -T src/grp-timedate/{systemd-timedated,timedatectl}/timedatectl.c

	mv -T src/{libsystemd/libsystemd-internal/sd-netlink,libshared}/local-addresses.c
	mv -T src/{libsystemd/libsystemd-internal/sd-netlink,libshared}/local-addresses.h
	mv -T src/{libsystemd/libsystemd-internal/sd-netlink,libshared}/test-local-addresses.c

	mv -T src/{journal,grp-journal}
	mv -T {,src/grp-journal/}catalog
	mkdir src/grp-journal/{systemd-journald,journalctl,libjournal-core}
	mv -T src/grp-journal/{,systemd-journald}/journald.c
	mv -T src/grp-journal/{,journalctl}/journalctl.c
	mv    src/grp-journal/*.* src/grp-journal/libjournal-core/

	mv -T src/{,grp-}journal-remote
	local suffix
	for suffix in gatewayd remote upload; do
		mkdir src/grp-journal-remote/systemd-journal-$suffix
		mv src/grp-journal-remote/journal-$suffix* src/grp-journal-remote/systemd-journal-$suffix/
	done

	mv -T src/{,grp-}hostname
	mv -T src/{,grp-}import
	mv -T src/{,grp-}locale
	mv -T src/{,grp-}login
	mv -T src/{,grp-}network
)

breakup_makefile() (
        find . \( -name Makefile -o -name '*.mk' \) -delete

        touch .tmp.move.all
        files=(.tmp.move.all)
        file=/dev/null
        IFS=''
        while read -r line; do
                if [[ $line = '#@'* ]]; then
                        file="${line#'#@'}"
                        file="${file%% *}"
                elif [[ $file = all ]]; then
                        printf '%s\n' "$line" | tee -a "${files[@]}" >/dev/null
                else
			if ! in_array "$file" "${files[@]}"; then
				cat .tmp.move.all > "$file"
				files+=("$file")
			fi
                        printf '%s\n' "$line" >> "$file"
                fi
        done < <(fixup_makefile <Makefile.am)
        rm .tmp.move.all
)

fixup_includes() (
	find src \( -name '*.h' -o -name '*.c' \) \
	     -exec grep '#include "sd-' -l -- {} + |
	    xargs -d $'\n' sed -ri 's|#include "(sd-[^"]*)"|#include <systemd/\1>|'
)

fixup_makefile() {
	sed -r \
	    -e '/^[^#	]*:/ { s|^(\s*)\S+/|\1$(outdir)/| }' \
	    -e 's|^if (.*)|ifneq ($(\1),)|' \
	    -e 's|rootprefix|prefix|g' \
	    -e 's|rootbin|bin|g' \
	    -e 's|rootlib|lib|g' \
	    -e 's|--version-script=.*/([^/]+)\.sym|--version-script=$(srcdir)/\1.sym|g'
}

fixup_makefiles() (
	sed -ri \
	    -e '/^	\$\(AM_V_at\)\$\(MKDIR_P\) \$\(dir \$@\)/d' \
	    -e 's/ \$\(CFLAGS\) / /g' \
	    -e 's/ \$\(CPPFLAGS\) / /g' \
	    -e 's/ \$\(AM_CPPFLAGS\) / $(ALL_CPPFLAGS) /g' \
	    -e '/^[^#	]*:/ { s|\S+/|$(outdir)/|g }' \
	    src/libbasic/Makefile \
	    src/libsystemd/libsystemd-journal-internal/Makefile \
	    src/udev/Makefile
	find -type f -name Makefile|while read -r filename; do
		sed -r -i "s|(/\.\.)*/config.mk|/$(realpath -ms --relative-to="${filename%/*}" config.mk)|" "$filename"
	done
)

move() (
	>&2 echo ' => move_files'
	move_files
	>&2 echo ' => breakup_makefile'
	breakup_makefile
	>&2 echo ' => fixup_includes'
	fixup_includes
	>&2 echo ' => fixup_makefiles'
	fixup_makefiles
)

main() {
	set -e

	if [[ -n "$(git status -s)" ]] || [[ -n "$(git clean -xdn)" ]]; then
		echo 'There are changes in the current directory.' >&2
		exit 1
	fi

	git checkout -b postmove

	move

	git add .
	git commit -m './move.sh'
	git merge -s ours lukeshu/postmove
	git checkout lukeshu/postmove
	git merge postmove
	git branch -d postmove
}

main "$@"