cranky/startnewrelease: Check before using DEBIAN_MASTER as a directory
In uc20/uc22 packages, although $DEBIAN_MASTER is not empty, we don't
have that directory availiable. Check if the directory really exists
before using it.
Originally, chroot sessions were either `sources` or `configs` in case they needed different sessions, but that has not turned out to be true. Remove the distinction in favor of a single session per series.
Additionally, add the option to specify a user when using `cranky chroot run`, so one can e.g. run as root to install additional packages. Also did some very minor style cleanup.
All `sources|configs` references have been updated in kteam-tools, but read-the-docs still needs to be updated.
## Migrating to the new naming system
Here is a command to remove all the old `sources|configs` sessions. You will need to `cranky chroot create-session <handle>` again.
```bash
for s in $(schroot -l --all-sessions | grep -Po "(?<=session:)cranky-.+-(sources|configs)$"); do schroot -e -c $s; done
```
You can also use this script to automatically remove and recreate the sessions.
```bash
#!/bin/bash
set -e
# get all sessions with the old naming scheme
OLD_SESSIONS=( $(schroot -l --all-sessions | grep -Po "(?<=session:)cranky-.+-(sources|configs)$") )
# get the handles from the old sessions to recreate them
OLD_HANDLES=( $(printf '%s\n' "${OLD_SESSIONS[@]}" | sed -E 's/cranky-(.+)-([a-z0-9]+)-(sources|configs)/\1:linux/') )
for (( i=0; i < ${#OLD_SESSIONS[@]}; ++i )); do
echo "Removing old session ${OLD_SESSIONS[i]}..."
schroot -e -c ${OLD_SESSIONS[i]}
echo "Recreating session for ${OLD_HANDLES[i]}..."
cranky chroot create-session ${OLD_HANDLES[i]}
done
```
Make cranky chroot backwards compatible:
1) If a new session is not found, try to find an old one and operate
on that.
2) Parse the old sources|configs commandline option (but ignore it).
Emit deprecation warnings for the above and add a deprecation notice to
the script usage.
Users can specify chroot session names (appended to the normal chroot
prefixes) using the --which option, like the old <sources|configs>. If
left out, it will create a default session.
The kernel series can be specified with: only the series, the handle,
or a path. If the series is omitted, it tries to infer the series from
the current directory.
Some help messages have been updated accordingly.
https://warthogs.atlassian.net/browse/KERNTT-724
Signed-off-by: Noah Wager <email address hidden>
[juergh: Limited the commit to adding --which commandline argument,
trimmed the commit message.]
Signed-off-by: Juerg Haefliger <email address hidden>
cranky: chroot: add option to run as different user
`cranky chroot run <handle> -u <user> -- <cmd>` will run the commands in
the chroot as the specified user. This is helpful if e.g. you want to
run as root to add packages.
From Juerg Haefliger: cranky chroot splits `sources` and `configs` session
types in case the sessions have differences, but this is not the case.
Remove the separation in favor of a single session per series.