Add demo for shell (FISH) script
This commit is contained in:
parent
5b695c9539
commit
c1911e6585
1191
demos/fish/.config
Normal file
1191
demos/fish/.config
Normal file
File diff suppressed because it is too large
Load Diff
4
demos/fish/.gitignore
vendored
Normal file
4
demos/fish/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
ncurses/
|
||||
fish-shell/
|
||||
busybox/
|
||||
occlum-context/
|
44
demos/fish/Occlum.json
Normal file
44
demos/fish/Occlum.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"vm": {
|
||||
"user_space_size": "512MB"
|
||||
},
|
||||
"process": {
|
||||
"default_stack_size": "4MB",
|
||||
"default_heap_size": "32MB",
|
||||
"default_mmap_size": "80MB"
|
||||
},
|
||||
"env": {
|
||||
"default": [
|
||||
"OCCLUM=yes",
|
||||
"HOME=/root"
|
||||
],
|
||||
"untrusted": [
|
||||
]
|
||||
},
|
||||
"entry_points": [
|
||||
"/bin"
|
||||
],
|
||||
"mount": [
|
||||
{
|
||||
"target": "/",
|
||||
"type": "sefs",
|
||||
"source": "./image",
|
||||
"options": {
|
||||
"integrity_only": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"target": "/root",
|
||||
"type": "sefs"
|
||||
},
|
||||
{
|
||||
"target": "/host",
|
||||
"type": "hostfs",
|
||||
"source": "."
|
||||
},
|
||||
{
|
||||
"target": "/tmp",
|
||||
"type": "ramfs"
|
||||
}
|
||||
]
|
||||
}
|
50
demos/fish/README.md
Normal file
50
demos/fish/README.md
Normal file
@ -0,0 +1,50 @@
|
||||
# Run FISH script on Occlum
|
||||
|
||||
This demo will show Occlum's support in shell script.
|
||||
|
||||
Occlum now only supports FISH (the friendly interactive shell, https://github.com/fish-shell/fish-shell) for now
|
||||
because FISH initially use `posix_spawn()` to create process.
|
||||
|
||||
This shell script works with BusyBox (the Swiss army knife of embedded Linux, https://busybox.net/).
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements
|
||||
for most of the utilities you usually find in GNU fileutils, shellutils, etc.
|
||||
|
||||
This shell script contains executable binaries, pipe symbols and output redirection like this:
|
||||
```
|
||||
busybox echo "Hello-world-from-fish" | busybox awk '$1=$1' FS="-" OFS=" " > /root/output.txt
|
||||
```
|
||||
|
||||
which is defined in `fish_script.sh`. `awk` will replace `-` to `space` and should output result
|
||||
string `Hello world from fish` and store in `/root/output.txt` of Occlum SEFS and can only be read
|
||||
inside Occlum.
|
||||
|
||||
## Step 1:
|
||||
Downlaod FISH and busybox and build them with Occlum tool chain:
|
||||
```
|
||||
./download_and_build.sh
|
||||
```
|
||||
|
||||
## Step 2:
|
||||
Prepare environment by running:
|
||||
```
|
||||
./env_setup.sh
|
||||
```
|
||||
|
||||
If user wants to run this demo on non-SGX platform, run command:
|
||||
```
|
||||
SGX_MODE=SIM ./env_setup.sh
|
||||
```
|
||||
|
||||
## Step 3:
|
||||
Run command to execute script:
|
||||
```
|
||||
cd occlum-context && occlum run /bin/fish /fish_script.sh
|
||||
```
|
||||
|
||||
## Step 4:
|
||||
Go to `occlum-context` and check result by running:
|
||||
```
|
||||
occlum run /bin/busybox cat /root/output.txt
|
||||
```
|
||||
|
||||
And you should see `Hello world from fish`.
|
34
demos/fish/download_and_build.sh
Executable file
34
demos/fish/download_and_build.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# download and install ncurses
|
||||
git clone -b v6.1 --depth 1 https://github.com/mirror/ncurses.git
|
||||
cd ncurses
|
||||
CC=occlum-gcc CXX=occlum-g++ CFLAGS="-O2 -fPIC" CXXFLAGS="-O2 -fPIC" LDFLAGS="-pie" \
|
||||
./configure --without-shared --without-cxx-shared --prefix=/usr/local/occlum --enable-overwrite
|
||||
make && make install
|
||||
cd ..
|
||||
|
||||
# download and build FISH
|
||||
git clone -b 3.1.2 --depth 1 https://github.com/fish-shell/fish-shell.git
|
||||
cd fish-shell
|
||||
git apply ../fish.patch
|
||||
mkdir build && cd build
|
||||
cmake ../ -DCMAKE_BUILD_TYPE=Debug -DCURSES_LIBRARY=/opt/occlum/toolchains/gcc/lib/libcurses.a \
|
||||
-DCMAKE_C_COMPILER=occlum-gcc -DCMAKE_CXX_COMPILER=occlum-g++ \
|
||||
-DCMAKE_CXX_COMPILER_AR=/usr/local/occlum/bin/occlum-ar \
|
||||
-DCMAKE_CXX_COMPILER_RANLIB=/usr/local/occlum/bin/occlum-ranlib \
|
||||
-DCMAKE_C_COMPILER_AR=/usr/local/occlum/bin/occlum-ar \
|
||||
-DCMAKE_C_COMPILER_RANLIB=/usr/local/occlum/bin/occlum-ranlib \
|
||||
-DCMAKE_LINKER=/usr/local/occlum/bin/occlum-ld -DCMAKE_C_FLAGS="-I/usr/local/occlum/include -fpic -pie" \
|
||||
-DCMAKE_CXX_FLAGS="-I/usr/local/occlum/include -fpic -pie"
|
||||
make
|
||||
cd ../../
|
||||
|
||||
# download and build busybox
|
||||
git clone -b 1_31_1 --depth 1 https://github.com/mirror/busybox.git
|
||||
cd busybox
|
||||
CROSS_COMPILE=/opt/occlum/toolchains/gcc/bin/occlum-
|
||||
make CROSS_COMPILE="$CROSS_COMPILE" defconfig
|
||||
cp ../.config .
|
||||
make CROSS_COMPILE="$CROSS_COMPILE"
|
13
demos/fish/env_setup.sh
Executable file
13
demos/fish/env_setup.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
#
|
||||
rm -rf occlum-context
|
||||
mkdir occlum-context && cd occlum-context
|
||||
occlum init
|
||||
cp ../Occlum.json .
|
||||
cp ../fish-shell/build/fish image/bin
|
||||
cp ../busybox/busybox image/bin
|
||||
cp ../fish_script.sh image
|
||||
|
||||
occlum build
|
13
demos/fish/fish.patch
Normal file
13
demos/fish/fish.patch
Normal file
@ -0,0 +1,13 @@
|
||||
diff --git a/src/exec.cpp b/src/exec.cpp
|
||||
index 1557caf0b..254dd0e2e 100644
|
||||
--- a/src/exec.cpp
|
||||
+++ b/src/exec.cpp
|
||||
@@ -565,7 +565,7 @@ static bool exec_external_command(parser_t &parser, const std::shared_ptr<job_t>
|
||||
|
||||
#if FISH_USE_POSIX_SPAWN
|
||||
// Prefer to use posix_spawn, since it's faster on some systems like OS X.
|
||||
- bool use_posix_spawn = g_use_posix_spawn && can_use_posix_spawn_for_job(j, dup2s);
|
||||
+ bool use_posix_spawn = g_use_posix_spawn; //&& can_use_posix_spawn_for_job(j, dup2s);
|
||||
if (use_posix_spawn) {
|
||||
s_fork_count++; // spawn counts as a fork+exec
|
||||
// Create posix spawn attributes and actions.
|
2
demos/fish/fish_script.sh
Normal file
2
demos/fish/fish_script.sh
Normal file
@ -0,0 +1,2 @@
|
||||
#! /bin/fish
|
||||
busybox echo "Hello-world-from-fish" | busybox awk '$1=$1' FS="-" OFS=" " > /root/output.txt
|
@ -70,3 +70,5 @@ chmod +x ${INSTALL_DIR}/bin/occlum-ld
|
||||
# Make symbolic links
|
||||
ln -sf ${INSTALL_DIR}/${TARGET}/lib/libc.so /lib/ld-musl-x86_64.so.1
|
||||
ln -sf ${INSTALL_DIR} /usr/local/occlum
|
||||
ln -sf ${INSTALL_DIR}/bin/x86_64-linux-musl-gcc-ar ${INSTALL_DIR}/bin/occlum-ar
|
||||
ln -sf ${INSTALL_DIR}/bin/x86_64-linux-musl-strip ${INSTALL_DIR}/bin/occlum-strip
|
||||
|
Loading…
Reference in New Issue
Block a user