diff --git a/README.md b/README.md index 2c2ccfa4..8ff808ca 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,16 @@ Hello World ``` Note that the Occlum toolchain is not cross-compiling in the traditional sense: the binaries built by the Occlum toolchain is also runnable on Linux. This property makes it convenient to compile, debug, and test user programs intended for Occlum. -**Step 2. Initialize a directory as the Occlum instance via `occlum init`** +**Step 2. Initialize a directory as the Occlum instance via `occlum init` or `occlum new`** ``` $ mkdir occlum_instance && cd occlum_instance $ occlum init ``` -The `occlum init` command creates the compile-time and run-time state of Occlum in the current working directory. Each Occlum instance directory should be used for a single instance of an application; multiple applications or different instances of a single application should use different Occlum instances. +or +``` +$ occlum new occlum_instance +``` +The `occlum init` command creates the compile-time and run-time state of Occlum in the current working directory. The `occlum new` command does basically the same thing but in a new instance diretory. Each Occlum instance directory should be used for a single instance of an application; multiple applications or different instances of a single application should use different Occlum instances. **Step 3. Generate a secure Occlum FS image and Occlum SGX enclave via `occlum build`** ``` diff --git a/src/pal/include/occlum_pal_api.h b/src/pal/include/occlum_pal_api.h index a8f52ecc..2071eb9c 100644 --- a/src/pal/include/occlum_pal_api.h +++ b/src/pal/include/occlum_pal_api.h @@ -21,9 +21,9 @@ int occlum_pal_get_version(void); * Occlum PAL attributes */ typedef struct occlum_pal_attr { - // Occlum instance directory. + // Occlum instance directory. // - // Specifies the path of an Occlum instance directory, which is usually created with the + // Specifies the path of an Occlum instance directory, which is usually created with the // `occlum new` command. The default value is "."; that is, the current working directory // is the Occlum instance directory. const char *instance_dir; diff --git a/tools/occlum b/tools/occlum index 543f4665..81a81d94 100755 --- a/tools/occlum +++ b/tools/occlum @@ -34,8 +34,11 @@ report_arg_error() { echo "" cat < + Create a new directory at and initialize as the Occlum instance. + occlum init - Initialize a directory as the Occlum instance + Initialize a directory as the Occlum instance. occlum build [--sign-key ] [--sign-tool ] [-f/--force] Build and sign an Occlum SGX enclave (.so) and generate its associated secure FS image @@ -70,6 +73,28 @@ check_has_built() { } +cmd_new() { + if [ -z $@ ]; then + echo "Error: target directory is not set" + exit 1 + fi + + dir_path="$@" + if [[ "$dir_path" != "/"* ]]; then + dir_path="$instance_dir/$@" + fi + + if [[ -e "$dir_path" ]]; then + echo "Error: destination \"$dir_path\" already exists" + exit 1 + fi + + mkdir -p $dir_path + instance_dir=$dir_path + status_file=$instance_dir/.__occlum_status + cd $dir_path && cmd_init +} + cmd_init() { if [ -f "$status_file" ]; then echo "Error: the current working directory has been initialized as an Occlum instance" @@ -261,6 +286,9 @@ fi cmd=$1 case "$cmd" in + new) + cmd_new "${@:2:1}" + ;; init) cmd_init ;;