-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configuration management #17
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
996494b
Add configuration management
benhylau 40e590e
Fix config_save script
benhylau a5b7835
Fixes for configurations management
benhylau 4005cf3
Create empty conf.d in boot partition
benhylau 771280b
Group boot partition directory creations
benhylau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,4 +157,5 @@ $(DISK_IMAGE): $(BUILD)/mtoolsrc $(BOOT_FILES) | |
truncate --size=1025K [email protected] # ensure the FAT bootblock is mapped | ||
MTOOLSRC=$(BUILD)/mtoolsrc mformat -v boot -N 1 z: | ||
MTOOLSRC=$(BUILD)/mtoolsrc mcopy $(BOOT_FILES) z: | ||
MTOOLSRC=$(BUILD)/mtoolsrc mmd z:conf.d | ||
mv [email protected] $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,5 +101,5 @@ $(BUILD)/mtoolsrc: Makefile | |
$(DISK_IMAGE): $(SRC_SPL) $(BUILD)/mtoolsrc $(BOOT_FILES) $(BOOT_DTB_FILES) | ||
$(call allwinner_spl,$(SRC_SPL),[email protected]) | ||
truncate --size=1025K [email protected] # ensure the FAT bootblock is mapped | ||
$(call uboot_bootdir,$(BUILD)/mtoolsrc,z:,$$((0x100000/512)),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
$(call uboot_dirs,$(BUILD)/mtoolsrc,z:,$$((0x100000/512)),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
mv [email protected] $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,5 +104,5 @@ $(DISK_IMAGE): $(SRC_SPL) $(BUILD)/mtoolsrc $(BOOT_FILES) $(BOOT_DTB_FILES) env | |
$(call allwinner_spl,$(SRC_SPL),[email protected]) | ||
truncate --size=1025K [email protected] # ensure the FAT bootblock is mapped | ||
dd if=env [email protected] conv=notrunc bs=$$((0x088000)) seek=1 | ||
$(call uboot_bootdir,$(BUILD)/mtoolsrc,z:,$$((0x100000/512)),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
$(call uboot_dirs,$(BUILD)/mtoolsrc,z:,$$((0x100000/512)),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
mv [email protected] $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,6 @@ $(BUILD)/mtoolsrc: Makefile | |
$(DISK_IMAGE): $(SRC_SPL) $(BUILD)/mtoolsrc $(BOOT_FILES) $(BOOT_DTB_FILES) | ||
$(call allwinner_spl,$(SRC_SPL),[email protected]) | ||
truncate --size=1025K [email protected] # ensure the FAT bootblock is mapped | ||
$(call uboot_bootdir,$(BUILD)/mtoolsrc,z:,$$((0x100000/512)),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
$(call uboot_dirs,$(BUILD)/mtoolsrc,z:,$$((0x100000/512)),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
mv [email protected] $@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,7 +139,7 @@ $(BUILD)/mtoolsrc: Makefile | |
$(DISK_IMAGE): $(SRC_SPL) $(BUILD)/mtoolsrc $(BOOT_FILES) $(BOOT_DTB_FILES) $(BOOT_DTBO_FILES) | ||
$(call allwinner_spl,$(SRC_SPL),[email protected]) | ||
truncate --size=1025K [email protected] # ensure the FAT bootblock is mapped | ||
$(call uboot_bootdir,$(BUILD)/mtoolsrc,z:,$$((0x100000/512)),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
$(call uboot_dirs,$(BUILD)/mtoolsrc,z:,$$((0x100000/512)),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
MTOOLSRC=$(BUILD)/mtoolsrc mmd z:boot/dtb/overlay | ||
MTOOLSRC=$(BUILD)/mtoolsrc mcopy $(BOOT_DTBO_FILES) z:boot/dtb/overlay | ||
mv [email protected] $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ $(BUILD)/mtoolsrc: Makefile | |
$(DISK_IMAGE): $(SRC_SPL) $(BUILD)/mtoolsrc $(BOOT_FILES) $(BOOT_DTB_FILES) $(BUILD)/root.fs | ||
$(call allwinner_spl,$(SRC_SPL),[email protected]) | ||
truncate --size=1025K [email protected] # ensure the FAT bootblock is mapped | ||
$(call uboot_bootdir,$(BUILD)/mtoolsrc,z:,$(PART1_BEGIN_SEC),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
$(call uboot_dirs,$(BUILD)/mtoolsrc,z:,$(PART1_BEGIN_SEC),$(BOOT_FILES),$(BOOT_DTB_FILES)) | ||
MTOOLSRC=$(BUILD)/mtoolsrc mpartition -c -T0x82 -b $(PART2_BEGIN_SEC) y: | ||
MTOOLSRC=$(BUILD)/mtoolsrc mpartition -c -T0x83 -b $(PART3_BEGIN_SEC) x: | ||
truncate --size=$$(( $(PART3_BEGIN_SEC)*512 )) [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Apply configurations from conf.d | ||
# | ||
# Copyright (C) 2018 Benedict Lau <[email protected]> | ||
|
||
CONFDIR=conf.d | ||
|
||
try_partition() { | ||
# Create file system node from partition | ||
mknod /dev/$1 b $2 $3 2>/dev/null | ||
|
||
# Mount partition as read-only | ||
mount /dev/$1 /mnt -o ro | ||
|
||
# Find conf.d in root of partition and extract in alphabetical order each | ||
# tar.gz archive into the ramdisk /etc, overwriting any existing file | ||
if [ -d "/mnt/$CONFDIR" ]; then | ||
for conf in /mnt/$CONFDIR/*.tar.gz; do | ||
echo Applying configurations from /dev/$1: $conf | ||
tar --extract -f $conf -C /etc | ||
done | ||
fi | ||
|
||
# Unmount partition | ||
umount /mnt | ||
} | ||
|
||
# Mount proc | ||
mount -t proc proc /proc | ||
|
||
cat /proc/partitions | while read major minor size name; do | ||
# Check each partition matching sd*[0-9] (e.g. sda1) or mmcblk*p* (e.g. mmcblk0p1) | ||
case $name in | ||
sd*[0-9]|mmcblk*p*) | ||
echo Checking for configuration files on $name | ||
try_partition $name $major $minor | ||
;; | ||
esac | ||
done |
43 changes: 43 additions & 0 deletions
43
debian/packages.d/systemd.customise.add/usr/local/sbin/config_save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Save current configurations to partition containing conf.d | ||
# | ||
# Copyright (C) 2018 Benedict Lau <[email protected]> | ||
|
||
CONFDIR=conf.d | ||
|
||
try_partition() { | ||
retval=1 | ||
|
||
# Mount partition as read-write | ||
mount /dev/$1 /mnt | ||
|
||
# Find conf.d in root of partition and save current configurations in /etc | ||
if [ -d "/mnt/$CONFDIR" ]; then | ||
echo Saving configurations to /dev/$1: "/mnt/$CONFDIR/50-node-config-save.tar.gz" | ||
tar --create --gzip -f "/mnt/$CONFDIR/50-node-config-save.tar.gz" -C /etc . | ||
|
||
# Set function return value to successful | ||
echo Configurations saved to /dev/$1: "/mnt/$CONFDIR/50-node-config-save.tar.gz" | ||
retval=0 | ||
fi | ||
|
||
# Unmount partition | ||
umount /mnt | ||
|
||
return $retval | ||
} | ||
|
||
cat /proc/partitions | while read major minor size name; do | ||
# Check each partition matching sd*[0-9] (e.g. sda1) or mmcblk*p* (e.g. mmcblk0p1) | ||
case $name in | ||
sd*[0-9]|mmcblk*p*) | ||
echo Checking for configuration directory on $name | ||
try_partition $name $major $minor | ||
S=$? | ||
|
||
# Save only to the first partition found with conf.d | ||
if [ $S -eq 0 ]; then | ||
break | ||
fi | ||
;; | ||
esac | ||
done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hamishcoleman Break like this after first successful save?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable