Compare commits
3 commits
1662776d6b
...
d44d8ddd8c
Author | SHA1 | Date | |
---|---|---|---|
d44d8ddd8c | |||
b2fe707cd4 | |||
57bbb0642b |
2 changed files with 65 additions and 22 deletions
52
Makefile
Normal file
52
Makefile
Normal file
|
@ -0,0 +1,52 @@
|
|||
NAME := qemush
|
||||
|
||||
# qemu Unix user
|
||||
QEMU_USER := qemu
|
||||
# sudo as qemu
|
||||
SUDO_QEMU := sudo -u $(QEMU_USER)
|
||||
|
||||
QEMUSH := /usr/local/bin/$(NAME)
|
||||
SRC_QEMUSH := bin/$(NAME)
|
||||
|
||||
# This repo's equivalent of effective qemu Unix user home
|
||||
SRC_QEMU_HOME := qemu
|
||||
SRC_QEMU_BIN := $(SRC_QEMU_HOME)/bin
|
||||
# Actual qemu Unix user home
|
||||
QEMU_HOME := $(shell echo ~$(QEMU_USER))
|
||||
QEMU_BIN := $(QEMU_HOME)/bin
|
||||
|
||||
# Names of all qemush modules
|
||||
SRC_MODULES_NAMES := $(notdir $(wildcard $(SRC_QEMU_BIN)/*))
|
||||
# Target location of modules
|
||||
MODULES := $(addprefix $(QEMU_BIN)/,$(SRC_MODULES_NAMES))
|
||||
# Mode to apply
|
||||
BINS_MODE := 740
|
||||
|
||||
# Compiler options
|
||||
CC := cc
|
||||
CC_OPTIONS = -O3
|
||||
# C sources file format
|
||||
SRC_FMT := c
|
||||
# Names of C programs to compile
|
||||
SRC_C_SOURCES_NAMES := $(notdir $(basename $(wildcard $(SRCD)/*.$(SRC_FMT))))
|
||||
# Location of C binaries
|
||||
C_BINARIES := $(addprefix $(QEMU_BIN)/,$(SRC_C_SOURCES_NAMES))
|
||||
|
||||
# Directories in ~qemu necessary for qemush to work
|
||||
QEMUSH_DIRS_NAMES := bin launchers images
|
||||
QEMUSH_DIRS := $(addprefix $(QEMU_HOME)/,$(QEMUSH_DIRS_NAMES))
|
||||
|
||||
all: $(QEMUSH_DIRS) $(MODULES) $(C_BINARIES) $(QEMUSH)
|
||||
|
||||
$(QEMUSH_DIRS):
|
||||
$(SUDO_QEMU) mkdir -p $@
|
||||
|
||||
$(QEMUSH): $(SRC_QEMUSH)
|
||||
sudo install -m 755 $^ $@
|
||||
|
||||
$(MODULES): $(QEMU_HOME)%: $(SRC_QEMU_HOME)%
|
||||
$(SUDO_QEMU) install -m $(BINS_MODE) $^ $@
|
||||
|
||||
$(C_BINARIES): $(QEMU_BIN)%: $(SRCD)/%.$(SRC_FMT)
|
||||
$(SUDO_QEMU) $(QEMU_USER) $(CC) $(CC_OPTIONS) -o $@ $^
|
||||
$(SUDO_QEMU) chmod $(BINS_MODE) $@
|
35
README.md
35
README.md
|
@ -75,36 +75,27 @@ For ease of use, you need to grant every user in the `qemu` group via
|
|||
`sudo` the right to execute commands as `qemu`. You can find an example
|
||||
`sudoers` rule in this repo's `etc/sudoers.d` folder.
|
||||
|
||||
### Add `qemush` in the `PATH`
|
||||
### Via `Makefile` (recommended)
|
||||
|
||||
Use your preferred way to add the `qemush` script to a folder of `PATH`.
|
||||
Recommended: copy the script in `/usr/local/bin` to make it effortlessly
|
||||
system wide.
|
||||
|
||||
### Add `qemush` modules in `~qemu/bin`
|
||||
|
||||
`qemush` needs reusable script modules like `diskpath` in its custom `bin`
|
||||
folder located at `~qemu/bin`. You can add them directly via `qemush` from
|
||||
this repo via the following command :
|
||||
Just run the following command at the root of this repository to install
|
||||
`qemush` (previous step is **mandatory**) :
|
||||
|
||||
```sh
|
||||
qemush do 'mkdir -p ~/bin && cp -v qemu/bin/* "$_"'
|
||||
make
|
||||
```
|
||||
|
||||
### Extra: add `first-free-port` in `PATH`
|
||||
> And what if I don't want to bindly run this obscure `Makefile` ???
|
||||
|
||||
`first-free-port` is a small C program designed accordingly to the Unix
|
||||
philosophy to show in `stdout` the first free (not listening) TCP port
|
||||
after `argv[1]`, or `argv[1]` if it is free. You will need it to allocate
|
||||
ports to protocols like SPICE in your launching scripts (example in
|
||||
`qemu/bin/*-spice`).
|
||||
You'd be right. The next section is the exhaustive list of steps handled
|
||||
by the `Makefile` for the installation process.
|
||||
|
||||
Example `qemush` command to add the program to a local `qemu` `bin` folder
|
||||
:
|
||||
### Manual installation (what does the `Makefile` do)
|
||||
|
||||
```sh
|
||||
qemush do 'mkdir ~/bin && cc -o "${_}/first-free-port" src/first-free-port.c'
|
||||
```
|
||||
- Create `images`, `launchers` and `bin` directories in `~qemu`
|
||||
- Copy `qemush` scripts parts from `qemu/bin` in `~qemu/bin` with mode
|
||||
`740`
|
||||
- Compile C programs from `src` in `~qemu/bin` with mode `740`
|
||||
- Copy `bin/qemush` to `/usr/local/bin/qemush` with mode `755`
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
Loading…
Reference in a new issue