Skip to content
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

v2.1 interfaces migration #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tp2bmc/board/tp2bmc/overlay/sbin/preinit
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
#!/bin/sh

USER_INTERFACES="/mnt/overlay/upper/etc/network/interfaces"

log() {
echo "PREINIT: $*"
}

# user_defined_old_interface_config
#
# Checks if the user has configured an interfaces file for fw < v2.1.
# Requires the overlay filesystem to be mounted.
#
user_defined_old_interface_config() {
if [ ! -f "$USER_INTERFACES" ]; then
# No user override
return 1
fi

local is_new
local has_eth0

grep -qE "node[1-4]|ge[01]" "$USER_INTERFACES" && is_new=1 || is_new=0
grep -qE "^[^#]*eth0" "$USER_INTERFACES" && has_eth0=1 || has_eth0=0

if [ "$is_new" -eq 0 ] || [ "$has_eth0" -eq 1 ]; then
return 0
else
return 1
fi
}

migrate_interfaces_v2_1() {
if user_defined_old_interface_config; then
mv "$USER_INTERFACES" "${USER_INTERFACES}_bak"
# Add a comment block at the top of the new file
sed -i '1i# This file was automatically updated by a migration script\n#\
The original /etc/network/interfaces file is renamed to `interfaces_bak`.\n#\
From v2.1 onwards, eth0 is deprecated and configuration needs to be applied to interface br0 instead.\n#' "/etc/network/interfaces"
log migrated interfaces file
fi
}

#
# is_safemode
#
Expand Down Expand Up @@ -71,8 +108,11 @@ preinit() {

pivot_overlay $OVERLAY

migrate_interfaces_v2_1

log Beginning init
exec /sbin/init
}


preinit
Loading