Skip to content

Commit

Permalink
20150819
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Dainese committed Aug 19, 2015
1 parent f13affd commit 5cd95cc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.0-67
0.9.0-68
16 changes: 15 additions & 1 deletion html/includes/api_labs.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function apiExportLabs($p) {

// Using "element" relative to "path", adding '/' if missing
$relement = substr($element, strlen($p['path']));
if (!strcmp(substr($relement, 1), '/')) {
if ($relement[0] != '/') {
$relement = '/'.$relement;
}

Expand Down Expand Up @@ -271,6 +271,20 @@ function apiExportLabs($p) {
}
}
}

// Now remove UUID from labs
$cmd = BASE_DIR.'/scripts/remove_uuid.sh "'.$export_file.'"';
exec($cmd, $o, $rc);
if ($rc != 0) {
if (is_file($export_file)) {
unlink($export_file);
}
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][$rc];
return $output;
}

$output['code'] = 200;
$output['status'] = 'success';
$output['message'] = $GLOBALS['messages'][80075];
Expand Down
1 change: 1 addition & 0 deletions html/includes/messages_en.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
$messages[12] = 'Failed to start node (12).';
$messages[13] = 'Unable to wipe node(s) (13).';
$messages[14] = 'Cannot create username (14).';
$messages[15] = 'Cannot remove UUID from exported labs (15).';

/***************************************************************************
* Classes
Expand Down
1 change: 1 addition & 0 deletions scripts/build_deb_unetlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cat html/includes/init.php | sed "s/define('VERSION', .*/define('VERSION', '${VE
cp -a scripts/set_uuid.php ${DATA_DIR}/opt/unetlab/scripts/
cp -a scripts/import_iou-web.php ${DATA_DIR}/opt/unetlab/scripts/
cp -a scripts/fix_iol_nvram.sh ${DATA_DIR}/opt/unetlab/scripts/
cp -a scripts/remove_uuid.sh ${DATA_DIR}/opt/unetlab/scripts/
cp -a IOUtools/iou_export ${DATA_DIR}/opt/unetlab/scripts/
chown -R root:root ${DATA_DIR}/opt/unetlab
chown -R www-data:www-data ${DATA_DIR}/opt/unetlab/data ${DATA_DIR}/opt/unetlab/labs
Expand Down
37 changes: 37 additions & 0 deletions scripts/remove_uuid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

if [ $# -ne 1 ]; then
echo 'ERROR: wrong options given.'
exit 15
fi

if [ ! -f ${1} ]; then
echo 'ERROR: file does not exist.'
exit 15
fi

TEMP=$(mktemp -d --suffix=_unetlab)
unzip -q -o -d ${TEMP} ${1} "*.unl"
if [ $? -ne 0 ]; then
rm -rf ${TEMP}
echo 'ERROR: cannot unzip file.'
exit 15
fi

find ${TEMP} -name "*.unl" -exec sed -i 's/ id="[0-9a-f-]\{36\}"//g' '{}' \;
if [ $? -ne 0 ]; then
rm -rf ${TEMP}
echo 'ERROR: cannot remove lab UUID.'
exit 15
fi

cd ${TEMP}

zip -q -r -u ${1} *
if [ $? -ne 0 ]; then
rm -rf ${TEMP}
echo 'ERROR: cannot update files.'
exit 15
fi

exit 0

0 comments on commit 5cd95cc

Please sign in to comment.