Browse Source

exec sg

main
pvincent 7 months ago
parent
commit
13194499f5
  1. 32
      lib/install.sh

32
lib/install.sh

@ -32,7 +32,7 @@ function prepare_lxd {
echo "define lxd and assign to user <$USER>"
sudo groupadd --force "$NEW_GROUP"
sudo usermod --append --groups "$NEW_GROUP" "$(whoami)"
exec sg "$NEW_GROUP" exec "$0 $TARGET SESSION_RELOAD_REQUIRED $@"
exec sg "$NEW_GROUP" -c "$0 SESSION_RELOAD_REQUIRED $TARGET $@"
# no further processing because exec has been called!
else
echo "user <$USER> already belongs to group <lxd>!"
@ -49,7 +49,7 @@ function prepare_lxd {
if [[ $(printenv container) == 'lxc' ]]; then
echo "nested configuration applying..."
cat <<EOF | lxd init --preseed
cat <<EOF | sg $NEW_GROUP -c 'lxd init --preseed'
config: {}
networks:
- name: lxdbr0
@ -57,6 +57,11 @@ networks:
config:
ipv4.address: auto
ipv6.address: none
storage_pools:
- config: {}
description: ""
name: default
driver: dir
profiles:
- config:
security.privileged: "true"
@ -135,7 +140,7 @@ EOF
# test environment container hostname
local env_container_hostname
env_container_hostname=$(lxc profile get default environment.container_hostname)
env_container_hostname=$(sg $NEW_GROUP -c 'lxc profile get default environment.container_hostname')
if [[ -z "$env_container_hostname" ]]; then
env_container_hostname=$(hostname -s)
if env | grep -q container_hostname; then
@ -144,7 +149,7 @@ EOF
fi
echo -n "set environment container_hostname to <$env_container_hostname> ... "
lxc profile set default environment.container_hostname "$env_container_hostname"
sg $NEW_GROUP -c "lxc profile set default environment.container_hostname \"$env_container_hostname\""
PREFIX="" echoinfo OK
else
echo "environment container_hostname <$env_container_hostname> already defined!"
@ -373,19 +378,19 @@ function preload_bookworm_image {
local PREFIX="preload:bookworm"
if [[ $(lxc image list debian/12/cloud -f csv | wc -l) -lt 1 ]]; then
echo -n "downloading images from publc remote, please hold on..."
lxc image copy images:debian/12/cloud local: --copy-aliases --quiet
echo -n "downloading images from public remote, please hold on..."
sg $NEW_GROUP -c 'lxc image copy images:debian/12/cloud local: --copy-aliases --quiet'
PREFIX="" echoinfo OK
else
echo -n "refreshing images from publc remote..."
lxc image refresh debian/12/cloud --quiet
echo -n "refreshing images from public remote..."
sg $NEW_GROUP -c 'lxc image refresh debian/12/cloud --quiet'
PREFIX="" echoinfo DONE
fi
}
### MAIN
if [[ "${2:-}" == "SESSION_RELOAD_REQUIRED" ]]; then
if [[ "${1:-}" == "SESSION_RELOAD_REQUIRED" ]]; then
SESSION_RELOAD_REQUIRED=true
shift
else
@ -426,9 +431,12 @@ else
opt_link
extra_dev_desktop
if [[ "$SESSION_RELOAD_REQUIRED" == false ]]; then
echoinfo "successful installation"
if [[ "$SESSION_RELOAD_REQUIRED" == true ]]; then
echowarn "current session has been reloaded, due to new group <$NEW_GROUP>."
echowarn "be aware to exit twice or fully disconnect/reconnect to take advantage of new group <$NEW_GROUP>!"
echoinfo "successful session installation "
sg $NEW_GROUP -c bash
else
echowarn "please reload your session, .bashrc needs to be reloaded!"
echoinfo "successful installation"
fi
fi
Loading…
Cancel
Save