From d10c96c3f870b84833904d95080fbc05f4e52235 Mon Sep 17 00:00:00 2001 From: xiaodongwang Date: Fri, 3 Apr 2015 18:55:37 -0700 Subject: [PATCH] do not quit when ssh key file not exists Change-Id: I1c0eab5d52656b4560527c89eaeb56696090ed38 --- cobbler/kickstarts/default.seed | 3 ++ .../snippets/kickstart_post_partition_disks | 2 +- cobbler/snippets/kickstart_ssh | 36 +++++++++++------- cobbler/snippets/preseed_apt_repo_config | 4 +- cobbler/snippets/preseed_partition_disks | 2 + cobbler/snippets/preseed_ssh | 37 +++++++++++------- cobbler/snippets/ssh.xml | 38 ++++++++++++------- cobbler/snippets/suse_pre_partition_disks | 33 ++++++++-------- 8 files changed, 97 insertions(+), 58 deletions(-) diff --git a/cobbler/kickstarts/default.seed b/cobbler/kickstarts/default.seed index 8562a4e..7461f83 100644 --- a/cobbler/kickstarts/default.seed +++ b/cobbler/kickstarts/default.seed @@ -56,6 +56,9 @@ d-i mirror/country string manual d-i mirror/http/hostname string $http_server d-i mirror/http/directory string $install_source_directory d-i mirror/http/proxy string +d-i mirror/http/mirror select $http_server +d-i mirror/protocol select http +d-i mirror/udeb/components multiselect main, restricted #set $os_v = $getVar('os_version','') #if $os_v and $os_v.lower()[0] > 'p' diff --git a/cobbler/snippets/kickstart_post_partition_disks b/cobbler/snippets/kickstart_post_partition_disks index eeddac7..ded9e96 100644 --- a/cobbler/snippets/kickstart_post_partition_disks +++ b/cobbler/snippets/kickstart_post_partition_disks @@ -29,5 +29,5 @@ for remove_partition in \${remove_partitions}; do if [ -z "\${partition_disk}" -o -z "\${partition_number}" ]; then continue fi - parted \${partition_disk} rm \${partition_number} + parted \${partition_disk} --script -- rm \${partition_number} done diff --git a/cobbler/snippets/kickstart_ssh b/cobbler/snippets/kickstart_ssh index 54d62f9..9900294 100644 --- a/cobbler/snippets/kickstart_ssh +++ b/cobbler/snippets/kickstart_ssh @@ -1,24 +1,34 @@ #set ssh_keys = $getVar("push_ssh_keys", "/root/.ssh/id_rsa.pub") #if $ssh_keys != "" -mkdir -p /root/.ssh -chmod 700 -R /root/.ssh + #set user_name = $getVar("username", "root") + #if $user_name == "root" + #set home = "/root" + #else + #set home = "/home/%s" % $user_name + #end if +mkdir -p $home/.ssh +chmod 700 -R $home/.ssh #set $firstline = True #for $ssh_key in $ssh_keys.split(',') #if not $ssh_key #continue #end if - #set f = $open($ssh_key) - #if $firstline -cat << EOL > /root/.ssh/authorized_keys - #echo $f.read() + #try + #set f = $open($ssh_key) + #if $firstline +cat << EOL > $home/.ssh/authorized_keys + #echo $f.read() EOL - #else -cat << EOL >> /root/.ssh/authorized_keys - #echo $f.read() + #else +cat << EOL >> $home/.ssh/authorized_keys + #echo $f.read() EOL - #end if - #silent $f.close() - #set $firstline = False + #end if + #set $firstline = False + #silent $f.close() + #except +# failed to read from $ssh_key + #end try #end for -chmod 600 /root/.ssh/authorized_keys +chmod 600 $home/.ssh/authorized_keys #end if diff --git a/cobbler/snippets/preseed_apt_repo_config b/cobbler/snippets/preseed_apt_repo_config index f86347c..bbc4cee 100644 --- a/cobbler/snippets/preseed_apt_repo_config +++ b/cobbler/snippets/preseed_apt_repo_config @@ -1,6 +1,8 @@ # Uncomment this if you don't want to use a network mirror d-i apt-setup/use_mirror boolean false - +d-i apt-setup/services-select multiselect +d-i apt-setup/security_host string $http_server +d-i apt-setup/security_path string $install_source_directory # Additional repositories, local[0-9] available #set $cur=0 #set $repo_data = $getVar("repo_data",[]) diff --git a/cobbler/snippets/preseed_partition_disks b/cobbler/snippets/preseed_partition_disks index 8b33a7f..e3b20bf 100644 --- a/cobbler/snippets/preseed_partition_disks +++ b/cobbler/snippets/preseed_partition_disks @@ -19,3 +19,5 @@ d-i partman/choose_partition select Finish partitioning and write changes to dis d-i mdadm/boot_degraded boolean true d-i partman-auto-lvm/no_boot boolean true d-i partman-basicfilesystems/no_mount_point false +d-i partman/filter_mounted boolean false +d-i partman/unmount_active boolean false diff --git a/cobbler/snippets/preseed_ssh b/cobbler/snippets/preseed_ssh index 4a49006..1a4ff39 100644 --- a/cobbler/snippets/preseed_ssh +++ b/cobbler/snippets/preseed_ssh @@ -1,25 +1,36 @@ sed -i 's/PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config #set ssh_keys = $getVar("push_ssh_keys", "/root/.ssh/id_rsa.pub") #if $ssh_keys != "" -mkdir -p /root/.ssh -chmod 700 -R /root/.ssh + #set user_name = $getVar("username", "root") + #if $user_name == "root" + #set home = "/root" + #else + #set home = "/home/%s" % $user_name + #end if +mkdir -p $home/.ssh + +chmod 700 -R $home/.ssh #set $firstline = True #for $ssh_key in $ssh_keys.split(',') #if not $ssh_key #continue #end if - #set $f = $open($ssh_key) - #if firstline -cat << EOF > /root/.ssh/authorized_keys - #echo $f.read() + #try + #set $f = $open($ssh_key) + #if firstline +cat << EOF > $home/.ssh/authorized_keys + #echo $f.read() EOF - #else -cat << EOF >> /root/.ssh/authorized_keys - #echo $f.read() + #else +cat << EOF >> $home/.ssh/authorized_keys + #echo $f.read() EOF - #end if - #set $firstline = False - #silent $f.close() + #end if + #set $firstline = False + #silent $f.close() + #except +# failed to read from $ssh_key + #end try #end for -chmod 600 /root/.ssh/authorized_keys +chmod 600 $home/.ssh/authorized_keys #end if diff --git a/cobbler/snippets/ssh.xml b/cobbler/snippets/ssh.xml index 1cb8a88..ed68f3d 100644 --- a/cobbler/snippets/ssh.xml +++ b/cobbler/snippets/ssh.xml @@ -1,33 +1,43 @@ #set ssh_keys = $getVar("push_ssh_keys", "/root/.ssh/id_rsa.pub") #if $ssh_keys != "" + #set user_name = $getVar("username", "root") + #if $user_name == "root" + #set home = "/root" + #else + #set home = "/home/%s" % $user_name + #end if - /root/.ssh/authorized_keys - root.root + $home/.ssh/authorized_keys + ${user_name}.${user_name} 600 shell /root/.ssh/authorized_keys - #echo $f.read() + #try + #set f = $open($ssh_key) + #if $firstline +cat << EOL > $home/.ssh/authorized_keys + #echo $f.read() EOL - #else -cat << EOL >> /root/.ssh/authorized_keys - #echo $f.read() + #else +cat << EOL >> $home/.ssh/authorized_keys + #echo $f.read() EOL - #end if - #silent $f.close() - #set $firstline = False + #end if + #set $firstline = False + #silent $f.close() + #except +# failed to read from $ssh_key + #end try #end for ]]> diff --git a/cobbler/snippets/suse_pre_partition_disks b/cobbler/snippets/suse_pre_partition_disks index c1545cf..bcad418 100644 --- a/cobbler/snippets/suse_pre_partition_disks +++ b/cobbler/snippets/suse_pre_partition_disks @@ -488,22 +488,23 @@ for disk in \${disks[@]}; do disk_name=\$(basename \$disk) eval "used_disk=\\${used_disk_\${disk_name}}" if [[ -z "\$used_disk" ]]; then - partition_numer=\$(lsblk -n -o MAJ:MIN,TYPE \$disk | grep part | awk '{print \$1}' | cut -d: -f2) - parted \$disk --script -- rm \${partition_numer} - fi -done -#end if - -#if $getVar('keep_old_partitions', '0') == "0" -for disk in \${disks[@]}; do - disk_name=\$(basename \$disk) - eval "used_disk=\\${used_disk_\${disk_name}}" - if [[ -z "\$used_disk" ]]; then - partition_numers=\$(parted \$disk --script -- p | awk '/^ / {print \$1}') - echo "remove partition numbers \${partition_numers} on disk \$disk" >> /tmp/log - for partition_numer in \${partition_numers}; do - parted \$disk --script -- rm \${partition_numer} - done + echo '' >> /tmp/profile/partition.xml + echo " \$disk" >> /tmp/profile/partition.xml + echo ' true' >> /tmp/profile/partition.xml + echo ' all' >> /tmp/profile/partition.xml + echo ' gpt' >> /tmp/profile/partition.xml + echo ' ' >> /tmp/profile/partition.xml + echo "add partition /reserved_\${disk_name} into partitions" >> /tmp/log + echo ' ' >> /tmp/profile/partition.xml + echo " \${partition_fstype}" >> /tmp/profile/partition.xml + echo ' true' >> /tmp/profile/partition.xml + echo " /reserved_\${disk_name}" >> /tmp/profile/partition.xml + echo ' label' >> /tmp/profile/partition.xml + echo " " >> /tmp/profile/partition.xml + echo " max" >> /tmp/profile/partition.xml + echo ' ' >> /tmp/profile/partition.xml + echo ' ' >> /tmp/profile/partition.xml + echo '' >> /tmp/profile/partition.xml fi done #end if