Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| #! /bin/sh | |
| # Just a little note, the files we're restoring normally come from a | |
| # Fat32 device, so make sure proper permissions are applied after a copy. | |
| PREREQ="" | |
| DESCRIPTION="Restoring kamikazi configuration from /isodevice/boot/config/ ..." | |
| prereqs() | |
| { | |
| echo "$PREREQ" | |
| } | |
| case $1 in | |
| # get pre-requisites | |
| prereqs) | |
| prereqs | |
| exit 0 | |
| ;; | |
| esac | |
| . /scripts/casper-functions | |
| log_begin_msg "$DESCRIPTION" | |
| _log_msg "\n\n\nKamikazi-restore: Welcome to Kamikazi\n\n" | |
| _log_msg "Kamikazi-restore: Searching for kernel module state to restore...\n" | |
| # Set up kernel modules very early if a file exists on isodevice. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -f /root/isodevice/boot/config/modules ]; then # we previously saved modules info. | |
| cp -f /root/isodevice/boot/config/modules /root/etc/modules | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/modules | |
| _log_msg "Kamikazi-restore: Restored kernel module state.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for DBUS machine-id to restore...\n" | |
| # Set the machine-id very early if a file exists on isodevice. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -f /root/isodevice/boot/config/machine-id ]; then # we previously saved a machine-id. | |
| cp -f /root/isodevice/boot/config/machine-id /root/var/lib/dbus/machine-id | |
| _log_msg "Kamikazi-restore: Restored DBUS machine-id.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for SSH Host Config to restore...\n" | |
| # Set the SSH Host config very early if they exist on isodevice. | |
| if [ -d /root/isodevice/boot/config/ssh ]; then # the ssh configuration folder exists. | |
| if [ -f /root/isodevice/boot/config/ssh/sshd_config ]; then # we previously saved configs. | |
| cp -f /root/isodevice/boot/config/ssh/sshd_config /root/etc/ssh/ # But we only want configs. | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/ssh/sshd_config | |
| _log_msg "Kamikazi-restore: Restored sshd_config state.\n" | |
| fi | |
| if [ -f /root/isodevice/boot/config/ssh/ssh_config ]; then # we previously saved host configs. | |
| cp -f /root/isodevice/boot/config/ssh/ssh_config /root/etc/ssh/ # But we only want configs. | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/ssh/ssh_config | |
| _log_msg "Kamikazi-restore: Restored ssh_config state.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for SSH Host Keys to restore...\n" | |
| # Set the SSH Host keys very early if they exist on isodevice. | |
| if [ -d /root/isodevice/boot/config/ssh ]; then # the ssh configuration folder exists. | |
| if [ -f /root/isodevice/boot/config/ssh/ssh_host_ecdsa_key ]; then # we previously saved host keys. | |
| cp -f /root/isodevice/boot/config/ssh/ssh_host_* /root/etc/ssh/ # But we only want host keys, not config. | |
| # Make sure the proper permissions are applied. | |
| chmod 0600 /root/etc/ssh/ssh_host_* | |
| chmod 0644 /root/etc/ssh/ssh_host_*.pub | |
| _log_msg "Kamikazi-restore: Restored SSH Host Keys.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for SSH Client Keys to restore...\n" | |
| # Restore the SSH Client keys very early if they exist on isodevice for git. | |
| if [ -d /root/isodevice/boot/config/keystore ]; then # the ssh client configuration folder exists. | |
| if [ -f /root/isodevice/boot/config/keystore/authorized_keys ]; then # we previously saved client keys. | |
| # Make sure the configuration directory actually exists. | |
| mkdir -p /root/etc/skel/.ssh/ | |
| # And root's too. | |
| mkdir -p /root/root/.ssh/ | |
| cp -f /root/isodevice/boot/config/keystore/* /root/etc/skel/.ssh/ # We'll take everything. | |
| cp -f /root/isodevice/boot/config/keystore/* /root/root/.ssh/ # For both root and generated users. | |
| # If root needs it's own authorized_keys, provide a root_keys, otherwise both will get the same. | |
| cp -f /root/isodevice/boot/config/keystore/root_keys /root/root/.ssh/authorized_keys # Root only pubkeys. | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/skel/.ssh/* | |
| chmod 0600 /root/etc/skel/.ssh/id_rsa | |
| chmod 0644 /root/root/.ssh/* | |
| chmod 0600 /root/root/.ssh/id_rsa | |
| _log_msg "Kamikazi-restore: Restored SSH Client Keys.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for hostname to restore...\n" | |
| # Set the hostname very early if a file exists on isodevice. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -f /root/isodevice/boot/config/hostname ]; then # we previously saved a host name. | |
| FROMFILE=$(cat /root/isodevice/boot/config/hostname) | |
| if [ "${FROMFILE}" != "${HOST}" ]; then | |
| HOST=${FROMFILE} | |
| _log_msg "Kamikazi-restore: Found hostname '${HOST}' to restore.\n" | |
| fi | |
| fi | |
| fi | |
| echo "$HOST" > /root/etc/hostname | |
| cat > /root/etc/hosts <<EOF | |
| 127.0.0.1 localhost | |
| 127.0.1.1 $HOST | |
| # The following lines are desirable for IPv6 capable hosts | |
| ::1 ip6-localhost ip6-loopback | |
| fe00::0 ip6-localnet | |
| ff00::0 ip6-mcastprefix | |
| ff02::1 ip6-allnodes | |
| ff02::2 ip6-allrouters | |
| ff02::3 ip6-allhosts | |
| # -- Kamikazi was here from casper-bottom/18kamikazi_restore | |
| EOF | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/hostname | |
| hostname "$HOST" | |
| _log_msg "Kamikazi-restore: Created hosts file and restored hostname ${HOST}.\n" | |
| _log_msg "Kamikazi-restore: Checking if WAN (br0) DHCP requests should be disabled...\n" | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -e /root/isodevice/boot/config/nodhcp ]; then # we don't want WAN dhcp | |
| touch /root/etc/kamikazi-core/nodhcp | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/kamikazi-core/nodhcp | |
| _log_msg "Kamikazi-restore: Disabled DHCP requests on WAN (br0).\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for DHCP configurations to restore...\n" | |
| # Copy over any openvswitch configuration. | |
| # The interfaces files should be available at approximately the same time we're copying this. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -d /root/isodevice/boot/config/dhcp ]; then # we previously saved ovsconfigs. | |
| # Overwrite the existing default configuration. | |
| cp -f /root/isodevice/boot/config/dhcp/* /root/etc/dhcp/ | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/dhcp/* | |
| _log_msg "Kamikazi-restore: Restored DHCP configuration.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for openvswitch configurations to restore...\n" | |
| # Copy over any openvswitch configuration. | |
| # The interfaces files should be available at approximately the same time we're copying this. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -d /root/isodevice/boot/config/openvswitch ]; then # we previously saved ovsconfigs. | |
| # Overwrite the existing default configuration. | |
| cp -f /root/isodevice/boot/config/openvswitch/* /root/etc/openvswitch/ | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/openvswitch/* | |
| _log_msg "Kamikazi-restore: Restored openvswitch configuration.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for ceph configurations to restore...\n" | |
| # Copy over any ceph configuration. | |
| # The interfaces files should be available at approximately the same time we're copying this. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -e /root/isodevice/boot/config/noceph ]; then # we don't want to start it at boot. | |
| touch /root/etc/kamikazi-core/noceph | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/kamikazi-core/noceph | |
| _log_msg "Kamikazi-restore: Disabled kamikazi-ceph, you must manually start ceph.\n" | |
| fi | |
| if [ -d /root/isodevice/boot/config/ceph ]; then # we previously saved cephconfigs. | |
| # Overwrite the existing default configuration. | |
| cp -f /root/isodevice/boot/config/ceph/* /root/etc/ceph/ | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/ceph/* | |
| _log_msg "Kamikazi-restore: Restored ceph configuration.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for samba configurations to restore...\n" | |
| # Copy over any samba configuration. | |
| # The interfaces files should be available at approximately the same time we're copying this. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -d /root/isodevice/boot/config/samba ]; then # we previously saved cephconfigs. | |
| # Overwrite the existing default configuration. | |
| cp -f /root/isodevice/boot/config/samba/* /root/etc/samba/ | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/samba/* | |
| _log_msg "Kamikazi-restore: Restored samba state.\n" | |
| fi | |
| fi | |
| MAKE_BRIDGE_CONFIG=true | |
| _log_msg "Kamikazi-restore: Searching for network interface configurations to restore...\n" | |
| # One of the pecularities of the FAT filesystem is a directory and a file can share the same name. | |
| # Simple advice: Don't. Pick one or the other -- 14.04+ will include interfaces.d if ip=frommedia | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| # If it's just a file, copy it over, removing interfaces.d from being imported by default. | |
| if [ -f /root/isodevice/boot/config/nics ]; then # we probably saved simple interfaces file. | |
| cp -f /root/isodevice/boot/config/nics /root/etc/network/interfaces | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/network/interfaces | |
| MAKE_BRIDGE_CONFIG=false | |
| _log_msg "Kamikazi-restore: Restored network interface file.\n" | |
| fi | |
| # If it's a directory named interfaces, just put the files in interfaces.d | |
| if [ -d /root/isodevice/boot/config/interfaces ]; then # we probably saved bridge configs. | |
| cp -f /root/isodevice/boot/config/interfaces/* /root/etc/network/interfaces.d/ | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/network/interfaces.d/* | |
| MAKE_BRIDGE_CONFIG=false | |
| _log_msg "Kamikazi-restore: Restored network interface directory.\n" | |
| fi | |
| fi | |
| if [ "$MAKE_BRIDGE_CONFIG" = true ]; then | |
| _log_msg "Kamikazi-restore: Network Configuration did not exist, making a default xenbr0 bridge.\n" | |
| IFFILE="/root/etc/network/interfaces.d/xenbr0" | |
| # First stuff a header in the file. | |
| cat >> "${IFFILE}" <<EOF | |
| # Virtual Machine bridge | |
| # | |
| # This is an example of a configuration with many biosdevname | |
| # physical network adapters added to the openvswitch bridge. | |
| # Spanning tree is enabled by default so it is harder to get in trouble. | |
| # | |
| # You should not use the 'auto' directive for openvswitch bridges. | |
| # Instead, 'service openvswitch-switch start-bridges' should be executed later in boot. | |
| allow-ovs xenbr0 | |
| iface xenbr0 inet manual | |
| ovs_type OVSBridge | |
| ovs_extra set Bridge xenbr0 stp_enable=true | |
| EOF | |
| # Now we need to make a list of the devices we've found. | |
| # Note, this only grabs interfaces that have a backing device. | |
| BRIDGE_PORTS="" | |
| for device in /sys/class/net/*/device; do # an iteration over the interfaces. | |
| name=$(basename ${device%*/device}) # Capture the name of the interface. | |
| BRIDGE_PORTS="${BRIDGE_PORTS} ${name}" | |
| done | |
| _log_msg "Kamikazi-restore: xenbr0: ${BRIDGE_PORTS}\n" | |
| cat >> "${IFFILE}" <<EOF | |
| ovs_ports ${BRIDGE_PORTS} | |
| EOF | |
| # Now we need to do it again, this time making an entry for each interface. | |
| for device in /sys/class/net/*/device; do # an iteration over the interfaces. | |
| name=$(basename ${device%*/device}) # Capture the name of the interface. | |
| _log_msg "Kamikazi-restore: Added ${name} to xenbr0\n" | |
| cat >> "${IFFILE}" <<EOF | |
| allow-xenbr0 ${name} | |
| iface ${name} inet manual | |
| ovs_bridge xenbr0 | |
| ovs_type OVSPort | |
| EOF | |
| done | |
| fi | |
| # If this stuff exists before 23networking runs, it will be used instead of generated. | |
| # If you actually want it to be generated anyway, remove ip=frommedia from the kernel cmdline. | |
| _log_msg "Kamikazi-restore: Searching for additional roles to restore...\n" | |
| # Copy over any role overrides. | |
| # kamikazi-boot-late will handle these far later in the boot process.. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -d /root/isodevice/boot/config/roles ]; then # we previously saved additional roles. | |
| # Overwrite the existing default configuration. | |
| cp -f /root/isodevice/boot/config/roles/* /root/home/git/kamikazi-core/resources/latest/config/roles/ | |
| # Make sure the proper permissions are applied. | |
| chmod 0755 /root/home/git/kamikazi-core/resources/latest/config/roles/* | |
| _log_msg "Kamikazi-restore: Restored additional roles.\n" | |
| fi | |
| fi | |
| # kamikazi-core will stash any local changes made to it's repo, pull, and pop the stash. | |
| _log_msg "Kamikazi-restore: Searching for a forced role to assume...\n" | |
| # If a forced role exists, copy it over.. | |
| # kamikazi-boot-late will handle this far later in the boot process.. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -e /root/isodevice/boot/config/role ]; then # we will force a specific role. | |
| # Make sure the configuration directory actually exists. | |
| mkdir -p /root/etc/kamikazi-core | |
| # Overwrite the existing default configuration. | |
| cp -f /root/isodevice/boot/config/role /root/etc/kamikazi-core/role | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/kamikazi-core/role | |
| _log_msg "Kamikazi-restore: Restored forced-role state.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for xen domains to restore...\n" | |
| # If a xendomains file or xenauto folder exists, copy it over.. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -e /root/isodevice/boot/config/xendomains ]; then # we will restore config. | |
| # Overwrite the existing default configuration. | |
| cp -f /root/isodevice/boot/config/xendomains /root/etc/default/xendomains | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/default/xendomains | |
| _log_msg "Kamikazi-restore: Restored xen domain configuration state.\n" | |
| fi | |
| if [ -d /root/isodevice/boot/config/xenauto ]; then # we will restore domains. | |
| # Make sure the configuration directory actually exists. | |
| mkdir -p /root/etc/xen/auto | |
| # In this case, there should be no default configuration. | |
| cp -f /root/isodevice/boot/config/xenauto/* /root/etc/xen/auto/ | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/xen/auto/* | |
| _log_msg "Kamikazi-restore: Restored xen autostart domains.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: Searching for GUI state to assume...\n" | |
| # If the GUI disable file exists, copy it over.. | |
| # kamikazi-boot-late will handle this far later in the boot process.. | |
| if [ -d /root/isodevice/boot/config ]; then # the general configuration folder exists. | |
| if [ -e /root/isodevice/boot/config/nogui ]; then # we will force a specific role. | |
| # Make sure the configuration directory actually exists. | |
| mkdir -p /root/etc/kamikazi-core | |
| # Overwrite the existing default configuration. | |
| cp -f /root/isodevice/boot/config/nogui /root/etc/kamikazi-core/nogui | |
| # Make sure the proper permissions are applied. | |
| chmod 0644 /root/etc/kamikazi-core/nogui | |
| _log_msg "Kamikazi-restore: Disabled GUI.\n" | |
| else | |
| _log_msg "Kamikazi-restore: Enabled GUI.\n" | |
| fi | |
| fi | |
| _log_msg "Kamikazi-restore: All configuration required for boot has been restored.\n" | |
| # Allow the messages on the screen to have a possiblity of being read. | |
| sleep 3; | |
| log_end_msg |