Change-Id: I33d4fe65b44a1479a40cc88ea2fff30e77e2b271
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1659
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Do not delete existing ova artifacts and additional fixes
Change-Id: I21b386f296be883d9ee2babd4f681fc8756785a5
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1663
Reviewed-by: suezzelur <anishs@vmware.com>
Tested-by: suezzelur <anishs@vmware.com>
Rename vmx template files and change default tar format
Change-Id: I045a88a802643f1c4926fd6f933f6e13d3ca80e6
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1666
Reviewed-by: suezzelur <anishs@vmware.com>
Tested-by: suezzelur <anishs@vmware.com>
Change tar format for ami,gce
Change-Id: I28c7852c57cda698f41f85a1c913be3b10809efe
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1671
Reviewed-by: suezzelur <anishs@vmware.com>
Tested-by: suezzelur <anishs@vmware.com>
Remove unneeded files, reduce the size of ami raw image
Change-Id: I4b75e5b623a10927af82a424eb64ac4100288b91
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1673
Reviewed-by: suezzelur <anishs@vmware.com>
Tested-by: suezzelur <anishs@vmware.com>
Change vmdk size of ovas
Change-Id: I67d8e856c68bf701b374d759c5a3eb05d9fafa52
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1683
Reviewed-by: suezzelur <anishs@vmware.com>
Tested-by: suezzelur <anishs@vmware.com>
Change grub for ami,gce to accept photon.cfg values
Change-Id: I2b34857285a1d30383b6e3f58cfe3164c9ae0895
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1691
Reviewed-by: suezzelur <anishs@vmware.com>
Tested-by: suezzelur <anishs@vmware.com>
Edit fstab to include UUID value of disk for ami, gce
Change-Id: I1018c7e3051ae9754ddf96f81209f16a87539a11
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1692
Reviewed-by: suezzelur <anishs@vmware.com>
Tested-by: suezzelur <anishs@vmware.com>
Change kernel parameters for ami image
Change-Id: I2aa42705b74489a807b374040fbd74592a8e6fda
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1698
Reviewed-by: suezzelur <anishs@vmware.com>
Tested-by: suezzelur <anishs@vmware.com>
cloud_image - PARTUUID in lowered case
systemd-remount-fs.service require PARTUUIS in lowered case.
Change-Id: Ie53dac9173787870778d617f3736843278586d55
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1693
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
Remove mk-setup-grub for cloud images
Change-Id: Icbc550a376f29742ed88801ae03140ce157917a2
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1880
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: suezzelur <anishs@vmware.com>
| ... | ... |
@@ -50,9 +50,10 @@ endif |
| 50 | 50 |
TOOLS_BIN := $(SRCROOT)/tools/bin |
| 51 | 51 |
CONTAIN := $(TOOLS_BIN)/contain |
| 52 | 52 |
VIXDISKUTIL := $(TOOLS_BIN)/vixdiskutil |
| 53 |
+IMGCONVERTER := $(TOOLS_BIN)/imgconverter |
|
| 53 | 54 |
|
| 54 | 55 |
.PHONY : all iso clean photon-build-machine photon-vagrant-build photon-vagrant-local cloud-image \ |
| 55 |
-check check-docker check-bison check-g++ check-gawk check-createrepo check-vagrant check-packer check-packer-ovf-plugin check-sanity \ |
|
| 56 |
+check check-docker check-bison check-g++ check-gawk check-createrepo check-kpartx check-vagrant check-packer check-packer-ovf-plugin check-sanity \ |
|
| 56 | 57 |
clean-install clean-chroot build-updated-packages |
| 57 | 58 |
|
| 58 | 59 |
THREADS?=1 |
| ... | ... |
@@ -431,13 +432,13 @@ photon-vagrant-local: check-packer check-vagrant |
| 431 | 431 |
echo "Unable to find $(PHOTON_STAGE)/photon-$(PHOTON_RELEASE_VERSION)-$(PHOTON_BUILD_NUMBER).iso ... aborting build"; \ |
| 432 | 432 |
fi |
| 433 | 433 |
|
| 434 |
-cloud-image: $(PHOTON_STAGE) $(VIXDISKUTIL) iso |
|
| 434 |
+cloud-image: check-kpartx $(PHOTON_STAGE) $(VIXDISKUTIL) $(IMGCONVERTER) iso |
|
| 435 | 435 |
@echo "Building cloud image $(IMG_NAME)..." |
| 436 | 436 |
@cd $(PHOTON_CLOUD_IMAGE_BUILDER_DIR) |
| 437 | 437 |
$(PHOTON_CLOUD_IMAGE_BUILDER) $(PHOTON_CLOUD_IMAGE_BUILDER_DIR) $(IMG_NAME) $(SRCROOT) $(PHOTON_GENERATED_DATA_DIR) $(PHOTON_STAGE)/photon-$(PHOTON_RELEASE_VERSION)-$(PHOTON_BUILD_NUMBER).iso $(ADDITIONAL_RPMS_PATH) |
| 438 | 438 |
|
| 439 | 439 |
|
| 440 |
-cloud-image-all: $(PHOTON_STAGE) $(VIXDISKUTIL) iso |
|
| 440 |
+cloud-image-all: check-kpartx $(PHOTON_STAGE) $(VIXDISKUTIL) $(IMGCONVERTER) iso |
|
| 441 | 441 |
@echo "Building cloud images - gce, ami, azure and ova..." |
| 442 | 442 |
@cd $(PHOTON_CLOUD_IMAGE_BUILDER_DIR) |
| 443 | 443 |
$(PHOTON_CLOUD_IMAGE_BUILDER) $(PHOTON_CLOUD_IMAGE_BUILDER_DIR) gce $(SRCROOT) $(PHOTON_GENERATED_DATA_DIR) $(PHOTON_STAGE)/photon-$(PHOTON_RELEASE_VERSION)-$(PHOTON_BUILD_NUMBER).iso $(ADDITIONAL_RPMS_PATH) |
| ... | ... |
@@ -466,6 +467,9 @@ check-gawk: |
| 466 | 466 |
check-createrepo: |
| 467 | 467 |
@command -v createrepo >/dev/null 2>&1 || { echo "Package createrepo not installed. Aborting." >&2; exit 1; }
|
| 468 | 468 |
|
| 469 |
+check-kpartx: |
|
| 470 |
+ @command -v kpartx >/dev/null 2>&1 || { echo "Package kpartx not installed. Aborting." >&2; exit 1; }
|
|
| 471 |
+ |
|
| 469 | 472 |
check-vagrant: check-packer |
| 470 | 473 |
@command -v $(VAGRANT) >/dev/null 2>&1 || { echo "Vagrant not installed or wrong path, expecting $(VAGRANT). Aborting" >&2; exit 1; }
|
| 471 | 474 |
|
| ... | ... |
@@ -514,3 +518,6 @@ $(VIXDISKUTIL): $(TOOLS_BIN) |
| 514 | 514 |
@cd $(SRCROOT)/tools/src/vixDiskUtil && \ |
| 515 | 515 |
make |
| 516 | 516 |
|
| 517 |
+$(IMGCONVERTER): $(TOOLS_BIN) |
|
| 518 |
+ @cd $(SRCROOT)/tools/src/imgconverter && \ |
|
| 519 |
+ make |
| ... | ... |
@@ -8,8 +8,11 @@ cd / |
| 8 | 8 |
echo "127.0.0.1 localhost" >> /etc/hosts |
| 9 | 9 |
|
| 10 | 10 |
# Update /etc/resolv.conf |
| 11 |
-rm /etc/resolv.conf |
|
| 12 |
-echo "nameserver 172.31.0.2" >> /etc/resolv.conf |
|
| 11 |
+if [ -f /etc/resolv.conf ] |
|
| 12 |
+ then |
|
| 13 |
+ rm /etc/resolv.conf |
|
| 14 |
+fi |
|
| 15 |
+echo "nameserver 169.254.169.253" >> /etc/resolv.conf |
|
| 13 | 16 |
echo "search ec2.internal" >> /etc/resolv.conf |
| 14 | 17 |
|
| 15 | 18 |
|
| ... | ... |
@@ -54,11 +57,14 @@ echo "Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc, |
| 54 | 54 |
echo "Tunnel no" >> /etc/ssh/ssh_config |
| 55 | 55 |
echo "ServerAliveInterval 420" >> /etc/ssh/ssh_config |
| 56 | 56 |
|
| 57 |
-sed -i '/.*linux.*vmlinuz/ s/$/ console=ttyS0/' /boot/grub/grub.cfg |
|
| 57 |
+sed -i 's/net.ifnames=0//' /boot/grub/grub.cfg |
|
| 58 |
+sed -i 's/$photon_cmdline/init=\/lib\/systemd\/systemd loglevel=3 ro console=ttyS0 earlyprintk=ttyS0/' /boot/grub/grub.cfg |
|
| 58 | 59 |
|
| 59 | 60 |
# Disable loading/unloading of modules |
| 60 | 61 |
echo 1 > /proc/sys/kernel/modules_disabled |
| 61 | 62 |
|
| 62 | 63 |
# Remove kernel symbols |
| 63 |
-rm /boot/system.map* |
|
| 64 |
- |
|
| 64 |
+if [ -f /boot/system.map* ] |
|
| 65 |
+ then |
|
| 66 |
+ rm /boot/system.map* |
|
| 67 |
+fi |
|
| 65 | 68 |
\ No newline at end of file |
| 66 | 69 |
deleted file mode 100755 |
| ... | ... |
@@ -1,9 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
- |
|
| 3 |
-PHOTON_IMG_OUTPUT_PATH=$1 |
|
| 4 |
- |
|
| 5 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 6 |
-mv photon-ami.raw photon-ami-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.raw |
|
| 7 |
-tar -Szcf photon-ami-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.tar.gz photon-ami-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.raw |
|
| 8 |
- |
|
| 9 |
-rm -f photon-ami-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.raw |
| ... | ... |
@@ -1,12 +1,18 @@ |
| 1 | 1 |
{
|
| 2 |
- "hostname": "photon-machine", |
|
| 3 |
- "password": |
|
| 4 |
- {
|
|
| 5 |
- "crypted": false, |
|
| 6 |
- "text": "PASSWORD" |
|
| 7 |
- }, |
|
| 8 |
- "type": "ami", |
|
| 2 |
+ "hostname": "photon-machine", |
|
| 3 |
+ "password": |
|
| 4 |
+ {
|
|
| 5 |
+ "crypted": false, |
|
| 6 |
+ "text": "PASSWORD" |
|
| 7 |
+ }, |
|
| 8 |
+ "type": "ami", |
|
| 9 | 9 |
"size": {"root": "8", "swap": "0"},
|
| 10 |
- "public_key":"<ssh-key-here>" |
|
| 10 |
+ "public_key":"<ssh-key-here>", |
|
| 11 |
+ "postinstallscripts": [ "ami-patch.sh", "../password-expiry.sh" ], |
|
| 12 |
+ "additionalfiles": [ |
|
| 13 |
+ {"cloud-photon.cfg": "/etc/cloud/cloud.cfg"}
|
|
| 14 |
+ ], |
|
| 15 |
+ "artifacttype": "tgz", |
|
| 16 |
+ "keeprawdisk": "false" |
|
| 11 | 17 |
} |
| 12 | 18 |
|
| ... | ... |
@@ -48,7 +48,8 @@ echo "Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc, |
| 48 | 48 |
echo "Tunnel no" >> /etc/ssh/ssh_config |
| 49 | 49 |
echo "ServerAliveInterval 180" >> /etc/ssh/ssh_config |
| 50 | 50 |
|
| 51 |
-sed -i '/.*linux.*vmlinuz/ s/$/ console=ttyS0 earlyprintk=ttyS0 rootdelay=30/' /boot/grub/grub.cfg |
|
| 51 |
+sed -i 's/net.ifnames=0//' /boot/grub/grub.cfg |
|
| 52 |
+sed -i 's/$photon_cmdline/init=\/lib\/systemd\/systemd loglevel=3 ro console=ttyS0 earlyprintk=ttyS0 rootdelay=30/' /boot/grub/grub.cfg |
|
| 52 | 53 |
|
| 53 | 54 |
# Disable loading/unloading of modules |
| 54 | 55 |
echo 1 > /proc/sys/kernel/modules_disabled |
| 55 | 56 |
deleted file mode 100755 |
| ... | ... |
@@ -1,12 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
- |
|
| 3 |
-PHOTON_IMG_OUTPUT_PATH=$1 |
|
| 4 |
-SRC_ROOT=$2 |
|
| 5 |
-cd $SRC_ROOT/tools/src/imgconverter |
|
| 6 |
-mkdir -p $SRC_ROOT/tools/bin |
|
| 7 |
-make clean |
|
| 8 |
-make |
|
| 9 |
-$SRC_ROOT/tools/bin/imgconverter -i $PHOTON_IMG_OUTPUT_PATH/photon-azure.raw -v vhd -o $PHOTON_IMG_OUTPUT_PATH/photon-azure-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.vhd |
|
| 10 |
- |
|
| 11 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-azure.raw |
|
| 12 |
- |
| ... | ... |
@@ -1,12 +1,18 @@ |
| 1 | 1 |
{
|
| 2 |
- "hostname": "photon-machine", |
|
| 3 |
- "password": |
|
| 4 |
- {
|
|
| 5 |
- "crypted": false, |
|
| 6 |
- "text": "PASSWORD" |
|
| 7 |
- }, |
|
| 8 |
- "type": "azure", |
|
| 9 |
- "size": {"root": "8", "swap": "0"},
|
|
| 10 |
- "public_key":"<ssh-key-here>" |
|
| 2 |
+ "hostname": "photon-machine", |
|
| 3 |
+ "password": |
|
| 4 |
+ {
|
|
| 5 |
+ "crypted": false, |
|
| 6 |
+ "text": "PASSWORD" |
|
| 7 |
+ }, |
|
| 8 |
+ "type": "azure", |
|
| 9 |
+ "size": {"root": "16", "swap": "0"},
|
|
| 10 |
+ "public_key":"<ssh-key-here>", |
|
| 11 |
+ "postinstallscripts": [ "azure-patch.sh", "../password-expiry.sh" ], |
|
| 12 |
+ "additionalfiles": [ |
|
| 13 |
+ {"cloud-photon.cfg": "/etc/cloud/cloud.cfg"}
|
|
| 14 |
+ ], |
|
| 15 |
+ "artifacttype": "vhd", |
|
| 16 |
+ "keeprawdisk": "false" |
|
| 11 | 17 |
} |
| 12 | 18 |
|
| ... | ... |
@@ -18,25 +18,31 @@ GENERATED_DATA_PATH=$4 |
| 18 | 18 |
PHOTON_ISO_PATH=$5 |
| 19 | 19 |
PHOTON_STAGE_PATH=${PHOTON_ISO_PATH%/*}
|
| 20 | 20 |
ADDITIONAL_RPMS_PATH=$6 |
| 21 |
-INSTALLER_PATH=$PHOTON_STAGE_PATH/$IMG_NAME |
|
| 22 |
-ISO_MOUNT_FOLDER=$PHOTON_STAGE_PATH/iso_mount |
|
| 21 |
+WORKING_DIR=$PHOTON_STAGE_PATH/$IMG_NAME |
|
| 23 | 22 |
|
| 24 | 23 |
PHOTON_IMG_OUTPUT_PATH=$PHOTON_STAGE_PATH/$IMG_NAME |
| 25 | 24 |
VMDK_CONFIG_FILE=${BUILD_SCRIPTS_PATH}/$IMG_NAME/vmdk_$IMG_NAME.json
|
| 26 | 25 |
VMDK_CONFIG_SAFE_FILE=${BUILD_SCRIPTS_PATH}/$IMG_NAME/vmdk_safe_$IMG_NAME.json
|
| 27 | 26 |
|
| 28 |
-mkdir -p $INSTALLER_PATH/installer |
|
| 29 |
-cp -R $SRC_ROOT/installer $INSTALLER_PATH/ |
|
| 27 |
+cd $BUILD_SCRIPTS_PATH |
|
| 28 |
+image_list=`for i in $(ls -d */); do echo ${i%%/}; done`
|
|
| 29 |
+if ! [[ $image_list =~ (^|[[:space:]])$IMG_NAME($|[[:space:]]) ]] |
|
| 30 |
+ then |
|
| 31 |
+ echo "Input image name not supported. Aborting."; exit 1; |
|
| 32 |
+fi |
|
| 30 | 33 |
|
| 31 |
-cd $INSTALLER_PATH/installer |
|
| 34 |
+rm -rf $WORKING_DIR |
|
| 35 |
+mkdir -p $WORKING_DIR/installer |
|
| 36 |
+cp -R $SRC_ROOT/installer $WORKING_DIR/ |
|
| 37 |
+ |
|
| 38 |
+cd $WORKING_DIR/installer |
|
| 32 | 39 |
cp $VMDK_CONFIG_FILE $VMDK_CONFIG_SAFE_FILE |
| 33 | 40 |
cp ${BUILD_SCRIPTS_PATH}/mk-setup-vmdk.sh .
|
| 34 | 41 |
cp ${BUILD_SCRIPTS_PATH}/mk-clean-vmdk.sh .
|
| 35 | 42 |
|
| 36 |
- |
|
| 37 |
-if [[ $IMG_NAME != ova* ]] |
|
| 43 |
+if [[ $IMG_NAME == ova* ]] |
|
| 38 | 44 |
then |
| 39 |
- cp ${BUILD_SCRIPTS_PATH}/mk-setup-grub.sh .
|
|
| 45 |
+ command -v ovftool >/dev/null 2>&1 || { echo "Ovftool not installed. Aborting." >&2; exit 1; }
|
|
| 40 | 46 |
fi |
| 41 | 47 |
|
| 42 | 48 |
if [ -e ${BUILD_SCRIPTS_PATH}/${IMG_NAME}/mk-setup-grub.sh ]
|
| ... | ... |
@@ -49,105 +55,26 @@ sed -i "s/PASSWORD/$PASSWORD/" $VMDK_CONFIG_SAFE_FILE |
| 49 | 49 |
|
| 50 | 50 |
if [ -n "$ADDITIONAL_RPMS_PATH" ] |
| 51 | 51 |
then |
| 52 |
- mkdir $PHOTON_STAGE_PATH/RPMS/additonal |
|
| 53 |
- cp -f $ADDITIONAL_RPMS_PATH/* $PHOTON_STAGE_PATH/RPMS/additonal/ |
|
| 52 |
+ mkdir $PHOTON_STAGE_PATH/RPMS/additional |
|
| 53 |
+ cp -f $ADDITIONAL_RPMS_PATH/* $PHOTON_STAGE_PATH/RPMS/additional/ |
|
| 54 | 54 |
fi |
| 55 | 55 |
|
| 56 |
-./photonInstaller.py -p $GENERATED_DATA_PATH/build_install_options_$IMG_NAME.json -r $PHOTON_STAGE_PATH/RPMS -v $INSTALLER_PATH/photon-${IMG_NAME} -o $GENERATED_DATA_PATH -f $VMDK_CONFIG_SAFE_FILE
|
|
| 56 |
+./photonInstaller.py -p $GENERATED_DATA_PATH/build_install_options_$IMG_NAME.json -r $PHOTON_STAGE_PATH/RPMS -v $WORKING_DIR/photon-${IMG_NAME} -o $GENERATED_DATA_PATH -f $VMDK_CONFIG_SAFE_FILE
|
|
| 57 | 57 |
cat $VMDK_CONFIG_SAFE_FILE |
| 58 | 58 |
rm $VMDK_CONFIG_SAFE_FILE |
| 59 | 59 |
|
| 60 | 60 |
cd $BUILD_SCRIPTS_PATH |
| 61 | 61 |
|
| 62 |
-DISK_DEVICE=`losetup --show -f ${PHOTON_IMG_OUTPUT_PATH}/photon-${IMG_NAME}.raw`
|
|
| 63 |
- |
|
| 64 |
-echo "Mapping device partition to loop device" |
|
| 65 |
-kpartx -av $DISK_DEVICE |
|
| 66 |
- |
|
| 67 |
-DEVICE_NAME=`echo $DISK_DEVICE|cut -c6- ` |
|
| 68 |
- |
|
| 69 |
-echo "DISK_DEVICE=$DISK_DEVICE" |
|
| 70 |
-echo "ROOT_PARTITION=/dev/mapper/${DEVICE_NAME}p2"
|
|
| 71 |
- |
|
| 72 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}
|
|
| 73 |
-mkdir $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}
|
|
| 74 |
- |
|
| 75 |
-UUID_VALUE=$(blkid -s UUID -o value /dev/mapper/${DEVICE_NAME}p2)
|
|
| 76 |
-PARTUUID_VALUE=$(blkid -s PARTUUID -o value /dev/mapper/${DEVICE_NAME}p2)
|
|
| 77 |
-if [ -z "$PARTUUID_VALUE" ] ; then |
|
| 78 |
- PARTUUID_VALUE=$(sgdisk -i 2 $DISK_DEVICE | grep "Partition unique GUID" | cut -d ' ' -f 4) |
|
| 79 |
-fi |
|
| 80 |
- |
|
| 81 |
-mkdir -p $ISO_MOUNT_FOLDER |
|
| 82 |
-mount -o loop $PHOTON_ISO_PATH $ISO_MOUNT_FOLDER |
|
| 83 |
-mount -v -t ext4 /dev/mapper/${DEVICE_NAME}p2 $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}
|
|
| 84 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/installer
|
|
| 85 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/LOGS
|
|
| 86 |
-cp $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/shadow $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/shadow.bak
|
|
| 87 |
-sed -e "s/^\(root:\)[^:]*:/\1*:/" $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/shadow.bak > $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/shadow
|
|
| 88 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/shadow.bak
|
|
| 89 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/shadow-
|
|
| 90 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/machine-id
|
|
| 91 |
-touch $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/machine-id
|
|
| 92 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/fstab
|
|
| 93 |
-echo "UUID=$UUID_VALUE / ext4 defaults 1 1" >> $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/fstab
|
|
| 94 |
-sed -i "s/rootpartition=PARTUUID=$/rootpartition=PARTUUID=$PARTUUID_VALUE/" $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/boot/grub/grub.cfg
|
|
| 95 |
- |
|
| 96 |
-mount -o bind /proc $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/proc
|
|
| 97 |
-mount -o bind /dev $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/dev
|
|
| 98 |
-mount -o bind /dev/pts $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/dev/pts
|
|
| 99 |
-mount -o bind /sys $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/sys
|
|
| 100 |
-if [ -n "$ADDITIONAL_RPMS_PATH" ] |
|
| 101 |
- then |
|
| 102 |
- mkdir $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/additional_rpms
|
|
| 103 |
- mkdir $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/var/run
|
|
| 104 |
- cp -f $PHOTON_STAGE_PATH/RPMS/additonal/* $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/additional_rpms/
|
|
| 105 |
- chroot $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME} /bin/bash -c "rpm -i /additional_rpms/*"
|
|
| 106 |
- rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/additional_rpms/
|
|
| 107 |
-fi |
|
| 108 |
- |
|
| 109 |
-if [ $IMG_NAME != "ova" ] && [ $IMG_NAME != "ova_uefi" ] && [ $IMG_NAME != "ova_ovs" ] |
|
| 110 |
- then |
|
| 111 |
- cd $BUILD_SCRIPTS_PATH |
|
| 112 |
- if [ $IMG_NAME = "gce" ] |
|
| 113 |
- then |
|
| 114 |
- cp ntpd.service $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/lib/systemd/system/
|
|
| 115 |
- cp eth0.service $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/lib/systemd/system/
|
|
| 116 |
- fi |
|
| 117 |
- if [ $IMG_NAME != "ova_generic" ] |
|
| 118 |
- then |
|
| 119 |
- if [ -e $IMG_NAME/cloud-photon.cfg ] |
|
| 120 |
- then |
|
| 121 |
- cp -f $IMG_NAME/cloud-photon.cfg $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/cloud/cloud.cfg
|
|
| 122 |
- fi |
|
| 123 |
- cp $IMG_NAME/$IMG_NAME-patch.sh $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/
|
|
| 124 |
- cp /etc/resolv.conf $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/
|
|
| 125 |
- echo "chrooting and running patch inside the chroot" |
|
| 126 |
- chroot $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME} /bin/bash -c "/$IMG_NAME-patch.sh"
|
|
| 127 |
- rm -f $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/$IMG_NAME-patch.sh
|
|
| 128 |
- # Change the max password days to 99999 |
|
| 129 |
- chroot $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME} /bin/bash -c "cat /etc/shadow | cut -d: -f1 | xargs -I {} chage -I -1 -m 0 -M 99999 -E -1 -W 7 {}"
|
|
| 130 |
- sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 99999/' $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/etc/login.defs
|
|
| 131 |
- fi |
|
| 132 |
-fi |
|
| 133 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/sys
|
|
| 134 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/dev/pts
|
|
| 135 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/dev
|
|
| 136 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}/proc
|
|
| 137 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME}
|
|
| 138 |
-umount $ISO_MOUNT_FOLDER |
|
| 139 |
-rm -rf $ISO_MOUNT_FOLDER |
|
| 140 |
- |
|
| 141 |
-echo "Deleting device map partition" |
|
| 142 |
-kpartx -d $DISK_DEVICE |
|
| 143 |
- |
|
| 144 |
-rm -rf photon-${IMG_NAME}
|
|
| 145 |
- |
|
| 146 |
-echo "Detaching loop device from raw disk" |
|
| 147 |
-losetup -d $DISK_DEVICE |
|
| 148 |
- |
|
| 149 |
- |
|
| 150 |
-cd $IMG_NAME |
|
| 151 |
-./mk-$IMG_NAME-image.sh $PHOTON_STAGE_PATH/$IMG_NAME $SRC_ROOT |
|
| 62 |
+./customize_cloud_image.py \ |
|
| 63 |
+ -r ${PHOTON_IMG_OUTPUT_PATH}/photon-${IMG_NAME}.raw \
|
|
| 64 |
+ -c $VMDK_CONFIG_FILE \ |
|
| 65 |
+ -w $WORKING_DIR \ |
|
| 66 |
+ -m $PHOTON_IMG_OUTPUT_PATH/photon-${IMG_NAME} \
|
|
| 67 |
+ -a $PHOTON_STAGE_PATH/RPMS/additional \ |
|
| 68 |
+ -i $IMG_NAME \ |
|
| 69 |
+ -t $SRC_ROOT/tools/bin/ \ |
|
| 70 |
+ -b $BUILD_SCRIPTS_PATH |
|
| 71 |
+ |
|
| 72 |
+rm -rf $WORKING_DIR/installer |
|
| 152 | 73 |
|
| 153 | 74 |
exit 0 |
| 154 | 75 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,262 @@ |
| 0 |
+#!/usr/bin/python2 |
|
| 1 |
+ |
|
| 2 |
+import os |
|
| 3 |
+import re |
|
| 4 |
+import shutil |
|
| 5 |
+import tarfile |
|
| 6 |
+import fileinput |
|
| 7 |
+from optparse import OptionParser |
|
| 8 |
+from utils import Utils |
|
| 9 |
+ |
|
| 10 |
+def create_ova_image(raw_image_name, tools_path, build_scripts_path, config): |
|
| 11 |
+ output_path = os.path.dirname(os.path.realpath(raw_image_name)) |
|
| 12 |
+ utils = Utils() |
|
| 13 |
+ # Remove older artifacts |
|
| 14 |
+ files = os.listdir(output_path) |
|
| 15 |
+ for file in files: |
|
| 16 |
+ if file.endswith(".vmdk"):
|
|
| 17 |
+ os.remove(os.path.join(output_path, file)) |
|
| 18 |
+ |
|
| 19 |
+ vmx_path = output_path + '/photon-ova.vmx' |
|
| 20 |
+ utils.replaceandsaveasnewfile(build_scripts_path + '/vmx-template', vmx_path, 'VMDK_IMAGE', output_path + '/photon-ova.vmdk') |
|
| 21 |
+ vixdiskutil_path = tools_path + 'vixdiskutil' |
|
| 22 |
+ vmdk_path = output_path + '/photon-ova.vmdk' |
|
| 23 |
+ ovf_path = output_path + '/photon-ova.ovf' |
|
| 24 |
+ mf_path = output_path + '/photon-ova.mf' |
|
| 25 |
+ utils.runshellcommand("{} -convert {} -cap 16000 {}".format(vixdiskutil_path, raw_image_name, vmdk_path))
|
|
| 26 |
+ utils.runshellcommand("{} -wmeta toolsVersion 2147483647 {}".format(vixdiskutil_path, vmdk_path))
|
|
| 27 |
+ |
|
| 28 |
+ utils.runshellcommand("ovftool {} {}".format(vmx_path, ovf_path))
|
|
| 29 |
+ utils.replaceinfile(ovf_path, 'otherGuest', 'other3xLinux64Guest') |
|
| 30 |
+ |
|
| 31 |
+ #Add product info |
|
| 32 |
+ for line in fileinput.input(ovf_path, inplace=True): |
|
| 33 |
+ if line.strip() == '</VirtualSystem>': |
|
| 34 |
+ print ' \t<ProductSection> \n \t\t<Info>Information about the installed software</Info> \n \t\t<Product>Photon</Product> \n \t\t<Vendor>VMware Inc.</Vendor> \n \t\t<Version>1.0</Version> \n \t\t<FullVersion>1.0</FullVersion> \n \t</ProductSection> ' |
|
| 35 |
+ print line, |
|
| 36 |
+ |
|
| 37 |
+ if os.path.exists(mf_path): |
|
| 38 |
+ os.remove(mf_path) |
|
| 39 |
+ |
|
| 40 |
+ cwd = os.getcwd() |
|
| 41 |
+ os.chdir(output_path) |
|
| 42 |
+ out = utils.runshellcommand("openssl sha1 photon-ova-disk1.vmdk photon-ova.ovf")
|
|
| 43 |
+ with open(mf_path, "w") as source: |
|
| 44 |
+ source.write(out) |
|
| 45 |
+ rawsplit = os.path.splitext(raw_image_name) |
|
| 46 |
+ ova_name = rawsplit[0] + '.ova' |
|
| 47 |
+ |
|
| 48 |
+ ovatar = tarfile.open(ova_name, "w", format = tarfile.USTAR_FORMAT) |
|
| 49 |
+ for name in ["photon-ova.ovf", "photon-ova.mf", "photon-ova-disk1.vmdk"]: |
|
| 50 |
+ ovatar.add(name, arcname=os.path.basename(name)) |
|
| 51 |
+ ovatar.close() |
|
| 52 |
+ os.remove(vmx_path) |
|
| 53 |
+ os.remove(mf_path) |
|
| 54 |
+ |
|
| 55 |
+ if 'additionalhwversion' in config: |
|
| 56 |
+ for addlversion in config['additionalhwversion']: |
|
| 57 |
+ new_ovf_path = output_path + "/photon-ova-hw{}.ovf".format(addlversion)
|
|
| 58 |
+ mf_path = output_path + "/photon-ova-hw{}.mf".format(addlversion)
|
|
| 59 |
+ utils.replaceandsaveasnewfile(ovf_path, new_ovf_path, "vmx-.*<", "vmx-{}<".format(addlversion))
|
|
| 60 |
+ out = utils.runshellcommand("openssl sha1 photon-ova-disk1.vmdk photon-ova-hw{}.ovf".format(addlversion))
|
|
| 61 |
+ with open(mf_path, "w") as source: |
|
| 62 |
+ source.write(out) |
|
| 63 |
+ temp_name_list = os.path.basename(ova_name).split('-')
|
|
| 64 |
+ temp_name_list = temp_name_list[:2] + ["hw{}".format(addlversion)] + temp_name_list[2:]
|
|
| 65 |
+ new_ova_name = '-'.join(temp_name_list) |
|
| 66 |
+ new_ova_path = output_path + '/' + new_ova_name |
|
| 67 |
+ ovatar = tarfile.open(new_ova_path, "w", format = tarfile.USTAR_FORMAT) |
|
| 68 |
+ for name in [new_ovf_path, mf_path, "photon-ova-disk1.vmdk"]: |
|
| 69 |
+ ovatar.add(name, arcname=os.path.basename(name)) |
|
| 70 |
+ ovatar.close() |
|
| 71 |
+ |
|
| 72 |
+ os.remove(new_ovf_path) |
|
| 73 |
+ os.remove(mf_path) |
|
| 74 |
+ os.chdir(cwd) |
|
| 75 |
+ os.remove(ovf_path) |
|
| 76 |
+ os.remove(vmdk_path) |
|
| 77 |
+ files = os.listdir(output_path) |
|
| 78 |
+ for file in files: |
|
| 79 |
+ if file.endswith(".vmdk"):
|
|
| 80 |
+ os.remove(os.path.join(output_path, file)) |
|
| 81 |
+ |
|
| 82 |
+ |
|
| 83 |
+if __name__ == '__main__': |
|
| 84 |
+ usage = "Usage: %prog [options]" |
|
| 85 |
+ parser = OptionParser(usage) |
|
| 86 |
+ |
|
| 87 |
+ parser.add_option("-r", "--raw-image-path", dest="raw_image_path")
|
|
| 88 |
+ parser.add_option("-c", "--vmdk-config-path", dest="vmdk_config_path")
|
|
| 89 |
+ parser.add_option("-w", "--working-directory", dest="working_directory")
|
|
| 90 |
+ parser.add_option("-m", "--mount-path", dest="mount_path")
|
|
| 91 |
+ parser.add_option("-a", "--additional-rpms-path", dest="additional_rpms_path")
|
|
| 92 |
+ parser.add_option("-i", "--image-name", dest="image_name")
|
|
| 93 |
+ parser.add_option("-t", "--tools-bin-path", dest="tools_bin_path")
|
|
| 94 |
+ parser.add_option("-b", "--build-scripts-path", dest="build_scripts_path")
|
|
| 95 |
+ |
|
| 96 |
+ (options, args) = parser.parse_args() |
|
| 97 |
+ utils = Utils() |
|
| 98 |
+ config = utils.jsonread(options.vmdk_config_path) |
|
| 99 |
+ print options |
|
| 100 |
+ |
|
| 101 |
+ disk_device = (utils.runshellcommand("losetup --show -f {}".format(options.raw_image_path))).rstrip('\n')
|
|
| 102 |
+ disk_partitions = utils.runshellcommand("kpartx -as {}".format(disk_device))
|
|
| 103 |
+ device_name = disk_device.split('/')[2]
|
|
| 104 |
+ |
|
| 105 |
+ if not os.path.exists(options.mount_path): |
|
| 106 |
+ os.mkdir(options.mount_path) |
|
| 107 |
+ loop_device_path = "/dev/mapper/{}p2".format(device_name)
|
|
| 108 |
+ |
|
| 109 |
+ try: |
|
| 110 |
+ print "Generating PARTUUID for the loop device ..." |
|
| 111 |
+ partuuidval = (utils.runshellcommand("blkid -s PARTUUID -o value {}".format(loop_device_path))).rstrip('\n')
|
|
| 112 |
+ uuidval = (utils.runshellcommand("blkid -s UUID -o value {}".format(loop_device_path))).rstrip('\n')
|
|
| 113 |
+ if (partuuidval == ''): |
|
| 114 |
+ sgdiskout = utils.runshellcommand("sgdisk -i 2 {} ".format(disk_device))
|
|
| 115 |
+ partuuidval = (re.findall(r'Partition unique GUID.*', sgdiskout))[0].split(':')[1].strip(' ').lower()
|
|
| 116 |
+ |
|
| 117 |
+ if (partuuidval == ''): |
|
| 118 |
+ raise RuntimeError("Cannot generate partuuid")
|
|
| 119 |
+ |
|
| 120 |
+ # Mount the loop device |
|
| 121 |
+ print "Mounting the loop device for customization ..." |
|
| 122 |
+ utils.runshellcommand("mount -t ext4 {} {}".format(loop_device_path, options.mount_path))
|
|
| 123 |
+ shutil.rmtree(options.mount_path + "/installer", ignore_errors=True) |
|
| 124 |
+ shutil.rmtree(options.mount_path + "/LOGS", ignore_errors=True) |
|
| 125 |
+ # Clear the root password if not set explicitly from the config file |
|
| 126 |
+ if (config['password']['text'] != 'PASSWORD'): |
|
| 127 |
+ utils.replaceinfile(options.mount_path + "/etc/shadow",'root:.*?:','root:*:') |
|
| 128 |
+ # Clear machine-id so it gets regenerated on boot |
|
| 129 |
+ open(options.mount_path + "/etc/machine-id", "w").close() |
|
| 130 |
+ os.remove(options.mount_path + "/etc/fstab") |
|
| 131 |
+ |
|
| 132 |
+ f = open(options.mount_path + "/etc/fstab", "w") |
|
| 133 |
+ if (uuidval != ''): |
|
| 134 |
+ f.write("UUID={} / ext4 defaults 1 1\n".format(uuidval))
|
|
| 135 |
+ else: |
|
| 136 |
+ f.write("PARTUUID={} / ext4 defaults 1 1\n".format(partuuidval))
|
|
| 137 |
+ f.close() |
|
| 138 |
+ utils.replaceinfile(options.mount_path + "/boot/grub/grub.cfg", "rootpartition=PARTUUID=.*$", "rootpartition=PARTUUID={}".format(partuuidval))
|
|
| 139 |
+ |
|
| 140 |
+ if os.path.exists(options.additional_rpms_path): |
|
| 141 |
+ print "Installing additional rpms" |
|
| 142 |
+ os.mkdir(options.mount_path + "/additional_rpms") |
|
| 143 |
+ os.mkdir(options.mount_path + "/var/run") |
|
| 144 |
+ utils.copyallfiles(additional_rpms_path, options.mount_path + "/additional_rpms") |
|
| 145 |
+ utils.runshellcommand("chroot {} /bin/bash -c 'rpm -i /additional_rpms/*'".format(options.mount_path))
|
|
| 146 |
+ shutil.rmtree(options.mount_path + "/additional_rpms", ignore_errors=True) |
|
| 147 |
+ shutil.rmtree(additional_rpms_path, ignore_errors=True) |
|
| 148 |
+ |
|
| 149 |
+ utils.runshellcommand("mount -o bind /proc {}".format(options.mount_path + "/proc"))
|
|
| 150 |
+ utils.runshellcommand("mount -o bind /dev {}".format(options.mount_path + "/dev"))
|
|
| 151 |
+ utils.runshellcommand("mount -o bind /dev/pts {}".format(options.mount_path + "/dev/pts"))
|
|
| 152 |
+ utils.runshellcommand("mount -o bind /sys {}".format(options.mount_path + "/sys"))
|
|
| 153 |
+ |
|
| 154 |
+ if 'additionalfiles' in config: |
|
| 155 |
+ print " Copying additional files into the raw image ..." |
|
| 156 |
+ for filetuples in config['additionalfiles']: |
|
| 157 |
+ for src,dest in filetuples.iteritems(): |
|
| 158 |
+ shutil.copyfile(options.build_scripts_path + '/' + options.image_name + '/' + src, options.mount_path + '/' + dest) |
|
| 159 |
+ |
|
| 160 |
+ |
|
| 161 |
+ if 'postinstallscripts' in config: |
|
| 162 |
+ print " Running post install scripts ..." |
|
| 163 |
+ if not os.path.exists(options.mount_path + "/tempscripts"): |
|
| 164 |
+ os.mkdir(options.mount_path + "/tempscripts") |
|
| 165 |
+ for script in config['postinstallscripts']: |
|
| 166 |
+ shutil.copy(options.build_scripts_path + '/' + options.image_name + '/' + script, options.mount_path + "/tempscripts") |
|
| 167 |
+ for script in os.listdir(options.mount_path + "/tempscripts"): |
|
| 168 |
+ print " ...running script {}".format(script)
|
|
| 169 |
+ utils.runshellcommand("chroot {} /bin/bash -c '/tempscripts/{}'".format(options.mount_path, script))
|
|
| 170 |
+ shutil.rmtree(options.mount_path + "/tempscripts", ignore_errors=True) |
|
| 171 |
+ |
|
| 172 |
+ utils.runshellcommand("umount -l {}".format(options.mount_path + "/sys"))
|
|
| 173 |
+ utils.runshellcommand("umount -l {}".format(options.mount_path + "/dev/pts"))
|
|
| 174 |
+ utils.runshellcommand("umount -l {}".format(options.mount_path + "/dev"))
|
|
| 175 |
+ utils.runshellcommand("umount -l {}".format(options.mount_path + "/proc"))
|
|
| 176 |
+ utils.runshellcommand("umount -l {}".format(options.mount_path))
|
|
| 177 |
+ |
|
| 178 |
+ mount_out = utils.runshellcommand("mount")
|
|
| 179 |
+ print "List of mounted devices:" |
|
| 180 |
+ print mount_out |
|
| 181 |
+ |
|
| 182 |
+ finally: |
|
| 183 |
+ utils.runshellcommand("kpartx -d {}".format(disk_device))
|
|
| 184 |
+ utils.runshellcommand("losetup -d {}".format(disk_device))
|
|
| 185 |
+ |
|
| 186 |
+ shutil.rmtree(options.mount_path) |
|
| 187 |
+ |
|
| 188 |
+ photon_release_ver = os.environ['PHOTON_RELEASE_VER'] |
|
| 189 |
+ photon_build_num = os.environ['PHOTON_BUILD_NUM'] |
|
| 190 |
+ raw_image = options.raw_image_path |
|
| 191 |
+ new_name = "" |
|
| 192 |
+ img_path = os.path.dirname(os.path.realpath(raw_image)) |
|
| 193 |
+ # Rename gce image to disk.raw |
|
| 194 |
+ if options.image_name == "gce": |
|
| 195 |
+ print "Renaming the raw file to disk.raw ..." |
|
| 196 |
+ new_name = img_path + '/disk.raw' |
|
| 197 |
+ |
|
| 198 |
+ else: |
|
| 199 |
+ new_name = img_path + '/photon-' + options.image_name + '-' + photon_release_ver + '-' + photon_build_num + '.raw' |
|
| 200 |
+ |
|
| 201 |
+ shutil.move(raw_image, new_name) |
|
| 202 |
+ raw_image = new_name |
|
| 203 |
+ |
|
| 204 |
+ if config['artifacttype'] == 'tgz': |
|
| 205 |
+ print "Generating the tar.gz artifact ..." |
|
| 206 |
+ tarname = img_path + '/photon-' + options.image_name + '-' + photon_release_ver + '-' + photon_build_num + '.tar.gz' |
|
| 207 |
+ tgzout = tarfile.open(tarname, "w:gz") |
|
| 208 |
+ tgzout.add(raw_image, arcname=os.path.basename(raw_image)) |
|
| 209 |
+ tgzout.close() |
|
| 210 |
+ elif config['artifacttype'] == 'vhd': |
|
| 211 |
+ imgconverter = options.tools_bin_path + '/imgconverter' |
|
| 212 |
+ vhdname = img_path + '/photon-' + options.image_name + '-' + photon_release_ver + '-' + photon_build_num + '.vhd' |
|
| 213 |
+ print "Converting raw disk to vhd ..." |
|
| 214 |
+ utils.runshellcommand("{} -i {} -v vhd -o {}".format(imgconverter, raw_image, vhdname))
|
|
| 215 |
+ elif config['artifacttype'] == 'ova': |
|
| 216 |
+ create_ova_image(raw_image, options.tools_bin_path, options.build_scripts_path + '/' + options.image_name, config) |
|
| 217 |
+ if 'customartifacts' in config: |
|
| 218 |
+ if 'postinstallscripts' in config['customartifacts']: |
|
| 219 |
+ custom_path = img_path + '/photon-custom' |
|
| 220 |
+ if not os.path.exists(custom_path): |
|
| 221 |
+ os.mkdir(custom_path) |
|
| 222 |
+ index = 1 |
|
| 223 |
+ for script in config['customartifacts']['postinstallscripts']: |
|
| 224 |
+ print "Creating custom ova {}...".format(index)
|
|
| 225 |
+ if index > 1: |
|
| 226 |
+ raw_image_custom = img_path + "/photon-custom-{}".format(index) + photon_release_ver + '-' + photon_build_num + '.raw'
|
|
| 227 |
+ else: |
|
| 228 |
+ raw_image_custom = img_path + "/photon-custom-" + photon_release_ver + '-' + photon_build_num + '.raw' |
|
| 229 |
+ shutil.move(raw_image, raw_image_custom) |
|
| 230 |
+ disk_device = (utils.runshellcommand("losetup --show -f {}".format(raw_image_custom))).rstrip('\n')
|
|
| 231 |
+ disk_partitions = utils.runshellcommand("kpartx -as {}".format(disk_device))
|
|
| 232 |
+ device_name = disk_device.split('/')[2]
|
|
| 233 |
+ loop_device_path = "/dev/mapper/{}p2".format(device_name)
|
|
| 234 |
+ |
|
| 235 |
+ print "Mounting the loop device for ova customization ..." |
|
| 236 |
+ utils.runshellcommand("mount -t ext4 {} {}".format(loop_device_path, custom_path))
|
|
| 237 |
+ if not os.path.exists(custom_path + "/tempscripts"): |
|
| 238 |
+ os.mkdir(custom_path + "/tempscripts") |
|
| 239 |
+ shutil.copy(options.build_scripts_path + '/' + options.image_name + '/' + script, custom_path + "/tempscripts") |
|
| 240 |
+ print "Running custom ova script {}".format(script)
|
|
| 241 |
+ utils.runshellcommand("chroot {} /bin/bash -c '/tempscripts/{}'".format(custom_path, script))
|
|
| 242 |
+ shutil.rmtree(custom_path + "/tempscripts", ignore_errors=True) |
|
| 243 |
+ utils.runshellcommand("umount -l {}".format(custom_path))
|
|
| 244 |
+ |
|
| 245 |
+ mount_out = utils.runshellcommand("mount")
|
|
| 246 |
+ print "List of mounted devices:" |
|
| 247 |
+ print mount_out |
|
| 248 |
+ |
|
| 249 |
+ utils.runshellcommand("kpartx -d {}".format(disk_device))
|
|
| 250 |
+ utils.runshellcommand("losetup -d {}".format(disk_device))
|
|
| 251 |
+ create_ova_image(raw_image_custom, options.tools_bin_path, options.build_scripts_path + '/' + options.image_name, config) |
|
| 252 |
+ raw_image = raw_image_custom |
|
| 253 |
+ index = index + 1 |
|
| 254 |
+ |
|
| 255 |
+ shutil.rmtree(custom_path) |
|
| 256 |
+ |
|
| 257 |
+ else: |
|
| 258 |
+ raise ValueError("Unknown output format")
|
|
| 259 |
+ |
|
| 260 |
+ if config['keeprawdisk'] == 'false': |
|
| 261 |
+ os.remove(raw_image) |
| 10 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,11 +0,0 @@ |
| 1 |
-[Unit] |
|
| 2 |
-Description=Network interface initialization |
|
| 3 |
-After=local-fs.target network-online.target network.target |
|
| 4 |
-Wants=local-fs.target network-online.target network.target |
|
| 5 |
- |
|
| 6 |
-[Service] |
|
| 7 |
-ExecStart=/usr/sbin/ifconfig eth0 mtu 1460 up |
|
| 8 |
-Type=oneshot |
|
| 9 |
- |
|
| 10 |
-[Install] |
|
| 11 |
-WantedBy=multi-user.target |
| 12 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,11 @@ |
| 0 |
+[Unit] |
|
| 1 |
+Description=Network interface initialization |
|
| 2 |
+After=local-fs.target network-online.target network.target |
|
| 3 |
+Wants=local-fs.target network-online.target network.target |
|
| 4 |
+ |
|
| 5 |
+[Service] |
|
| 6 |
+ExecStart=/usr/sbin/ifconfig eth0 mtu 1460 up |
|
| 7 |
+Type=oneshot |
|
| 8 |
+ |
|
| 9 |
+[Install] |
|
| 10 |
+WantedBy=multi-user.target |
| 0 | 11 |
deleted file mode 100755 |
| ... | ... |
@@ -1,12 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
- |
|
| 3 |
-PHOTON_IMG_OUTPUT_PATH=$1 |
|
| 4 |
-RAWFILE="photon-gce.raw" |
|
| 5 |
-TARFILE="photon-gce-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.tar.gz" |
|
| 6 |
- |
|
| 7 |
-echo "Creating ${TARFILE} file from ${RAWFILE}."
|
|
| 8 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 9 |
-mv ${RAWFILE} disk.raw
|
|
| 10 |
-tar -Szcf $PHOTON_IMG_OUTPUT_PATH/${TARFILE} disk.raw
|
|
| 11 |
- |
|
| 12 |
-rm -f disk.raw |
| ... | ... |
@@ -63,7 +63,8 @@ fi |
| 63 | 63 |
# |
| 64 | 64 |
# Install grub2. |
| 65 | 65 |
# |
| 66 |
-UUID=$(blkid -s UUID -o value $ROOT_PARTITION_PATH) |
|
| 66 |
+UUID_VAL=$(blkid -s UUID -o value $ROOT_PARTITION_PATH) |
|
| 67 |
+PARTUUID_VAL=$(blkid -s PARTUUID -o value $ROOT_PARTITION_PATH) |
|
| 67 | 68 |
BOOT_UUID=$(blkid -s UUID -o value $BOOT_PARTITION_PATH) |
| 68 | 69 |
echo "Changing boot loader to MBR type on raw disk" |
| 69 | 70 |
|
| ... | ... |
@@ -93,7 +94,7 @@ if [ "$BOOTMODE" == "efi" ]; then |
| 93 | 93 |
grub_efi_install |
| 94 | 94 |
fi |
| 95 | 95 |
|
| 96 |
-cat > "$BUILDROOT"/boot/grub2/grub.cfg << "EOF" |
|
| 96 |
+cat > ${BUILDROOT}/boot/grub2/grub.cfg <<EOF
|
|
| 97 | 97 |
# Begin /boot/grub2/grub.cfg |
| 98 | 98 |
# |
| 99 | 99 |
# DO NOT EDIT THIS FILE |
| ... | ... |
@@ -103,21 +104,23 @@ cat > "$BUILDROOT"/boot/grub2/grub.cfg << "EOF" |
| 103 | 103 |
# |
| 104 | 104 |
|
| 105 | 105 |
### BEGIN /etc/grub.d/00_header ### |
| 106 |
-if [ -s $prefix/grubenv ]; then |
|
| 106 |
+if [ -s \$prefix/grubenv ]; then |
|
| 107 | 107 |
load_env |
| 108 | 108 |
fi |
| 109 | 109 |
set default="0" |
| 110 | 110 |
|
| 111 |
-if [ x"${feature_menuentry_id}" = xy ]; then
|
|
| 111 |
+if [ x"\${feature_menuentry_id}" = xy ]; then
|
|
| 112 | 112 |
menuentry_id_option="--id" |
| 113 | 113 |
else |
| 114 | 114 |
menuentry_id_option="" |
| 115 | 115 |
fi |
| 116 | 116 |
|
| 117 | 117 |
export menuentry_id_option |
| 118 |
+load_env -f "$BOOT_DIRECTORY"photon.cfg |
|
| 119 |
+set rootpartition=PARTUUID=$PARTUUID_VAL |
|
| 118 | 120 |
|
| 119 |
-if [ "${prev_saved_entry}" ]; then
|
|
| 120 |
- set saved_entry="${prev_saved_entry}"
|
|
| 121 |
+if [ "\${prev_saved_entry}" ]; then
|
|
| 122 |
+ set saved_entry="\${prev_saved_entry}"
|
|
| 121 | 123 |
save_env saved_entry |
| 122 | 124 |
set prev_saved_entry= |
| 123 | 125 |
save_env prev_saved_entry |
| ... | ... |
@@ -125,14 +128,14 @@ if [ "${prev_saved_entry}" ]; then
|
| 125 | 125 |
fi |
| 126 | 126 |
|
| 127 | 127 |
function savedefault {
|
| 128 |
- if [ -z "${boot_once}" ]; then
|
|
| 129 |
- saved_entry="${chosen}"
|
|
| 128 |
+ if [ -z "\${boot_once}" ]; then
|
|
| 129 |
+ saved_entry="\${chosen}"
|
|
| 130 | 130 |
save_env saved_entry |
| 131 | 131 |
fi |
| 132 | 132 |
} |
| 133 | 133 |
|
| 134 | 134 |
function load_video {
|
| 135 |
- if [ x$feature_all_video_module = xy ]; then |
|
| 135 |
+ if [ x\$feature_all_video_module = xy ]; then |
|
| 136 | 136 |
insmod all_video |
| 137 | 137 |
else |
| 138 | 138 |
insmod efi_gop |
| ... | ... |
@@ -152,51 +155,51 @@ set timeout=5 |
| 152 | 152 |
### END /etc/grub.d/00_header ### |
| 153 | 153 |
|
| 154 | 154 |
### BEGIN /etc/grub.d/10_linux ### |
| 155 |
-menuentry 'GNU/Linux' --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-UUID_PLACEHOLDER' {
|
|
| 155 |
+menuentry 'GNU/Linux' --class gnu-linux --class gnu --class os \$menuentry_id_option 'gnulinux-simple-UUID_PLACEHOLDER' {
|
|
| 156 | 156 |
load_video |
| 157 | 157 |
set gfxpayload=keep |
| 158 | 158 |
insmod gzio |
| 159 | 159 |
insmod part_msdos |
| 160 | 160 |
insmod ext2 |
| 161 | 161 |
set root='hd0,msdos2' |
| 162 |
- if [ x$feature_platform_search_hint = xy ]; then |
|
| 162 |
+ if [ x\$feature_platform_search_hint = xy ]; then |
|
| 163 | 163 |
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 UUID_PLACEHOLDER |
| 164 | 164 |
else |
| 165 | 165 |
search --no-floppy --fs-uuid --set=root UUID_PLACEHOLDER |
| 166 | 166 |
fi |
| 167 |
- echo 'Loading Linux 4.4.8 ...' |
|
| 168 |
- linux /boot/vmlinuz-4.4.8 root=/dev/sda2 ro console=ttyS0,38400n8 |
|
| 167 |
+ echo 'Loading Linux \$photon_linux ...' |
|
| 168 |
+ linux "$BOOT_DIRECTORY"\$photon_linux root=/dev/sda2 ro console=ttyS0,38400n8 |
|
| 169 | 169 |
} |
| 170 |
-submenu 'Advanced options for GNU/Linux' $menuentry_id_option 'gnulinux-advanced-UUID_PLACEHOLDER' {
|
|
| 171 |
- menuentry 'GNU/Linux, with Linux 4.4.8' --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.8-advanced-UUID_PLACEHOLDER' {
|
|
| 170 |
+submenu 'Advanced options for GNU/Linux' \$menuentry_id_option 'gnulinux-advanced-UUID_PLACEHOLDER' {
|
|
| 171 |
+ menuentry 'GNU/Linux, with Linux \$photon_linux' --class gnu-linux --class gnu --class os \$menuentry_id_option 'gnulinux-\$photon_linux-advanced-UUID_PLACEHOLDER' {
|
|
| 172 | 172 |
load_video |
| 173 | 173 |
set gfxpayload=keep |
| 174 | 174 |
insmod gzio |
| 175 | 175 |
insmod part_msdos |
| 176 | 176 |
insmod ext2 |
| 177 | 177 |
set root='hd0,msdos2' |
| 178 |
- if [ x$feature_platform_search_hint = xy ]; then |
|
| 178 |
+ if [ x\$feature_platform_search_hint = xy ]; then |
|
| 179 | 179 |
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 UUID_PLACEHOLDER |
| 180 | 180 |
else |
| 181 | 181 |
search --no-floppy --fs-uuid --set=root UUID_PLACEHOLDER |
| 182 | 182 |
fi |
| 183 |
- echo 'Loading Linux 4.4.8 ...' |
|
| 184 |
- linux /boot/vmlinuz-4.4.8 root=/dev/sda2 ro console=ttyS0,38400n8 |
|
| 183 |
+ echo 'Loading Linux \$photon_linux ...' |
|
| 184 |
+ linux "$BOOT_DIRECTORY"\$photon_linux root=/dev/sda2 ro console=ttyS0,38400n8 |
|
| 185 | 185 |
} |
| 186 |
- menuentry 'GNU/Linux, with Linux 4.4.8 (recovery mode)' --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.8-recovery-UUID_PLACEHOLDER' {
|
|
| 186 |
+ menuentry 'GNU/Linux, with Linux \$photon_linux (recovery mode)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'gnulinux-\$photon_linux-recovery-UUID_PLACEHOLDER' {
|
|
| 187 | 187 |
load_video |
| 188 | 188 |
set gfxpayload=keep |
| 189 | 189 |
insmod gzio |
| 190 | 190 |
insmod part_msdos |
| 191 | 191 |
insmod ext2 |
| 192 | 192 |
set root='hd0,msdos2' |
| 193 |
- if [ x$feature_platform_search_hint = xy ]; then |
|
| 193 |
+ if [ x\$feature_platform_search_hint = xy ]; then |
|
| 194 | 194 |
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 UUID_PLACEHOLDER |
| 195 | 195 |
else |
| 196 | 196 |
search --no-floppy --fs-uuid --set=root UUID_PLACEHOLDER |
| 197 | 197 |
fi |
| 198 |
- echo 'Loading Linux 4.4.8 ...' |
|
| 199 |
- linux /boot/vmlinuz-4.4.8 root=/dev/sda2 ro single console=ttyS0,38400n8 |
|
| 198 |
+ echo 'Loading Linux \$photon_linux ...' |
|
| 199 |
+ linux "$BOOT_DIRECTORY"\$photon_linux root=/dev/sda2 ro single console=ttyS0,38400n8 |
|
| 200 | 200 |
} |
| 201 | 201 |
} |
| 202 | 202 |
|
| ... | ... |
@@ -216,17 +219,17 @@ submenu 'Advanced options for GNU/Linux' $menuentry_id_option 'gnulinux-advanced |
| 216 | 216 |
### END /etc/grub.d/40_custom ### |
| 217 | 217 |
|
| 218 | 218 |
### BEGIN /etc/grub.d/41_custom ### |
| 219 |
-if [ -f ${config_directory}/custom.cfg ]; then
|
|
| 220 |
- source ${config_directory}/custom.cfg
|
|
| 221 |
-elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then
|
|
| 222 |
- source $prefix/custom.cfg; |
|
| 219 |
+if [ -f \${config_directory}/custom.cfg ]; then
|
|
| 220 |
+ source \${config_directory}/custom.cfg
|
|
| 221 |
+elif [ -z "\${config_directory}" -a -f \$prefix/custom.cfg ]; then
|
|
| 222 |
+ source \$prefix/custom.cfg; |
|
| 223 | 223 |
fi |
| 224 | 224 |
### END /etc/grub.d/41_custom ### |
| 225 | 225 |
|
| 226 | 226 |
# End /boot/grub2/grub.cfg |
| 227 | 227 |
EOF |
| 228 | 228 |
|
| 229 |
-sed -i "s/UUID_PLACEHOLDER/$UUID/" "$BUILDROOT"/boot/grub2/grub.cfg > ${LOGFILE}
|
|
| 229 |
+sed -i "s/UUID_PLACEHOLDER/$UUID_VAL/" "$BUILDROOT"/boot/grub2/grub.cfg > ${LOGFILE}
|
|
| 230 | 230 |
|
| 231 | 231 |
#Cleanup the workspace directory |
| 232 | 232 |
#find "$BUILDROOT"/{,usr/}{lib,bin,sbin} -type f -exec strip --strip-debug --strip-unneeded '{}' ';' > /dev/null 2>&1
|
| 233 | 233 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,12 @@ |
| 0 |
+[Unit] |
|
| 1 |
+Description=Network Time Service |
|
| 2 |
+After=network.target nss-lookup.target |
|
| 3 |
+ |
|
| 4 |
+[Service] |
|
| 5 |
+Type=forking |
|
| 6 |
+PrivateTmp=true |
|
| 7 |
+ExecStart=/usr/bin/ntpd -g -u ntp:ntp |
|
| 8 |
+Restart=always |
|
| 9 |
+ |
|
| 10 |
+[Install] |
|
| 11 |
+WantedBy=multi-user.target |
| ... | ... |
@@ -1,12 +1,20 @@ |
| 1 | 1 |
{
|
| 2 |
- "hostname": "photon-machine", |
|
| 3 |
- "password": |
|
| 4 |
- {
|
|
| 5 |
- "crypted": false, |
|
| 6 |
- "text": "PASSWORD" |
|
| 7 |
- }, |
|
| 8 |
- "type": "gce", |
|
| 9 |
- "size": {"root": "8", "swap": "0"},
|
|
| 10 |
- "public_key":"<ssh-key-here>" |
|
| 2 |
+ "hostname": "photon-machine", |
|
| 3 |
+ "password": |
|
| 4 |
+ {
|
|
| 5 |
+ "crypted": false, |
|
| 6 |
+ "text": "PASSWORD" |
|
| 7 |
+ }, |
|
| 8 |
+ "type": "gce", |
|
| 9 |
+ "size": {"root": "16", "swap": "0"},
|
|
| 10 |
+ "public_key":"<ssh-key-here>", |
|
| 11 |
+ "postinstallscripts": [ "gce-patch.sh", "../password-expiry.sh" ], |
|
| 12 |
+ "additionalfiles": [ |
|
| 13 |
+ {"cloud-photon.cfg": "/etc/cloud/cloud.cfg"},
|
|
| 14 |
+ {"ntpd.service": "/usr/lib/systemd/system/ntpd.service"},
|
|
| 15 |
+ {"eth0.service": "/usr/lib/systemd/system/eth0.service"}
|
|
| 16 |
+ ], |
|
| 17 |
+ "artifacttype": "tgz", |
|
| 18 |
+ "keeprawdisk": "false" |
|
| 11 | 19 |
} |
| 12 | 20 |
|
| 13 | 21 |
deleted file mode 100755 |
| ... | ... |
@@ -1,127 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
-################################################# |
|
| 3 |
-# Title: mk-setup-grub # |
|
| 4 |
-# Date: 2014-11-26 # |
|
| 5 |
-# Version: 1.0 # |
|
| 6 |
-# Author: sharathg@vmware.com # |
|
| 7 |
-# Options: # |
|
| 8 |
-################################################# |
|
| 9 |
-# Overview |
|
| 10 |
-# This is a precursor for the vmware build system. |
|
| 11 |
-# This assumes that an empty hard disk is attached to the build VM. |
|
| 12 |
-# The path to this empty disk is specified in the HDD variable in config.inc |
|
| 13 |
-# End |
|
| 14 |
-# |
|
| 15 |
-grub_efi_install() |
|
| 16 |
-{
|
|
| 17 |
- mkdir $BUILDROOT/boot/efi |
|
| 18 |
- # |
|
| 19 |
- # if it is a loop device then we should mount the dev mapped boot partition |
|
| 20 |
- # |
|
| 21 |
- if [[ $HDD == *"loop"* ]] |
|
| 22 |
- then |
|
| 23 |
- BOOT_PARTITION=/dev/mapper/`basename ${HDD}`p1
|
|
| 24 |
- else |
|
| 25 |
- BOOT_PARTITION=${HDD}1
|
|
| 26 |
- fi |
|
| 27 |
- mkfs.vfat $BOOT_PARTITION |
|
| 28 |
- mount -t vfat $BOOT_PARTITION $BUILDROOT/boot/efi |
|
| 29 |
- cp boot/unifont.pf2 /usr/share/grub/ |
|
| 30 |
- grub2-efi-install --target=x86_64-efi --efi-directory=$BUILDROOT/boot/efi --bootloader-id=Boot --root-directory=$BUILDROOT --recheck |
|
| 31 |
- rm $BUILDROOT/boot/efi/EFI/Boot/grubx64.efi |
|
| 32 |
- cp efi/bootx64.efi $BUILDROOT/boot/efi/EFI/Boot/bootx64.efi |
|
| 33 |
- umount $BUILDROOT/boot/efi |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-grub_mbr_install() |
|
| 37 |
-{
|
|
| 38 |
- $grubInstallCmd --force --boot-directory=$BUILDROOT/boot "$HDD" |
|
| 39 |
-} |
|
| 40 |
- |
|
| 41 |
-set -o errexit # exit if error...insurance ;) |
|
| 42 |
-set -o nounset # exit if variable not initalized |
|
| 43 |
-set +h # disable hashall |
|
| 44 |
-set -x |
|
| 45 |
-PRGNAME=${0##*/} # script name minus the path
|
|
| 46 |
-source config.inc # configuration parameters |
|
| 47 |
-source function.inc # commonn functions |
|
| 48 |
-LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}" # set log file name
|
|
| 49 |
-#LOGFILE=/dev/null # uncomment to disable log file |
|
| 50 |
-ARCH=$(uname -m) # host architecture |
|
| 51 |
-[ ${EUID} -eq 0 ] || fail "${PRGNAME}: Need to be root user: FAILURE"
|
|
| 52 |
-> ${LOGFILE} # clear/initialize logfile
|
|
| 53 |
- |
|
| 54 |
-# Check if passing a HDD and partition |
|
| 55 |
-if [ $# -eq 5 ] |
|
| 56 |
- then |
|
| 57 |
- BOOTMODE=$1 |
|
| 58 |
- HDD=$2 |
|
| 59 |
- ROOT_PARTITION_PATH=$3 |
|
| 60 |
- BOOT_PARTITION_PATH=$4 |
|
| 61 |
- BOOT_DIRECTORY=$5 |
|
| 62 |
-fi |
|
| 63 |
- |
|
| 64 |
-# |
|
| 65 |
-# Install grub2. |
|
| 66 |
-# |
|
| 67 |
-PARTUUID=$(blkid -s PARTUUID -o value $ROOT_PARTITION_PATH) |
|
| 68 |
-BOOT_UUID=$(blkid -s UUID -o value $BOOT_PARTITION_PATH) |
|
| 69 |
- |
|
| 70 |
- |
|
| 71 |
-grubInstallCmd="" |
|
| 72 |
-mkdir -p $BUILDROOT/boot/grub2 |
|
| 73 |
-ln -sfv grub2 $BUILDROOT/boot/grub |
|
| 74 |
-command -v grub-install >/dev/null 2>&1 && grubInstallCmd="grub-install" && { echo >&2 "Found grub-install"; }
|
|
| 75 |
-command -v grub2-install >/dev/null 2>&1 && grubInstallCmd="grub2-install" && { echo >&2 "Found grub2-install"; }
|
|
| 76 |
-if [ -z $grubInstallCmd ]; then |
|
| 77 |
-echo "Unable to found grub install command" |
|
| 78 |
-exit 1 |
|
| 79 |
-fi |
|
| 80 |
- |
|
| 81 |
-if [ "$BOOTMODE" == "bios" ]; then |
|
| 82 |
- grub_mbr_install |
|
| 83 |
-fi |
|
| 84 |
-if [ "$BOOTMODE" == "efi" ]; then |
|
| 85 |
- grub_efi_install |
|
| 86 |
-fi |
|
| 87 |
- |
|
| 88 |
-cp boot/unifont.pf2 ${BUILDROOT}/boot/grub2/
|
|
| 89 |
-mkdir -p ${BUILDROOT}/boot/grub2/themes/photon
|
|
| 90 |
-cp boot/splash.png ${BUILDROOT}/boot/grub2/themes/photon/photon.png
|
|
| 91 |
-cp boot/terminal_*.tga ${BUILDROOT}/boot/grub2/themes/photon/
|
|
| 92 |
-cp boot/theme.txt ${BUILDROOT}/boot/grub2/themes/photon/
|
|
| 93 |
-cat > "$BUILDROOT"/boot/grub2/grub.cfg << "EOF" |
|
| 94 |
-# Begin /boot/grub2/grub.cfg |
|
| 95 |
-set default=0 |
|
| 96 |
-set timeout=5 |
|
| 97 |
-set root=(hd0,2) |
|
| 98 |
-loadfont /boot/grub2/unifont.pf2 |
|
| 99 |
- |
|
| 100 |
-insmod gfxterm |
|
| 101 |
-insmod vbe |
|
| 102 |
-insmod tga |
|
| 103 |
-insmod png |
|
| 104 |
- |
|
| 105 |
-set gfxmode="640x480" |
|
| 106 |
-gfxpayload=keep |
|
| 107 |
- |
|
| 108 |
-terminal_output gfxterm |
|
| 109 |
- |
|
| 110 |
-set theme=/boot/grub2/themes/photon/theme.txt |
|
| 111 |
- |
|
| 112 |
-menuentry "Photon" {
|
|
| 113 |
- insmod ext2 |
|
| 114 |
- insmod part_gpt |
|
| 115 |
- linux /boot/vmlinuz-4.4.8 init=/lib/systemd/systemd root=PARTUUID=UUID_PLACEHOLDER loglevel=3 ro |
|
| 116 |
- initrd /boot/initrd.img-no-kmods |
|
| 117 |
-} |
|
| 118 |
-# End /boot/grub2/grub.cfg |
|
| 119 |
-EOF |
|
| 120 |
- |
|
| 121 |
-sed -i "s/UUID_PLACEHOLDER/$PARTUUID/" "$BUILDROOT"/boot/grub2/grub.cfg > ${LOGFILE}
|
|
| 122 |
- |
|
| 123 |
-#Cleanup the workspace directory |
|
| 124 |
-rm -rf "$BUILDROOT"/tools |
|
| 125 |
-rm -rf "$BUILDROOT"/RPMS |
|
| 126 |
- |
|
| 127 |
-#umount $BUILDROOT |
| 96 | 96 |
deleted file mode 100644 |
| ... | ... |
@@ -1,12 +0,0 @@ |
| 1 |
-[Unit] |
|
| 2 |
-Description=Network Time Service |
|
| 3 |
-After=network.target nss-lookup.target |
|
| 4 |
- |
|
| 5 |
-[Service] |
|
| 6 |
-Type=forking |
|
| 7 |
-PrivateTmp=true |
|
| 8 |
-ExecStart=/usr/bin/ntpd -g -u ntp:ntp |
|
| 9 |
-Restart=always |
|
| 10 |
- |
|
| 11 |
-[Install] |
|
| 12 |
-WantedBy=multi-user.target |
| 13 | 1 |
deleted file mode 100755 |
| ... | ... |
@@ -1,94 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
-set -x |
|
| 3 |
-PHOTON_IMG_OUTPUT_PATH=$1 |
|
| 4 |
-SRC_ROOT=$2 |
|
| 5 |
- |
|
| 6 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/*.vmdk |
|
| 7 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/*.ova |
|
| 8 |
- |
|
| 9 |
-#Generate two ova images one with a random password and the other with a defined password |
|
| 10 |
- |
|
| 11 |
-sed "s|VMDK_IMAGE|$PHOTON_IMG_OUTPUT_PATH/photon-ova.vmdk|" vmx-template > /tmp/vmx-temp.vmx |
|
| 12 |
-sed "s|VMDK_IMAGE|$PHOTON_IMG_OUTPUT_PATH/photon-custom.vmdk|" vmx-template > /tmp/vmx-temp-custom.vmx |
|
| 13 |
- |
|
| 14 |
-cp ../update_custom_password.py $PHOTON_IMG_OUTPUT_PATH/ |
|
| 15 |
- |
|
| 16 |
-$SRC_ROOT/tools/bin/vixdiskutil -convert $PHOTON_IMG_OUTPUT_PATH/photon-ova.raw -cap 16000 $PHOTON_IMG_OUTPUT_PATH/photon-ova.vmdk |
|
| 17 |
-$SRC_ROOT/tools/bin/vixdiskutil -wmeta toolsVersion 2147483647 $PHOTON_IMG_OUTPUT_PATH/photon-ova.vmdk |
|
| 18 |
- |
|
| 19 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 20 |
- |
|
| 21 |
-mkdir -p $PHOTON_IMG_OUTPUT_PATH/temp |
|
| 22 |
-ovftool /tmp/vmx-temp.vmx $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova.ovf |
|
| 23 |
-cd $PHOTON_IMG_OUTPUT_PATH/temp |
|
| 24 |
- |
|
| 25 |
-sed -i "s/otherGuest/other3xLinux64Guest/g" $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova.ovf |
|
| 26 |
-#Add product info |
|
| 27 |
-sed -i '/\/VirtualSystem>/i \ \t<ProductSection> \n \t\t<Info>Information about the installed software</Info> \n \t\t<Product>Photon</Product> \n \t\t<Vendor>VMware Inc.</Vendor> \n \t\t<Version>1.0</Version> \n \t\t<FullVersion>1.0</FullVersion> \n \t</ProductSection> ' $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova.ovf |
|
| 28 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova.mf |
|
| 29 |
-openssl sha1 *.vmdk photon-ova.ovf > photon-ova.mf |
|
| 30 |
-tar cf photon-ova-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova photon-ova.ovf photon-ova.mf photon-ova-disk1.vmdk |
|
| 31 |
-mv $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova $PHOTON_IMG_OUTPUT_PATH/ |
|
| 32 |
- |
|
| 33 |
-#generate a second ova with lower hardware version |
|
| 34 |
-cp photon-ova.ovf photon-ova-hw10.ovf |
|
| 35 |
-sed -i 's/vmx-11/vmx-10/g' photon-ova-hw10.ovf |
|
| 36 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova.mf |
|
| 37 |
-openssl sha1 *.vmdk photon-ova-hw10.ovf > photon-ova-hw10.mf |
|
| 38 |
-tar cf photon-ova-hw10-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova photon-ova-hw10.ovf photon-ova-hw10.mf photon-ova-disk1.vmdk |
|
| 39 |
-mv $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-hw10-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova $PHOTON_IMG_OUTPUT_PATH/ |
|
| 40 |
- |
|
| 41 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 42 |
-rm -rf photon-custom |
|
| 43 |
-DISK_DEVICE=`losetup --show -f ${PHOTON_IMG_OUTPUT_PATH}/photon-ova.raw`
|
|
| 44 |
-kpartx -av $DISK_DEVICE |
|
| 45 |
- |
|
| 46 |
-DEVICE_NAME=`echo $DISK_DEVICE|cut -c6- ` |
|
| 47 |
- |
|
| 48 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-custom |
|
| 49 |
-mkdir $PHOTON_IMG_OUTPUT_PATH/photon-custom |
|
| 50 |
- |
|
| 51 |
-mount -v -t ext4 /dev/mapper/${DEVICE_NAME}p2 $PHOTON_IMG_OUTPUT_PATH/photon-custom
|
|
| 52 |
-#The defined password is 'changeme' |
|
| 53 |
-cp $PHOTON_IMG_OUTPUT_PATH/photon-custom/etc/shadow $PHOTON_IMG_OUTPUT_PATH/photon-custom/etc/shadow.bak |
|
| 54 |
-sed -e "s/^\(root:\)[^:]*:/\1x:/" $PHOTON_IMG_OUTPUT_PATH/photon-custom/etc/shadow.bak > $PHOTON_IMG_OUTPUT_PATH/photon-custom/etc/shadow |
|
| 55 |
-./update_custom_password.py changeme $PHOTON_IMG_OUTPUT_PATH/photon-custom |
|
| 56 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-custom/etc/shadow- |
|
| 57 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-custom/etc/shadow.bak |
|
| 58 |
-# Force immediate password expiry |
|
| 59 |
-chroot $PHOTON_IMG_OUTPUT_PATH/photon-custom /bin/bash -c "chage -d 0 root" |
|
| 60 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-custom |
|
| 61 |
-kpartx -d $DISK_DEVICE |
|
| 62 |
- |
|
| 63 |
-rm -rf photon-custom |
|
| 64 |
- |
|
| 65 |
-echo "Detaching loop device from raw disk" |
|
| 66 |
-losetup -d $DISK_DEVICE |
|
| 67 |
- |
|
| 68 |
-$SRC_ROOT/tools/bin/vixdiskutil -convert $PHOTON_IMG_OUTPUT_PATH/photon-ova.raw -cap 16000 $PHOTON_IMG_OUTPUT_PATH/photon-custom.vmdk |
|
| 69 |
- |
|
| 70 |
-$SRC_ROOT/tools/bin/vixdiskutil -wmeta toolsVersion 2147483647 $PHOTON_IMG_OUTPUT_PATH/photon-custom.vmdk |
|
| 71 |
- |
|
| 72 |
-mkdir -p $PHOTON_IMG_OUTPUT_PATH/temp1 |
|
| 73 |
-ovftool /tmp/vmx-temp-custom.vmx $PHOTON_IMG_OUTPUT_PATH/temp1/photon-custom.ovf |
|
| 74 |
-cd $PHOTON_IMG_OUTPUT_PATH/temp1 |
|
| 75 |
-sed -i "s/otherGuest/other3xLinux64Guest/g" $PHOTON_IMG_OUTPUT_PATH/temp1/photon-custom.ovf |
|
| 76 |
-#Add product info |
|
| 77 |
-sed -i '/\/VirtualSystem>/i \ \t<ProductSection> \n \t\t<Info>Information about the installed software</Info> \n \t\t<Product>Photon</Product> \n \t\t<Vendor>VMware Inc.</Vendor> \n \t\t<Version>1.0</Version> \n \t\t<FullVersion>1.0</FullVersion> \n \t</ProductSection> ' $PHOTON_IMG_OUTPUT_PATH/temp1/photon-custom.ovf |
|
| 78 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/temp1/photon-custom.mf |
|
| 79 |
-openssl sha1 *.vmdk photon-custom.ovf > photon-custom.mf |
|
| 80 |
-tar cf photon-custom-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova photon-custom.ovf photon-custom.mf photon-custom-disk1.vmdk |
|
| 81 |
-mv $PHOTON_IMG_OUTPUT_PATH/temp1/photon-custom-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova $PHOTON_IMG_OUTPUT_PATH/ |
|
| 82 |
- |
|
| 83 |
-#generate a second custom ova with lower hardware version |
|
| 84 |
-cp photon-custom.ovf photon-custom-hw10.ovf |
|
| 85 |
-sed -i 's/vmx-11/vmx-10/g' photon-custom-hw10.ovf |
|
| 86 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/temp/photon-custom.mf |
|
| 87 |
-openssl sha1 *.vmdk photon-custom-hw10.ovf > photon-custom-hw10.mf |
|
| 88 |
-tar cf photon-custom-hw10-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova photon-custom-hw10.ovf photon-custom-hw10.mf photon-custom-disk1.vmdk |
|
| 89 |
-mv $PHOTON_IMG_OUTPUT_PATH/temp1/photon-custom-hw10-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova $PHOTON_IMG_OUTPUT_PATH/ |
|
| 90 |
- |
|
| 91 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 92 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/temp/ |
|
| 93 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/temp1/ |
|
| 94 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-ova.raw |
| ... | ... |
@@ -1,12 +1,16 @@ |
| 1 | 1 |
{
|
| 2 |
- "hostname": "photon-machine", |
|
| 3 |
- "password": |
|
| 4 |
- {
|
|
| 5 |
- "crypted": false, |
|
| 6 |
- "text": "PASSWORD" |
|
| 7 |
- }, |
|
| 8 |
- "type": "minimal", |
|
| 9 |
- "size": {"root": "8", "swap": "0"},
|
|
| 10 |
- "public_key":"<ssh-key-here>" |
|
| 2 |
+ "hostname": "photon-machine", |
|
| 3 |
+ "password": |
|
| 4 |
+ {
|
|
| 5 |
+ "crypted": false, |
|
| 6 |
+ "text": "PASSWORD" |
|
| 7 |
+ }, |
|
| 8 |
+ "type": "minimal", |
|
| 9 |
+ "size": { "root": "8", "swap": "0" },
|
|
| 10 |
+ "public_key":"<ssh-key-here>", |
|
| 11 |
+ "customartifacts": { "postinstallscripts": ["ova-custom-patch.sh"] },
|
|
| 12 |
+ "additionalhwversion": [ "10" ], |
|
| 13 |
+ "artifacttype": "ova", |
|
| 14 |
+ "keeprawdisk": "false" |
|
| 11 | 15 |
} |
| 12 | 16 |
|
| 13 | 17 |
deleted file mode 100755 |
| ... | ... |
@@ -1,76 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
-set -x |
|
| 3 |
-PHOTON_IMG_OUTPUT_PATH=$1 |
|
| 4 |
-SRC_ROOT=$2 |
|
| 5 |
- |
|
| 6 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/*.vmdk |
|
| 7 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/*.ova |
|
| 8 |
- |
|
| 9 |
-#Generate two ova images one with a random password and the other with a defined password |
|
| 10 |
- |
|
| 11 |
-sed "s|VMDK_IMAGE|$PHOTON_IMG_OUTPUT_PATH/photon-generic-ova.vmdk|" vmx-generic-template > /tmp/vmx-generic-temp.vmx |
|
| 12 |
-sed "s|VMDK_IMAGE|$PHOTON_IMG_OUTPUT_PATH/photon-generic-custom.vmdk|" vmx-generic-template > /tmp/vmx-generic-temp-custom.vmx |
|
| 13 |
- |
|
| 14 |
-cp ../update_custom_password.py $PHOTON_IMG_OUTPUT_PATH/ |
|
| 15 |
- |
|
| 16 |
-$SRC_ROOT/tools/bin/vixdiskutil -convert $PHOTON_IMG_OUTPUT_PATH/photon-ova_generic.raw -cap 16000 $PHOTON_IMG_OUTPUT_PATH/photon-generic-ova.vmdk |
|
| 17 |
-$SRC_ROOT/tools/bin/vixdiskutil -wmeta toolsVersion 2147483647 $PHOTON_IMG_OUTPUT_PATH/photon-generic-ova.vmdk |
|
| 18 |
- |
|
| 19 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 20 |
- |
|
| 21 |
-mkdir -p $PHOTON_IMG_OUTPUT_PATH/temp |
|
| 22 |
-ovftool /tmp/vmx-generic-temp.vmx $PHOTON_IMG_OUTPUT_PATH/temp/photon-generic-ova.ovf |
|
| 23 |
-cd $PHOTON_IMG_OUTPUT_PATH/temp |
|
| 24 |
- |
|
| 25 |
-sed -i "s/otherGuest/other3xLinux64Guest/g" $PHOTON_IMG_OUTPUT_PATH/temp/photon-generic-ova.ovf |
|
| 26 |
-#Add product info |
|
| 27 |
-sed -i '/\/VirtualSystem>/i \ \t<ProductSection> \n \t\t<Info>Information about the installed software</Info> \n \t\t<Product>Photon</Product> \n \t\t<Vendor>VMware Inc.</Vendor> \n \t\t<Version>1.0.0</Version> \n \t\t<FullVersion>1.0.0-TP2</FullVersion> \n \t</ProductSection> ' $PHOTON_IMG_OUTPUT_PATH/temp/photon-generic-ova.ovf |
|
| 28 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/temp/photon-generic-ova.mf |
|
| 29 |
-openssl sha1 *.vmdk photon-generic-ova.ovf > photon-generic-ova.mf |
|
| 30 |
-tar cf photon-generic-ova-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova photon-generic-ova.ovf photon-generic-ova.mf photon-generic-ova-disk1.vmdk |
|
| 31 |
-mv $PHOTON_IMG_OUTPUT_PATH/temp/photon-generic-ova-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova $PHOTON_IMG_OUTPUT_PATH/ |
|
| 32 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 33 |
-rm -rf photon-generic-custom |
|
| 34 |
-DISK_DEVICE=`losetup --show -f ${PHOTON_IMG_OUTPUT_PATH}/photon-ova_generic.raw`
|
|
| 35 |
-kpartx -av $DISK_DEVICE |
|
| 36 |
- |
|
| 37 |
-DEVICE_NAME=`echo $DISK_DEVICE|cut -c6- ` |
|
| 38 |
- |
|
| 39 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom |
|
| 40 |
-mkdir $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom |
|
| 41 |
- |
|
| 42 |
-mount -v -t ext4 /dev/mapper/${DEVICE_NAME}p2 $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom
|
|
| 43 |
-#The defined password is 'changeme' |
|
| 44 |
-cp $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom/etc/shadow $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom/etc/shadow.bak |
|
| 45 |
-sed -e "s/^\(root:\)[^:]*:/\1x:/" $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom/etc/shadow.bak > $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom/etc/shadow |
|
| 46 |
-./update_custom_password.py changeme $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom |
|
| 47 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom/etc/shadow- |
|
| 48 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom/etc/shadow.bak |
|
| 49 |
-# Force immediate password expiry |
|
| 50 |
-chroot $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom /bin/bash -c "chage -d 0 root" |
|
| 51 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom |
|
| 52 |
-kpartx -d $DISK_DEVICE |
|
| 53 |
- |
|
| 54 |
-rm -rf photon-generic-custom |
|
| 55 |
- |
|
| 56 |
-echo "Detaching loop device from raw disk" |
|
| 57 |
-losetup -d $DISK_DEVICE |
|
| 58 |
- |
|
| 59 |
-$SRC_ROOT/tools/bin/vixdiskutil -convert $PHOTON_IMG_OUTPUT_PATH/photon-ova_generic.raw -cap 16000 $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom.vmdk |
|
| 60 |
- |
|
| 61 |
-$SRC_ROOT/tools/bin/vixdiskutil -wmeta toolsVersion 2147483647 $PHOTON_IMG_OUTPUT_PATH/photon-generic-custom.vmdk |
|
| 62 |
- |
|
| 63 |
-mkdir -p $PHOTON_IMG_OUTPUT_PATH/temp1 |
|
| 64 |
-ovftool /tmp/vmx-generic-temp-custom.vmx $PHOTON_IMG_OUTPUT_PATH/temp1/photon-generic-custom.ovf |
|
| 65 |
-cd $PHOTON_IMG_OUTPUT_PATH/temp1 |
|
| 66 |
-sed -i "s/otherGuest/other3xLinux64Guest/g" $PHOTON_IMG_OUTPUT_PATH/temp1/photon-generic-custom.ovf |
|
| 67 |
-#Add product info |
|
| 68 |
-sed -i '/\/VirtualSystem>/i \ \t<ProductSection> \n \t\t<Info>Information about the installed software</Info> \n \t\t<Product>Photon</Product> \n \t\t<Vendor>VMware Inc.</Vendor> \n \t\t<Version>1.0.0</Version> \n \t\t<FullVersion>1.0.0-TP2</FullVersion> \n \t</ProductSection> ' $PHOTON_IMG_OUTPUT_PATH/temp1/photon-generic-custom.ovf |
|
| 69 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/temp1/photon-generic-custom.mf |
|
| 70 |
-openssl sha1 *.vmdk photon-generic-custom.ovf > photon-generic-custom.mf |
|
| 71 |
-tar cf photon-generic-custom-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova photon-generic-custom.ovf photon-generic-custom.mf photon-generic-custom-disk1.vmdk |
|
| 72 |
-mv $PHOTON_IMG_OUTPUT_PATH/temp1/photon-generic-custom-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova $PHOTON_IMG_OUTPUT_PATH/ |
|
| 73 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 74 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/temp/ |
|
| 75 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/temp1/ |
|
| 76 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-ova_generic.raw |
| ... | ... |
@@ -7,6 +7,9 @@ |
| 7 | 7 |
}, |
| 8 | 8 |
"type": "minimal", |
| 9 | 9 |
"size": {"root": "8", "swap": "0"},
|
| 10 |
- "public_key":"<ssh-key-here>" |
|
| 10 |
+ "public_key":"<ssh-key-here>", |
|
| 11 |
+ "customartifacts": { "postinstallscripts": ["ova_generic-custom-patch.sh"] },
|
|
| 12 |
+ "artifacttype": "ova", |
|
| 13 |
+ "keeprawdisk": "false" |
|
| 11 | 14 |
} |
| 12 | 15 |
|
| 13 | 16 |
deleted file mode 100644 |
| ... | ... |
@@ -1,22 +0,0 @@ |
| 1 |
-.encoding = "UTF-8" |
|
| 2 |
-virtualHW.version = "10" |
|
| 3 |
-scsi0.present = "TRUE" |
|
| 4 |
-scsi0.virtualDev = "pvscsi" |
|
| 5 |
-scsi0:0.present = "TRUE" |
|
| 6 |
-scsi0:0.fileName = "VMDK_IMAGE" |
|
| 7 |
-ethernet0.present = "TRUE" |
|
| 8 |
-ethernet0.virtualDev = "vmxnet3" |
|
| 9 |
-ethernet0.wakeOnPcktRcv = "FALSE" |
|
| 10 |
-ethernet0.addressType = "generated" |
|
| 11 |
-ethernet0.linkStatePropagation.enable = "TRUE" |
|
| 12 |
-ethernet0.connectionType = "None" |
|
| 13 |
-displayName = "Photon" |
|
| 14 |
-guestOS = "*other26xLinux64Guest" |
|
| 15 |
-memsize = "2048" |
|
| 16 |
-ide1:0.present = "TRUE" |
|
| 17 |
-ide1:0.autodetect = "TRUE" |
|
| 18 |
-ide1:0.deviceType = "cdrom-raw" |
|
| 19 |
-ide1:0.startConnected = "FALSE" |
|
| 20 |
- |
|
| 21 |
- |
|
| 22 |
- |
| 23 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 0 |
+.encoding = "UTF-8" |
|
| 1 |
+virtualHW.version = "10" |
|
| 2 |
+scsi0.present = "TRUE" |
|
| 3 |
+scsi0.virtualDev = "pvscsi" |
|
| 4 |
+scsi0:0.present = "TRUE" |
|
| 5 |
+scsi0:0.fileName = "VMDK_IMAGE" |
|
| 6 |
+ethernet0.present = "TRUE" |
|
| 7 |
+ethernet0.virtualDev = "vmxnet3" |
|
| 8 |
+ethernet0.wakeOnPcktRcv = "FALSE" |
|
| 9 |
+ethernet0.addressType = "generated" |
|
| 10 |
+ethernet0.linkStatePropagation.enable = "TRUE" |
|
| 11 |
+ethernet0.connectionType = "None" |
|
| 12 |
+displayName = "Photon" |
|
| 13 |
+guestOS = "*other26xLinux64Guest" |
|
| 14 |
+memsize = "2048" |
|
| 15 |
+ide1:0.present = "TRUE" |
|
| 16 |
+ide1:0.autodetect = "TRUE" |
|
| 17 |
+ide1:0.deviceType = "cdrom-raw" |
|
| 18 |
+ide1:0.startConnected = "FALSE" |
|
| 19 |
+ |
|
| 20 |
+ |
|
| 21 |
+ |
| 0 | 22 |
deleted file mode 100755 |
| ... | ... |
@@ -1,60 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
-set -x |
|
| 3 |
-PHOTON_IMG_OUTPUT_PATH=$1 |
|
| 4 |
-SRC_ROOT=$2 |
|
| 5 |
- |
|
| 6 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/*.vmdk |
|
| 7 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/*.ova |
|
| 8 |
-sed "s|VMDK_IMAGE|$PHOTON_IMG_OUTPUT_PATH/photon-ova-ovs.vmdk|" vmx-ovs-template > /tmp/vmx-temp-ovs.vmx |
|
| 9 |
- |
|
| 10 |
-cp ../update_custom_password.py $PHOTON_IMG_OUTPUT_PATH/ |
|
| 11 |
- |
|
| 12 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 13 |
- |
|
| 14 |
-DISK_DEVICE=`losetup --show -f ${PHOTON_IMG_OUTPUT_PATH}/photon-ova_ovs.raw`
|
|
| 15 |
-echo "Mapping device partition to loop device" |
|
| 16 |
-kpartx -av $DISK_DEVICE |
|
| 17 |
-DEVICE_NAME=`echo $DISK_DEVICE|cut -c6- ` |
|
| 18 |
-echo "DISK_DEVICE=$DISK_DEVICE" |
|
| 19 |
-echo "ROOT_PARTITION=/dev/mapper/${DEVICE_NAME}p2"
|
|
| 20 |
- |
|
| 21 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs |
|
| 22 |
-mkdir $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs |
|
| 23 |
- |
|
| 24 |
-mount -v -t ext4 /dev/mapper/${DEVICE_NAME}p2 $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs
|
|
| 25 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs/etc/systemd/system/multi-user.target.wants/cloud-* |
|
| 26 |
-cp $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs/etc/shadow $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs/etc/shadow.bak |
|
| 27 |
-sed -e "s/^\(root:\)[^:]*:/\1x:/" $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs/etc/shadow.bak > $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs/etc/shadow |
|
| 28 |
-./update_custom_password.py ovs $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs |
|
| 29 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs/etc/shadow- |
|
| 30 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs/etc/shadow.bak |
|
| 31 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs |
|
| 32 |
- |
|
| 33 |
-echo "Deleting device map partition" |
|
| 34 |
-kpartx -d $DISK_DEVICE |
|
| 35 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs |
|
| 36 |
-echo "Detaching loop device from raw disk" |
|
| 37 |
-losetup -d $DISK_DEVICE |
|
| 38 |
- |
|
| 39 |
- |
|
| 40 |
-$SRC_ROOT/tools/bin/vixdiskutil -convert $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs.raw -cap 16000 $PHOTON_IMG_OUTPUT_PATH/photon-ova-ovs.vmdk |
|
| 41 |
-$SRC_ROOT/tools/bin/vixdiskutil -wmeta toolsVersion 2147483647 $PHOTON_IMG_OUTPUT_PATH/photon-ova-ovs.vmdk |
|
| 42 |
- |
|
| 43 |
-mkdir -p $PHOTON_IMG_OUTPUT_PATH/temp |
|
| 44 |
-ovftool /tmp/vmx-temp-ovs.vmx $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-ovs.ovf |
|
| 45 |
-cd $PHOTON_IMG_OUTPUT_PATH/temp |
|
| 46 |
- |
|
| 47 |
-sed -i "s/otherGuest/other3xLinux64Guest/g" $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-ovs.ovf |
|
| 48 |
-#disable pcibridge and add uefi metadata |
|
| 49 |
-#sed -i '/vmw:value="efi"\/>/a \ \t<vmw:ExtraConfig ovf:required="false" vmw:key="uefi.secureBoot.enabled" vmw:value="TRUE"/>\n \ \t<vmw:ExtraConfig ovf:required="false" vmw:key="pciBridge5.present" vmw:value="false"/>\n \ \t<vmw:ExtraConfig ovf:required="false" vmw:key="pciBridge6.present" vmw:value="false"/>\n \ \t<vmw:ExtraConfig ovf:required="false" vmw:key="pciBridge7.present" vmw:value="false"/> ' $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-ovs.ovf |
|
| 50 |
-#Add product info |
|
| 51 |
-sed -i '/\/VirtualSystem>/i \ \t<ProductSection> \n \t\t<Info>Information about the installed software</Info> \n \t\t<Product>Photon</Product> \n \t\t<Vendor>VMware Inc.</Vendor> \n \t\t<Version>1.0.0</Version> \n \t\t<FullVersion>1.0.0-TP3</FullVersion> \n \t</ProductSection> ' $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-ovs.ovf |
|
| 52 |
- |
|
| 53 |
-openssl sha1 *.vmdk photon-ova-ovs.ovf > photon-ova-ovs.mf |
|
| 54 |
-tar cf photon-ova-ovs-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova photon-ova-ovs.ovf photon-ova-ovs.mf photon-ova-ovs-disk1.vmdk |
|
| 55 |
-mv $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-ovs-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova $PHOTON_IMG_OUTPUT_PATH/ |
|
| 56 |
- |
|
| 57 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/temp/ |
|
| 58 |
- |
|
| 59 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-ova_ovs.raw |
|
| 60 |
- |
| 12 | 14 |
deleted file mode 100644 |
| ... | ... |
@@ -1,19 +0,0 @@ |
| 1 |
-.encoding = "UTF-8" |
|
| 2 |
-virtualHW.version = "13" |
|
| 3 |
-scsi0.present = "TRUE" |
|
| 4 |
-scsi0.virtualDev = "pvscsi" |
|
| 5 |
-scsi0:0.present = "TRUE" |
|
| 6 |
-scsi0:0.fileName = "VMDK_IMAGE" |
|
| 7 |
-ethernet0.present = "TRUE" |
|
| 8 |
-ethernet0.virtualDev = "vmxnet3" |
|
| 9 |
-ethernet0.wakeOnPcktRcv = "FALSE" |
|
| 10 |
-ethernet0.addressType = "generated" |
|
| 11 |
-ethernet0.linkStatePropagation.enable = "TRUE" |
|
| 12 |
-ethernet0.connectionType = "None" |
|
| 13 |
-displayName = "Photon" |
|
| 14 |
-guestOS = "*other26xLinux64Guest" |
|
| 15 |
-memsize = "2048" |
|
| 16 |
-ide1:0.present = "TRUE" |
|
| 17 |
-ide1:0.autodetect = "TRUE" |
|
| 18 |
-ide1:0.deviceType = "cdrom-raw" |
|
| 19 |
-ide1:0.startConnected = "FALSE" |
| 20 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,19 @@ |
| 0 |
+.encoding = "UTF-8" |
|
| 1 |
+virtualHW.version = "13" |
|
| 2 |
+scsi0.present = "TRUE" |
|
| 3 |
+scsi0.virtualDev = "pvscsi" |
|
| 4 |
+scsi0:0.present = "TRUE" |
|
| 5 |
+scsi0:0.fileName = "VMDK_IMAGE" |
|
| 6 |
+ethernet0.present = "TRUE" |
|
| 7 |
+ethernet0.virtualDev = "vmxnet3" |
|
| 8 |
+ethernet0.wakeOnPcktRcv = "FALSE" |
|
| 9 |
+ethernet0.addressType = "generated" |
|
| 10 |
+ethernet0.linkStatePropagation.enable = "TRUE" |
|
| 11 |
+ethernet0.connectionType = "None" |
|
| 12 |
+displayName = "Photon" |
|
| 13 |
+guestOS = "*other26xLinux64Guest" |
|
| 14 |
+memsize = "2048" |
|
| 15 |
+ide1:0.present = "TRUE" |
|
| 16 |
+ide1:0.autodetect = "TRUE" |
|
| 17 |
+ide1:0.deviceType = "cdrom-raw" |
|
| 18 |
+ide1:0.startConnected = "FALSE" |
| 0 | 19 |
deleted file mode 100755 |
| ... | ... |
@@ -1,59 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
-set -x |
|
| 3 |
-PHOTON_IMG_OUTPUT_PATH=$1 |
|
| 4 |
-SRC_ROOT=$2 |
|
| 5 |
- |
|
| 6 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/*.vmdk |
|
| 7 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/*.ova |
|
| 8 |
-sed "s|VMDK_IMAGE|$PHOTON_IMG_OUTPUT_PATH/photon-ova-uefi.vmdk|" vmx-uefi-template > /tmp/vmx-temp-uefi.vmx |
|
| 9 |
- |
|
| 10 |
-cd $PHOTON_IMG_OUTPUT_PATH |
|
| 11 |
- |
|
| 12 |
-DISK_DEVICE=`losetup --show -f ${PHOTON_IMG_OUTPUT_PATH}/photon-ova_uefi.raw`
|
|
| 13 |
- |
|
| 14 |
-echo "Mapping device partition to loop device" |
|
| 15 |
-kpartx -av $DISK_DEVICE |
|
| 16 |
- |
|
| 17 |
-DEVICE_NAME=`echo $DISK_DEVICE|cut -c6- ` |
|
| 18 |
- |
|
| 19 |
-echo "DISK_DEVICE=$DISK_DEVICE" |
|
| 20 |
-echo "ROOT_PARTITION=/dev/mapper/${DEVICE_NAME}p2"
|
|
| 21 |
- |
|
| 22 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-ova_uefi |
|
| 23 |
-mkdir $PHOTON_IMG_OUTPUT_PATH/photon-ova_uefi |
|
| 24 |
- |
|
| 25 |
-mount -v -t ext4 /dev/mapper/${DEVICE_NAME}p2 $PHOTON_IMG_OUTPUT_PATH/photon-ova_uefi
|
|
| 26 |
- |
|
| 27 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-ova_uefi/etc/systemd/system/multi-user.target.wants/cloud-* |
|
| 28 |
- |
|
| 29 |
-umount $PHOTON_IMG_OUTPUT_PATH/photon-ova_uefi |
|
| 30 |
- |
|
| 31 |
-echo "Deleting device map partition" |
|
| 32 |
-kpartx -d $DISK_DEVICE |
|
| 33 |
- |
|
| 34 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/photon-ova_uefi |
|
| 35 |
- |
|
| 36 |
-echo "Detaching loop device from raw disk" |
|
| 37 |
-losetup -d $DISK_DEVICE |
|
| 38 |
- |
|
| 39 |
-$SRC_ROOT/tools/bin/vixdiskutil -convert $PHOTON_IMG_OUTPUT_PATH/photon-ova_uefi.raw -cap 16000 $PHOTON_IMG_OUTPUT_PATH/photon-ova-uefi.vmdk |
|
| 40 |
-$SRC_ROOT/tools/bin/vixdiskutil -wmeta toolsVersion 2147483647 $PHOTON_IMG_OUTPUT_PATH/photon-ova-uefi.vmdk |
|
| 41 |
- |
|
| 42 |
-mkdir -p $PHOTON_IMG_OUTPUT_PATH/temp |
|
| 43 |
-ovftool /tmp/vmx-temp-uefi.vmx $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-uefi.ovf |
|
| 44 |
-cd $PHOTON_IMG_OUTPUT_PATH/temp |
|
| 45 |
- |
|
| 46 |
-sed -i "s/otherGuest/other3xLinux64Guest/g" $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-uefi.ovf |
|
| 47 |
-#disable pcibridge and add uefi metadata |
|
| 48 |
-sed -i '/vmw:value="efi"\/>/a \ \t<vmw:ExtraConfig ovf:required="false" vmw:key="uefi.secureBoot.enabled" vmw:value="TRUE"/>\n \ \t<vmw:ExtraConfig ovf:required="false" vmw:key="pciBridge5.present" vmw:value="false"/>\n \ \t<vmw:ExtraConfig ovf:required="false" vmw:key="pciBridge6.present" vmw:value="false"/>\n \ \t<vmw:ExtraConfig ovf:required="false" vmw:key="pciBridge7.present" vmw:value="false"/> ' $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-uefi.ovf |
|
| 49 |
-#Add product info |
|
| 50 |
-sed -i '/\/VirtualSystem>/i \ \t<ProductSection> \n \t\t<Info>Information about the installed software</Info> \n \t\t<Product>Photon</Product> \n \t\t<Vendor>VMware Inc.</Vendor> \n \t\t<Version>1.0.0</Version> \n \t\t<FullVersion>1.0.0-TP2</FullVersion> \n \t</ProductSection> ' $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-uefi.ovf |
|
| 51 |
- |
|
| 52 |
-openssl sha1 *.vmdk photon-ova-uefi.ovf > photon-ova-uefi.mf |
|
| 53 |
-tar cf photon-ova-uefi-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova photon-ova-uefi.ovf photon-ova-uefi.mf photon-ova-uefi-disk1.vmdk |
|
| 54 |
-mv $PHOTON_IMG_OUTPUT_PATH/temp/photon-ova-uefi-$PHOTON_RELEASE_VER-$PHOTON_BUILD_NUM.ova $PHOTON_IMG_OUTPUT_PATH/ |
|
| 55 |
- |
|
| 56 |
-rm -rf $PHOTON_IMG_OUTPUT_PATH/temp/ |
|
| 57 |
- |
|
| 58 |
-rm -f $PHOTON_IMG_OUTPUT_PATH/photon-ova_uefi.raw |
|
| 59 |
- |
| 14 | 16 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 0 |
+.encoding = "UTF-8" |
|
| 1 |
+virtualHW.version = "13" |
|
| 2 |
+scsi0.present = "TRUE" |
|
| 3 |
+scsi0.virtualDev = "pvscsi" |
|
| 4 |
+scsi0:0.present = "TRUE" |
|
| 5 |
+scsi0:0.fileName = "VMDK_IMAGE" |
|
| 6 |
+ethernet0.present = "TRUE" |
|
| 7 |
+ethernet0.virtualDev = "vmxnet3" |
|
| 8 |
+ethernet0.wakeOnPcktRcv = "FALSE" |
|
| 9 |
+ethernet0.addressType = "generated" |
|
| 10 |
+ethernet0.linkStatePropagation.enable = "TRUE" |
|
| 11 |
+ethernet0.connectionType = "None" |
|
| 12 |
+displayName = "Photon" |
|
| 13 |
+guestOS = "*other26xLinux64Guest" |
|
| 14 |
+memsize = "2048" |
|
| 15 |
+ide1:0.present = "TRUE" |
|
| 16 |
+ide1:0.autodetect = "TRUE" |
|
| 17 |
+ide1:0.deviceType = "cdrom-raw" |
|
| 18 |
+ide1:0.startConnected = "FALSE" |
|
| 19 |
+firmware = "efi" |
|
| 20 |
+ |
|
| 21 |
+ |
|
| 22 |
+ |
| 0 | 23 |
deleted file mode 100644 |
| ... | ... |
@@ -1,23 +0,0 @@ |
| 1 |
-.encoding = "UTF-8" |
|
| 2 |
-virtualHW.version = "13" |
|
| 3 |
-scsi0.present = "TRUE" |
|
| 4 |
-scsi0.virtualDev = "pvscsi" |
|
| 5 |
-scsi0:0.present = "TRUE" |
|
| 6 |
-scsi0:0.fileName = "VMDK_IMAGE" |
|
| 7 |
-ethernet0.present = "TRUE" |
|
| 8 |
-ethernet0.virtualDev = "vmxnet3" |
|
| 9 |
-ethernet0.wakeOnPcktRcv = "FALSE" |
|
| 10 |
-ethernet0.addressType = "generated" |
|
| 11 |
-ethernet0.linkStatePropagation.enable = "TRUE" |
|
| 12 |
-ethernet0.connectionType = "None" |
|
| 13 |
-displayName = "Photon" |
|
| 14 |
-guestOS = "*other26xLinux64Guest" |
|
| 15 |
-memsize = "2048" |
|
| 16 |
-ide1:0.present = "TRUE" |
|
| 17 |
-ide1:0.autodetect = "TRUE" |
|
| 18 |
-ide1:0.deviceType = "cdrom-raw" |
|
| 19 |
-ide1:0.startConnected = "FALSE" |
|
| 20 |
-firmware = "efi" |
|
| 21 |
- |
|
| 22 |
- |
|
| 23 |
- |
| 0 | 4 |
deleted file mode 100755 |
| ... | ... |
@@ -1,32 +0,0 @@ |
| 1 |
-#!/usr/bin/python2 |
|
| 2 |
- |
|
| 3 |
-import os |
|
| 4 |
-import crypt |
|
| 5 |
-import random |
|
| 6 |
-import string |
|
| 7 |
-import sys |
|
| 8 |
-import re |
|
| 9 |
- |
|
| 10 |
- |
|
| 11 |
-def crypt_password(password, root_path): |
|
| 12 |
- shadow_password = crypt.crypt(password, "$6$" + "".join([random.choice(string.ascii_letters + string.digits) for _ in range(16)])) |
|
| 13 |
- |
|
| 14 |
- shadow_filename = os.path.join(root_path, 'etc/shadow') |
|
| 15 |
- |
|
| 16 |
- if os.path.isfile(shadow_filename) == False: |
|
| 17 |
- with open(shadow_filename, "w") as destination: |
|
| 18 |
- destination.write("root:"+shadow_password+":")
|
|
| 19 |
- else: |
|
| 20 |
- #add password hash in shadow file |
|
| 21 |
- with open(shadow_filename, "r") as source: |
|
| 22 |
- lines=source.readlines() |
|
| 23 |
- |
|
| 24 |
- with open(shadow_filename, "w") as destination: |
|
| 25 |
- for line in lines: |
|
| 26 |
- destination.write(re.sub("root:x:", "root:"+shadow_password+":", line))
|
|
| 27 |
- |
|
| 28 |
-if __name__ == '__main__': |
|
| 29 |
- if len(sys.argv) < 3: |
|
| 30 |
- print ("Usage : update_custom_password.py <password> <root_path>")
|
|
| 31 |
- sys.exit(1) |
|
| 32 |
- crypt_password(str(sys.argv[1]), str(sys.argv[2])) |
| 33 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,76 @@ |
| 0 |
+#!/usr/bin/python2 |
|
| 1 |
+ |
|
| 2 |
+import os |
|
| 3 |
+import ctypes |
|
| 4 |
+import ctypes.util |
|
| 5 |
+import json |
|
| 6 |
+import collections |
|
| 7 |
+import subprocess |
|
| 8 |
+import fileinput |
|
| 9 |
+import re |
|
| 10 |
+ |
|
| 11 |
+class Utils(object): |
|
| 12 |
+ def __init__(self): |
|
| 13 |
+ self.filesystems = [] |
|
| 14 |
+ with open('/proc/filesystems') as fs:
|
|
| 15 |
+ for line in fs: |
|
| 16 |
+ self.filesystems.append(line.rstrip('\n').split('\t')[1])
|
|
| 17 |
+ |
|
| 18 |
+ self.libcloader = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
|
|
| 19 |
+ |
|
| 20 |
+ def mount(self, source, destination, filesystem, flags): |
|
| 21 |
+ if not os.access(source, os.R_OK): |
|
| 22 |
+ raise Exception("Could not find path " + source)
|
|
| 23 |
+ if not os.access(destination, os.F_OK): |
|
| 24 |
+ os.mkdir(destination) |
|
| 25 |
+ if not os.access(destination, os.W_OK): |
|
| 26 |
+ raise Exception("Could not write to path " + destination)
|
|
| 27 |
+ if filesystem not in self.filesystems: |
|
| 28 |
+ raise ValueError("Filesystem unknown")
|
|
| 29 |
+ ret = self.libcloader.mount(ctypes.c_char_p(source), |
|
| 30 |
+ ctypes.c_char_p(destination), |
|
| 31 |
+ ctypes.c_char_p(filesystem), |
|
| 32 |
+ ctypes.c_char_p(flags), |
|
| 33 |
+ 0) |
|
| 34 |
+ if ret != 0: |
|
| 35 |
+ raise RuntimeError("Cannot mount {} : {}".format(source, os.strerror(ctypes.get_errno())))
|
|
| 36 |
+ |
|
| 37 |
+ def umount(self, destination): |
|
| 38 |
+ ret = self.libcloader.umount(ctypes.c_char_p(destination)) |
|
| 39 |
+ if ret != 0: |
|
| 40 |
+ raise RuntimeError("Cannot umount {} : {}".format(destination, os.strerror(ctypes.get_errno())))
|
|
| 41 |
+ |
|
| 42 |
+ def jsonread(self, filename): |
|
| 43 |
+ json_data = open(filename) |
|
| 44 |
+ data = json.load(json_data, object_pairs_hook=collections.OrderedDict) |
|
| 45 |
+ json_data.close() |
|
| 46 |
+ return data |
|
| 47 |
+ |
|
| 48 |
+ def runshellcommand(self, cmd, ignore_errors=False): |
|
| 49 |
+ command=cmd.split() |
|
| 50 |
+ p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
| 51 |
+ output, err = p.communicate() |
|
| 52 |
+ rc = p.returncode |
|
| 53 |
+ if not ignore_errors: |
|
| 54 |
+ if rc != 0: |
|
| 55 |
+ print err |
|
| 56 |
+ raise RuntimeError("Cannot run command {}".format(cmd))
|
|
| 57 |
+ return output |
|
| 58 |
+ |
|
| 59 |
+ def replaceinfile(self, filename, pattern, sub): |
|
| 60 |
+ for line in fileinput.input(filename, inplace=True): |
|
| 61 |
+ line = re.sub(pattern, sub, line) |
|
| 62 |
+ print line, |
|
| 63 |
+ |
|
| 64 |
+ def replaceandsaveasnewfile(self, old_file, new_file, pattern, sub): |
|
| 65 |
+ with open(old_file, "r") as old, open(new_file, "w") as new: |
|
| 66 |
+ for line in old: |
|
| 67 |
+ line = re.sub(pattern, sub, line) |
|
| 68 |
+ new.write(line) |
|
| 69 |
+ |
|
| 70 |
+ def copyallfiles(self, src, target): |
|
| 71 |
+ files = os.listdir(src) |
|
| 72 |
+ for file in files: |
|
| 73 |
+ filename = os.path.join(src, file) |
|
| 74 |
+ if (os.path.isfile(filename)): |
|
| 75 |
+ shutil.copy(filename, target) |