summaryrefslogtreecommitdiff
path: root/tools/notsd-move
blob: 096c3d83389929173e63314270cbd7e81164fd21 (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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
#!/usr/bin/env bash

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

split_lib() (
	shopt -s nullglob
	local d=$1
	local t

	if t=("$d"/test-*) && [[ ${#t[@]} -gt 0 ]]; then
		mkdir "$d/test"
		mv -t "$d/test" -- "${t[@]}"
	fi

	if t=("$d"/*.c) && [[ ${#t[@]} -gt 0 ]]; then
		mkdir "$d/src"
		mv -t "$d/src" -- "${t[@]}"
	fi

	if t=("$d"/*.h) && [[ ${#t[@]} -gt 0 ]]; then
		local h=${d##*/lib}
		mkdir "$d/include"
		mkdir "$d/include/$h"
		mv -t "$d/include/$h" -- "${t[@]}"
	else
		return 1
	fi
)

grp() {
	local grp=$1
	shift
	if [[ -d "${grp}.d" ]]; then
		mv -T "${grp}.d" "$grp"
	else
		mkdir "$grp"
	fi
	mv "$@" -t "$grp"
}

move_files() (
	# first focus on getting directories to the right names.
	mv -T src/{,systemd-}debug-generator
	mv -T src/{,systemd-}fstab-generator
	mv -T src/{,systemd-}getty-generator
	mv -T src/{,systemd-}gpt-auto-generator
	mv -T src/{,systemd-}rc-local-generator
	mv -T src/{,systemd-}system-update-generator
	mv -T src/{,systemd-}sysv-generator

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

	mv src/udev/*_id      -t src
	mv src/udev/mtd_probe -t src
	mv src/udev/collect   -t src

	mv -T src/boot/efi src/systemd-boot
	mv -T src/boot     src/bootctl

	mkdir src/libsystemd/src
	mv -t src/libsystemd/src src/libsystemd/sd-*
	mkdir src/libsystemd/include
	mv -T src/systemd src/libsystemd/include/systemd

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

	mkdir src/systemd
	mv -t src/systemd \
	   src/core/main* \
	   src/core/*systemd* \
	   src/core/system.conf \
	   src/core/user.conf
	mkdir src/systemd-shutdown
	mv -t src/systemd-shutdown \
	   src/core/shutdown* \
	   src/core/umount*
	mv -T src/{,lib}core

	mv -T src/{,libsystemd-}basic
	mv -T src/{,libsystemd-}shared

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

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

	mkdir src/libsystemd-gcrypt
	mv -T src/libsystemd-{shared,gcrypt}/gcrypt-util.c
	mv -T src/libsystemd-{shared,gcrypt}/gcrypt-util.h

	mkdir src/libsystemd-blkid
	mv -T src/libsystemd-{basic,blkid}/blkid-util.h

	mkdir src/libsystemd-microhttpd
	mv -t src/libsystemd-microhttpd \
	   src/journal-remote/microhttpd*

	split_lib src/libcore
	split_lib src/libsystemd-basic
	split_lib src/libsystemd-shared
	split_lib src/libsystemd-network
	split_lib src/libsystemd-firewall
	split_lib src/libsystemd-gcrypt
	split_lib src/libsystemd-blkid
	split_lib src/libsystemd-microhttpd

	mv -t src/libcore/src \
	   src/libcore/linux \
	   src/libcore/include/core/dbus*.h
	mv -T src/libcore/{src,include/core}/dbus-manager.h
	mv -T src/libcore/{include/core,src}/audit-fd.h
	mv -T src/libcore/{include/core,src}/load-dropin.h
	mv -T src/libcore/{include/core,src}/locale-setup.h
	mv -T src/libcore/{include/core,src}/selinux-access.h
	mv -T src/libcore/{include/core,src}/transaction.h
	mv -T src/libcore/{include/core,src}/unit-printf.h
	mv -T src/libcore/{,src}/load-fragment-gperf.gperf.m4

	mv src/libsystemd-shared/{test,include/systemd-shared}/test-tables.h
	rmdir src/libsystemd-shared/test

	mkdir src/systemd-hibernate-resume-generator
	mv -t src/systemd-hibernate-resume-generator \
	   src/systemd-hibernate-resume/*generator*

	# src/resolve => src/{libbasic-dns,resolve,resolved}
	mkdir src/libbasic-dns
	mv -t src/libbasic-dns \
	   src/resolve/dns-type.{c,h} \
	   src/resolve/resolved-dns-{answer,dnssec,packet,question,rr}.{c,h} \
	   src/resolve/test-*
	mkdir src/systemd-resolve
	mv -t src/systemd-resolve \
	   src/resolve/resolve-tool.c
	mkdir src/systemd-resolved
	mv -t src/systemd-resolved \
	   src/resolve/.gitignore \
	   src/resolve/*
	rmdir src/resolve
	split_lib src/libbasic-dns

	# src/import => src/{libimport,systemd-{export,importd,import}}
	mkdir src/libimport
	mv -t src/libimport \
	   src/import/import-common.{c,h} \
	   src/import/import-compress.{c,h} \
	   src/import/qcow2-util.{c,h} \
	   src/import/test-qcow2.c
	mkdir src/systemd-export
	mv -t src/systemd-export \
	   src/import/export*
	mkdir src/systemd-importd
	mv -t src/systemd-importd \
	   src/import/.gitignore \
	   src/import/importd.c \
	   src/import/org.*
	mkdir src/systemd-import
	mv -t src/systemd-import \
	   src/import/import*
	mkdir src/systemd-pull
	mv -t src/systemd-pull \
	   src/import/pull* \
	   src/import/curl-util*
	rmdir src/import

	# src/journal => src/...
	mkdir src/libjournal-core
	mv -t src/libjournal-core \
	   src/journal/.gitignore \
	   src/journal/journald-* \
	   src/journal/test-*
	mkdir src/systemd-cat
	mv -t src/systemd-cat \
	   src/journal/cat.c
	mkdir src/journalctl
	mv -t src/journalctl \
	   src/journal/journal-qrcode.{c,h} \
	   src/journal/journalctl.c
	mkdir src/systemd-journald
	mv -t src/systemd-journald \
	   src/journal/journald.*
	mkdir src/libsystemd/src/sd-journal
	mv -t src/libsystemd/src/sd-journal \
	   src/journal/audit-type.c \
	   src/journal/audit-type.h \
	   src/journal/catalog.c \
	   src/journal/catalog.h \
	   src/journal/compress.c \
	   src/journal/compress.h \
	   src/journal/fsprg.c \
	   src/journal/fsprg.h \
	   src/journal/journal-authenticate.c \
	   src/journal/journal-authenticate.h \
	   src/journal/journal-def.h \
	   src/journal/journal-file.c \
	   src/journal/journal-file.h \
	   src/journal/journal-internal.h \
	   src/journal/journal-send.c \
	   src/journal/journal-vacuum.c \
	   src/journal/journal-vacuum.h \
	   src/journal/journal-verify.c \
	   src/journal/journal-verify.h \
	   src/journal/lookup3.c \
	   src/journal/lookup3.h \
	   src/journal/mmap-cache.c \
	   src/journal/mmap-cache.h \
	   src/journal/sd-journal.c
	rmdir src/journal
	split_lib src/libjournal-core
	mv -T src/libjournal-core/{,src/}journald-gperf.gperf

	# src/network => src/...
	mkdir src/systemd-networkd-wait-online
	mv -t src/systemd-networkd-wait-online \
	   src/network/networkd-wait-online*
	mkdir src/libnetworkd-core
	mv -t src/libnetworkd-core \
	   src/network/.gitignore \
	   src/network/networkd-*
	mkdir src/networkctl
	mv -t src/networkctl \
	   src/network/networkctl.c
	mkdir src/systemd-networkd
	mv -t src/systemd-networkd \
	   src/network/networkd* \
	   src/network/org.*
	mkdir src/grp-network.d
	mv -t src/grp-network.d \
	   src/network/test-*
	rmdir src/network

	# src/machine => src/{machinectl,systemd-machined,libmachine-core}
	mkdir src/machinectl src/systemd-machined src/libmachine-core
	mv -T src/{machine,machinectl}/machinectl.c
	mv -T src/{machine,systemd-machined}/machined.c
	mv -t src/systemd-machined \
	   src/machine/.gitignore \
	   src/machine/org.*
	mv -t src/libmachine-core \
	   src/machine/*
	rmdir src/machine
	split_lib src/libmachine-core

	# src/coredump => src/{coredumpctl,systemd-coredump}
	mkdir src/coredumpctl
	mv -t src/coredumpctl \
	   src/coredump/coredumpctl*
	mkdir src/systemd-coredump
	mv -t src/systemd-coredump \
	   src/coredump/*
	rmdir src/coredump

	# src/hostname => src/{hostnamectl,systemd-hostnamed}
	mkdir src/hostnamectl
	mv -t src/hostnamectl \
	   src/hostname/hostnamectl*
	mkdir src/systemd-hostnamed
	mv -t src/systemd-hostnamed \
	   src/hostname/.gitignore \
	   src/hostname/*
	rmdir src/hostname

	# src/journal-remote => src/...
	mkdir src/systemd-journal-gatewayd
	mv -t src/systemd-journal-gatewayd \
	   src/journal-remote/journal-gateway*
	mkdir src/systemd-journal-remote
	mv -t src/systemd-journal-remote \
	   src/journal-remote/journal-remote*
	mkdir src/systemd-journal-upload
	mv -t src/systemd-journal-upload \
	   src/journal-remote/journal-upload*
	mkdir src/grp-remote.d
	mv -t src/grp-remote.d \
	   src/journal-remote/.gitignore \
	   src/journal-remote/browse.html \
	   src/journal-remote/log-generator.py
	rmdir src/journal-remote

	# src/locale => src/...
	mkdir src/localectl
	mv -t src/localectl \
	   src/locale/localectl*
	mkdir src/systemd-localed
	mv -t src/systemd-localed \
	   src/locale/.gitignore \
	   src/locale/*
	rmdir src/locale

	# src/login => src/...
	mkdir src/grp-login.d
	mv -t src/grp-login.d \
	   src/login/.gitignore \
	   src/login/test-*
	mkdir src/loginctl
	mv -t src/loginctl \
	   src/login/loginctl* \
	   src/login/sysfs-show*
	mkdir src/pam_systemd
	mv -t src/pam_systemd \
	   src/login/pam*
	mkdir src/systemd-inhibit
	mv -t src/systemd-inhibit \
	   src/login/inhibit*
	mkdir src/systemd-logind
	mv -t src/systemd-logind \
	   src/login/logind* \
	   src/login/*.rules \
	   src/login/*.rules.in \
	   src/login/org.*
	mv -T src/login/systemd-user.m4 src/systemd-logind/systemd-user.pam.m4
	rmdir src/login

	# src/timedate => src/...
	mkdir src/timedatectl
	mv -t src/timedatectl \
	   src/timedate/timedatectl*
	mkdir src/systemd-timedated
	mv -t src/systemd-timedated \
	   src/timedate/.gitignore \
	   src/timedate/timedated* \
	   src/timedate/org.*
	rmdir src/timedate

	# src/udev => src/...
	mv -T src/udev/udev.h src/libudev/udev.h
	mkdir src/udevadm
	mv -t src/udevadm \
	   src/udev/udevadm*
	mkdir src/libudev-core
	mv -t src/libudev-core \
	   src/udev/net \
	   src/udev/udev-*
	mkdir src/systemd-udevd
	mv -t src/systemd-udevd \
	   src/udev/udev.conf* \
	   src/udev/udevd*
	mkdir src/grp-udev.d
	mv -t src/grp-udev.d \
	   src/udev/.gitignore \
	   src/udev/udev.*
	rm src/udev/.vimrc
	rmdir src/udev

	# .conf is such a useless suffix
	for ext in sysctl sysusers tmpfiles; do
		for file in $ext.d/*.conf*; do
			mv -T "$file" "${file/.conf/.$ext}"
		done
	done
	for ext in xorg; do
		for file in $ext/*.sh*; do
			mv -T "$file" "${file/.sh/.$ext}"
		done
	done

	# less obvious manpage groups
	mv -T man/{glib-event-glue,sd_event_get_fd-glib-example}.c
	mv -T man/systemd-{halt.service,shutdown}.xml
	mv -T man/systemd-{suspend.service,sleep}.xml
	mv -t src/libsystemd \
	   man/libsystemd* \
	   man/sd*
	mv -t src/libudev \
	   man/udev_*
	mkdir src/manpages
	mv -t src/manpages \
	   man/daemon.xml \
	   man/file-hierarchy.xml \
	   man/hostname.xml \
	   man/locale.conf.xml \
	   man/localtime.xml \
	   man/machine-id.xml \
	   man/machine-info.xml \
	   man/os-release.xml
	mv -t src/systemctl \
	   man/halt.xml \
	   man/runlevel.xml \
	   man/shutdown.xml \
	   man/telinit.xml \
	   man/systemd.preset.xml
	mv -t src/systemd \
	   man/systemd-system.conf.xml
	mkdir src/grp-system.d
	mv -t src/grp-system.d \
	   man/bootup.xml \
	   man/kernel-command-line.xml
	mv -t src/systemd-udevd \
	   man/udev.conf.xml
	mv -t src/grp-udev.d \
	   man/udev.xml
	mv -t src/systemd-cryptsetup \
	   man/*crypt*
	mv -t src/systemd-machine-id-setup \
	   man/systemd-machine-id*
	mv -t src/systemd-path src/libsystemd/include/systemd/sd-path*
	mv -t src/systemd-path src/libsystemd/src/sd-path/*
	rmdir src/libsystemd/src/sd-path
	mv -t src/systemd-resolved \
	   man/dnssec-trust-anchors*
	mv -t src/systemd-tty-ask-password-agent \
	   man/systemd-ask-password-console*

	# less obvious unit groups
	# suffix these with '*' in case they gain or lose the .in suffix.
	for thing in hibernate hybrid-sleep suspend; do
		mv -t src/systemd-sleep \
		   units/"$thing".target* \
		   units/systemd-"$thing".service*
	done
	for thing in halt kexec poweroff reboot; do
		mv -t src/systemd-shutdown \
		   units/"$thing".target* \
		   units/systemd-"$thing".service*
	done
	mv -t src/systemd-binfmt \
	   units/*binfmt*
	mv -t src/systemd-modules-load \
	   units/kmod*
	mv -t src/systemd-quotacheck \
	   units/quota*
	mv -t src/systemd-journald \
	   units/*journald*
	mv -t src/systemd-cryptsetup \
	   units/cryptsetup*
	mv -t src/systemd-logind \
	   units/user.slice*
	mv -t src/systemd-machined \
	   units/machine.slice*

	# muck
	mv -t src/libsystemd-basic/src src/libsystemd-basic/.gitignore
	mv -T {test,src/systemd-boot}/test-efi-create-disk.sh
	mv -t src/systemd-tmpfiles units/systemd-tmpfiles*
	mv -t src/systemd-tmpfiles \
	   tmpfiles.d/tmp.* \
	   tmpfiles.d/var.* \
	   tmpfiles.d/etc.* \
	   tmpfiles.d/home.* \
	   tmpfiles.d/*nologin* \
	   tmpfiles.d/legacy.* \
	   tmpfiles.d/x11.*
	mv -t src/systemd-sysusers \
	   sysusers.d/.gitignore \
	   sysusers.d/basic*
	mkdir src/libudev/src
	mv -t src/libudev/src src/libudev/*.{c,h}
	mkdir src/libudev/include
	mv -T src/libudev/{src,include}/libudev.h
	mv -T src/{systemd-networkd,libnetworkd-core}/networkd.h
	mv -T src/{systemd-resolved,libbasic-dns/include/basic-dns}/resolved-def.h
	mv -t src/cdrom_id  rules/*cdrom*
	mv -t src/mtd_probe rules/*mtd*
	mv -t src/v4l_id    rules/*v4l*
	mv -t src/libsystemd-network/include/systemd-network \
	   src/libsystemd/include/systemd/sd-dhcp* \
	   src/libsystemd/include/systemd/sd-ipv4* \
	   src/libsystemd/include/systemd/sd-lldp* \
	   src/libsystemd/include/systemd/sd-ndisc*
	mkdir src/libsystemd/include-staging{,/systemd-staging}
	mv -t src/libsystemd/include-staging/systemd-staging \
	   src/libsystemd/include/systemd/sd-{device,hwdb,netlink,network,resolve}.h

	mkdir src/grp-journal.d
	mv -t src/grp-journal.d tmpfiles.d/journal-nocow.*
	mv -t src/grp-remote.d tmpfiles.d/systemd-remote.*
	mv -t src/systemd tmpfiles.d/systemd-tmpfs.tmpfiles*
	mv -t src/systemd xorg/??-systemd-user.*; rmdir xorg
	mv -t src/systemd-vconsole-setup man/vconsole.conf.xml
	mv -t src/systemd-coredump \
	   sysctl.d/*coredump*
	mv -t src/systemd-sysctl \
	   sysctl.d/??-default.*

	mv -t src/systemd-sysv-generator \
	   docs/sysvinit/.gitignore \
	   docs/sysvinit/*
	rmdir docs/sysvinit
	mv -t src/grp-journal.d \
	   docs/var-log/.gitignore \
	   docs/var-log/*
	rmdir docs/var-log
	rm docs/.gitignore
	rmdir docs

	# auto-distribute the stuff
	for d in man units sysusers.d tmpfiles.d; do
		pushd $d >/dev/null
		for file in *; do
			base=${file%%.*}
			base=${base%%@*}
			if [[ -d ../src/"${base}" ]]; then
				mv "$file" -t ../src/"${base}"
			elif [[ -d ../src/"${base#systemd-}" ]]; then
				mv "$file" -t ../src/"${base#systemd-}"
			elif [[ -d ../src/systemd-"${base}" ]]; then
				mv "$file" -t ../src/systemd-"${base}"
			fi
		done
		popd >/dev/null
	done
	rmdir sysusers.d #tmpfiles.d

	pushd shell-completion/bash >/dev/null
	mv -T  systemctl.in ../../src/systemctl/systemctl.completion.bash.in
	cat .gitignore   >> ../../src/systemctl/.gitignore
	rm .gitignore
	for file in *; do
		if [[ -d ../../src/"$file" ]]; then
			mv -T "$file" "../../src/$file/$file.completion.bash"
		fi
	done
	popd >/dev/null
	rmdir shell-completion/bash

	pushd shell-completion/zsh >/dev/null
	mv -T _systemctl.in ../../src/systemctl/systemctl.completion.zsh.in
	cat .gitignore   >> ../../src/systemctl/.gitignore
	rm .gitignore
	for file in _*; do
		if [[ -d ../../src/"${file#_}" ]]; then
			mv -T "$file" "../../src/${file#_}/${file#_}.completion.zsh"
		fi
	done
	popd >/dev/null
	mv -T shell-completion/zsh src/zsh-completion
	rmdir shell-completion

	# do this *after* auto-splitting, because of
	# systemd-journal-{gatewayd,remote,upload}.
	mv -t src/journalctl \
	   units/*journal*
	# fix a false positive
	mv -t units \
	   src/systemd-shutdown/shutdown.target

	# categorize
	grp src/grp-boot \
	    src/bootctl \
	    src/kernel-install \
	    src/systemd-boot
	grp src/grp-coredump \
	    src/coredumpctl \
	    src/systemd-coredump
	grp src/grp-hostname \
	    src/hostnamectl \
	    src/systemd-hostnamed
	grp src/grp-initprogs \
	    src/systemd-backlight \
	    src/systemd-binfmt \
	    src/systemd-detect-virt \
	    src/systemd-firstboot \
	    src/systemd-fsck \
	    src/systemd-modules-load \
	    src/systemd-quotacheck \
	    src/systemd-random-seed \
	    src/systemd-rfkill \
	    src/systemd-sysctl \
	    src/systemd-sysusers \
	    src/systemd-tmpfiles \
	    src/systemd-update-done \
	    src/systemd-update-utmp \
	    src/systemd-user-sessions \
	    src/systemd-vconsole-setup
	grp src/grp-initprogs/grp-sleep \
	    src/systemd-hibernate-resume \
	    src/systemd-hibernate-resume-generator \
	    src/systemd-sleep
	grp src/grp-remote \
	    src/libsystemd-microhttpd \
	    src/systemd-journal-gatewayd \
	    src/systemd-journal-remote \
	    src/systemd-journal-upload
	grp src/grp-journal \
	    catalog \
	    src/grp-remote \
	    src/journalctl \
	    src/libjournal-core \
	    src/systemd-cat \
	    src/systemd-journald
	grp src/grp-locale \
	    src/localectl \
	    src/systemd-localed
	grp src/grp-login \
	    src/loginctl \
	    src/pam_systemd \
	    src/systemd-inhibit \
	    src/systemd-logind
	grp src/grp-machine \
	    src/libmachine-core \
	    src/machinectl \
	    src/nss-mymachines \
	    src/systemd-machined
	grp src/grp-machine/grp-import \
	    src/libimport \
	    src/systemd-export \
	    src/systemd-import \
	    src/systemd-importd \
	    src/systemd-pull
	grp src/grp-network \
	    network \
	    src/libnetworkd-core \
	    src/networkctl \
	    src/systemd-networkd \
	    src/systemd-networkd-wait-online
	grp src/grp-resolve \
	    src/libbasic-dns \
	    src/nss-resolve \
	    src/systemd-resolve \
	    src/systemd-resolved
	grp src/grp-system \
	    src/libcore \
	    src/systemctl \
	    src/systemd \
	    src/systemd-shutdown
	grp src/grp-system/grp-utils \
	    src/systemd-analyze \
	    src/systemd-delta \
	    src/systemd-fstab-generator \
	    src/systemd-run \
	    src/systemd-sysv-generator
	grp src/grp-timedate \
	    src/systemd-timedated \
	    src/timedatectl
	grp src/grp-udev \
	    rules \
	    hwdb \
	    src/libudev-core \
	    src/*_id \
	    src/collect \
	    src/mtd_probe \
	    src/systemd-hwdb \
	    src/systemd-udevd \
	    src/udevadm
	grp src/grp-utils \
	    src/systemd-ac-power \
	    src/systemd-escape \
	    src/systemd-notify \
	    src/systemd-path \
	    src/systemd-socket-activate

	mv -t src/grp-udev \
	   src/grp-udev/rules/*
	cat src/grp-udev/rules/.gitignore >> src/grp-udev/.gitignore
	rm src/grp-udev/rules/.gitignore
	rmdir src/grp-udev/rules

	mv -t src/grp-journal/systemd-journald \
	   src/grp-journal/catalog/.gitignore \
	   src/grp-journal/catalog/*
	rmdir src/grp-journal/catalog

	mv -t src/systemd-timesyncd system-preset/??-timesyncd.preset
	for file in system-preset/??-*.preset; do
		base="${file##*/??-}"
		base="${base%.preset}"
		base="${base%d}"
		mv -t src/grp-"$base" "$file"
	done
	rmdir system-preset

	mv -t src/libsystemd/src/sd-bus \
	   src/libsystemd-shared/src/bus-util.c \
	   src/libsystemd-shared/include/systemd-shared/bus-util.h

	ln -srT src/libsystemd/include/systemd/_sd-common.h src/libsystemd-network/include/systemd-network/_sd-common.h
	ln -srT src/libsystemd/include/systemd/_sd-common.h src/grp-utils/systemd-path/_sd-common.h
	ln -srT src/grp-login/systemd-logind/logind-acl.h   src/grp-udev/libudev-core/logind-acl.h
	ln -srT src/grp-login/systemd-logind/logind-acl.c   src/grp-udev/libudev-core/logind-acl.c
	ln -srT src/libsystemd/src/sd-login/sd-login.c      src/grp-udev/libudev-core/sd-login.c
)

breakup_makefile() (
	mkdir -p build-aux/Makefile.{once,each}.{head,tail}

	touch .tmp.move.all
	files=(.tmp.move.all)
	file=/dev/null
	IFS=''
	declare -i i=0
	trap 'printf "Makefile.am:%d:%s\n" $i "$line"' EXIT
	while read -r line; do
		i+=1
		if [[ $line = '#@'* ]]; then
			file="${line#'#@'}"
			file="${file%% *}"
			if [[ $file = auto/* ]]; then
				IFS=/
				read -r auto dir makefile <<<"$file"
				IFS=''
				[[ $auto = auto ]]
				[[ $makefile = Makefile ]]
				d="$(find src -type d -name "$dir")"
				[[ -n "$d" ]]
				[[ "$(wc -l <<<"$d")" = 1 ]]
				file="$d/Makefile"
			fi
			if [[ "$file" != all ]] && ! in_array "$file" "${files[@]}"; then
				cat .tmp.move.all > "$file"
				files+=("$file")
			fi
		elif [[ $file = all ]]; then
			printf '%s\n' "$line" | tee -a "${files[@]}" >/dev/null
		else
			printf '%s\n' "$line" >> "$file"
		fi
	done < <(fixup_makefile <Makefile.am)
	trap -- EXIT
	rm .tmp.move.all

	sed -ri \
	    -e '/^[^#	]*:/ { s|\S+/|$(outdir)/|g }' \
	    src/libsystemd-basic/src/Makefile \
	    src/libsystemd/src/Makefile \
	    src/libsystemd/src/sd-journal/Makefile \
	    src/grp-udev/libudev-core/Makefile

	ln -sT ../subdir.mk src/libsystemd/src/sd-network/Makefile
	ln -sT ../subdir.mk src/libsystemd/src/sd-event/Makefile
	ln -sT ../subdir.mk src/libsystemd/src/sd-login/Makefile
	ln -sT ../subdir.mk src/libsystemd/src/sd-resolve/Makefile
	ln -sT ../subdir.mk src/libsystemd/src/sd-daemon/Makefile
	ln -sT ../subdir.mk src/libsystemd/src/sd-netlink/Makefile
	ln -sT ../subdir.mk src/libsystemd/src/sd-id128/Makefile
	ln -sT ../subdir.mk src/libsystemd/src/sd-device/Makefile
)

fixup_makefile() {
	sed -r \
	    -e '#### Specific complete strings #####' \
	    -e 's|\$\(CPP\) \$\(CFLAGS\) \$\(AM_CPPFLAGS\) \$\(CPPFLAGS\)|$(CPP) $(sd.ALL_CPPFLAGS)|g' \
	    -e '/^	\$\(AM_V_at\)\$\(MKDIR_P\) \$\(dir \$@\)/d' \
	    \
	    -e '#### General cases #################' \
	    -e '/^[^#	]*:/ { s|^(\s*)\S+/|\1$(outdir)/| }' \
	    -e 's|^if (.*)|ifneq ($(\1),)|' \
	    -e '/^\s*\$\(AM_(C|CPP|LD)FLAGS\b/d' \
	    -e 's|--version-script=.*/([^/]+)\.sym|--version-script=$(srcdir)/\1.sym|g' \
	    -e 's|\$\((lib\S+)_la_LIBADD\)|\1.la|g' \
	    \
	    -e '#### Rename helpers ################' \
	    -e 's|libbasic_la|libsystemd_basic_la|g' \
	    -e 's|libbasic|libsystemd-basic|g' \
	    -e 's|libsystemd-basic-dns|libbasic-dns|g' \
	    \
	    -e 's|libshared_la|libsystemd_shared_la|g' \
	    -e 's|libshared|libsystemd-shared|g' \
	    \
	    -e 's|libfirewall_la|libsystemd_firewall_la|g' \
	    -e 's|libfirewall|libsystemd-firewall|g'
}

breakup_zshcompletion() (
	sed_expr='
		1 {
			i #compdef %s
			d
		}
		/^case/,/^esac/ {
			/^    %s)/,/^    ;;/ {
				s/^        //p
			}
			d
		}
	'

	cd shell-completion/zsh
	read -r _ cmds < _systemd
	for cmd in $cmds; do
		printf -v cmd_sed_expr "$sed_expr" $cmd $cmd
		sed -e "$cmd_sed_expr" < _systemd > _$cmd
	done
	rm _systemd
)

run() (
	local tmp
	tmp="$(mktemp --tmpdir)"
	trap 'rm -f -- "$tmp"' EXIT
	"$0" "$@" |& tail -n20 > "$tmp" || { r=$?; cat "$tmp"; return $r; }
	return 0
)

move() (
	find . \( -name Makefile -o -name '*.mk' \) -delete
	find src -type d -empty -exec rmdir -p --ignore-fail-on-non-empty -- {} +

	>&2 echo ' => breakup_zshcompletion'
	run breakup_zshcompletion
	>&2 echo ' => move_files'
	run move_files
	>&2 echo ' => breakup_makefile'
	run breakup_makefile
	>&2 echo ' => ./tools/notsd-fixup'
	./tools/notsd-fixup
)

main() {
	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 tmp/postmove

	move

	git add .
	git commit -m './tools/notsd-move'
	git merge --no-edit -s ours notsystemd/postmove
	git checkout notsystemd/postmove
	git merge tmp/postmove
	git branch -d tmp/postmove
}

set -e
set -o pipefail
if [[ $# -gt 0 ]]; then
	set -x;
else
	set -- main
fi
"$@"