1
1
#! /bin/bash
2
2
3
+ # locally build docker name is linuxboot/heads:dev-env
4
+ DOCKER_IMAGE=" linuxboot/heads:dev-env"
5
+
3
6
# Check if Nix is installed
4
- if ! command -v nix & > /dev/null; then
5
- echo " Nix is not installed or not in the PATH. Please install Nix before running this script."
6
- echo " Refer to the README.md at the root of the repository for installation instructions."
7
- exit 1
7
+ if ! command -v nix & > /dev/null; then
8
+ echo " Nix is not installed or not in the PATH. Please install Nix before running this script."
9
+ echo " Refer to the README.md at the root of the repository for installation instructions."
10
+ exit 1
8
11
fi
9
12
10
13
# Check if Docker is installed
11
- if ! command -v docker & > /dev/null; then
12
- echo " Docker is not installed or not in the PATH. Please install Docker before running this script."
13
- echo " Refer to the README.md at the root of the repository for installation instructions."
14
- exit 1
14
+ if ! command -v docker & > /dev/null; then
15
+ echo " Docker is not installed or not in the PATH. Please install Docker before running this script."
16
+ echo " Refer to the README.md at the root of the repository for installation instructions."
17
+ exit 1
15
18
fi
16
19
17
20
# Inform the user about the Docker image being used
18
- echo " ** This ./docker_local_dev.sh script is for developers usage only. ** "
21
+ echo " !!! This ./docker_local_dev.sh script is for developers usage only. !!! "
19
22
echo " "
20
- echo " Using the last locally produced Docker image: linuxboot/heads:dev-env"
21
- echo " Warning: Using anything other than the published Docker image might lead to non-reproducible builds."
23
+ echo " Using the last locally built Docker image when flake.nix/flake.lock was modified and repo was dirty : linuxboot/heads:dev-env"
24
+ echo " !!! Warning: Using anything other than the published Docker image might lead to non-reproducible builds. !!! "
22
25
echo " "
23
26
echo " For using the latest published Docker image, refer to ./docker_latest.sh."
24
27
echo " For producing reproducible builds as CircleCI, refer to ./docker_repro.sh."
25
28
echo " "
26
- echo " ---"
27
29
28
30
# Function to display usage information
29
31
usage () {
30
- echo " Usage: $0 [OPTIONS] -- [COMMAND]"
31
- echo " Options:"
32
- echo " CPUS=N Set the number of CPUs"
33
- echo " V=1 Enable verbose mode"
34
- echo " Command:"
35
- echo " The command to run inside the Docker container, e.g., make BOARD=BOARD_NAME"
32
+ echo " Usage: $0 [OPTIONS] -- [COMMAND]"
33
+ echo " Options:"
34
+ echo " CPUS=N Set the number of CPUs"
35
+ echo " V=1 Enable verbose mode"
36
+ echo " Command:"
37
+ echo " The command to run inside the Docker container, e.g., make BOARD=BOARD_NAME"
36
38
}
37
39
38
40
# Function to kill GPG toolstack related processes using USB devices
39
41
kill_usb_processes () {
40
- echo " Killing any GPG toolstack related processes on host currently using USB devices... "
41
- sudo lsof /dev/bus/usb/00 * /0 * 2> /dev/null | awk ' NR>1 {print $2} ' | xargs -r ps -p | grep -E ' scdaemon|pcscd ' | awk ' {print $1} ' | xargs -r sudo kill -9
42
- if [ $? -ne 0 ] ; then
43
- echo " Failed to kill GPG toolstack related processes using USB devices. Please run the following command manually: "
44
- echo " sudo lsof /dev/bus/usb/00*/0* | awk 'NR>1 {print \ $ 2}' | xargs -r ps -p | grep -E 'scdaemon|pcscd' | awk '{print \ $ 1}' | xargs -r sudo kill -9"
45
- exit 1
46
- fi
42
+ # check if scdaemon or pcscd processes are using USB devices
43
+ if [ -d /dev/bus/usb ] ; then
44
+ if sudo lsof /dev/bus/usb/00 * /0 * 2> /dev/null | awk ' NR>1 {print $2} ' | xargs -r ps -p | grep -E ' scdaemon|pcscd ' > /dev/null ; then
45
+ echo " Killing GPG toolstack related processes using USB devices... "
46
+ sudo lsof /dev/bus/usb/00* /0* 2> /dev/null | awk ' NR>1 {print $2}' | xargs -r ps -p | grep -E ' scdaemon|pcscd' | awk ' {print $1}' | xargs -r sudo kill -9
47
+ fi
48
+ fi
47
49
}
48
50
49
51
# Handle Ctrl-C (SIGINT) to exit gracefully
50
52
trap " echo 'Script interrupted. Exiting...'; exit 1" SIGINT
51
53
52
54
# Check if --help or -h is provided
53
55
for arg in " $@ " ; do
54
- if [[ " $arg " == " --help" || " $arg " == " -h" ]]; then
55
- usage
56
- exit 0
57
- fi
56
+ if [[ " $arg " == " --help" || " $arg " == " -h" ]]; then
57
+ usage
58
+ exit 0
59
+ fi
58
60
done
59
61
60
62
# Check if the git repository is dirty and if flake.nix or flake.lock are part of the uncommitted changes
61
63
if [ -n " $( git status --porcelain | grep -E ' flake\.nix|flake\.lock' ) " ]; then
62
- echo " Warning: Uncommitted changes detected in flake.nix or flake.lock. The Docker image will be rebuilt. "
63
- echo " If this was not intended, please commit your changes and rerun the script."
64
- echo " Building the Docker image from flake.nix..."
65
- nix --print-build-logs --verbose develop --ignore-environment --command true
66
- nix --print-build-logs --verbose build .# dockerImage && docker load < result
64
+ echo " ** Warning: Uncommitted changes detected in flake.nix or flake.lock. The Docker image will be rebuilt!** "
65
+ echo " If this was not intended, please CTRL-C now, commit your changes and rerun the script."
66
+ echo " Building the Docker image from flake.nix..."
67
+ nix --print-build-logs --verbose develop --ignore-environment --command true
68
+ nix --print-build-logs --verbose build .# dockerImage && docker load <result
67
69
else
68
- echo " Git repository is clean. Using the previously built Docker image."
69
- echo " ---"
70
- sleep 1
70
+ echo " Git repository is clean. Using the previously built Docker image when repository was unclean and flake.nix/flake.lock changes were uncommited."
71
+ sleep 1
71
72
fi
72
73
73
74
# Kill processes using USB devices
@@ -77,8 +78,16 @@ kill_usb_processes
77
78
echo " ----"
78
79
echo " Usage reminder: The minimal command is 'make BOARD=XYZ', where additional options, including 'V=1' or 'CPUS=N' are optional."
79
80
echo " For more advanced QEMU testing options, refer to targets/qemu.md and boards/qemu-*/*.config."
81
+ echo
82
+ echo " Type exit within docker image to get back to host if launched interactively!"
80
83
echo " ----"
81
- echo " Entering the Docker container. Type 'exit' to return to the host shell. "
84
+ echo
82
85
83
86
# Execute the docker run command with the provided parameters
84
- docker run --device=/dev/bus/usb:/dev/bus/usb -e DISPLAY=$DISPLAY --network host --rm -ti -v $( pwd) :$( pwd) -w $( pwd) linuxboot/heads:dev-env -- " $@ "
87
+ if [ -d " /dev/bus/usb" ]; then
88
+ echo " --->Launching container with access to host's USB buses (some USB devices were connected to host)..."
89
+ docker run --device=/dev/bus/usb:/dev/bus/usb -e DISPLAY=$DISPLAY --network host --rm -ti -v $( pwd) :$( pwd) -w $( pwd) $DOCKER_IMAGE -- " $@ "
90
+ else
91
+ echo " --->Launching container without access to host's USB buses (no USB devices was connected to host)..."
92
+ docker run -e DISPLAY=$DISPLAY --network host --rm -ti -v $( pwd) :$( pwd) -w $( pwd) $DOCKER_IMAGE -- " $@ "
93
+ fi
0 commit comments