Browse Source

exec sg

main
pvincent 9 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>" echo "define lxd and assign to user <$USER>"
sudo groupadd --force "$NEW_GROUP" sudo groupadd --force "$NEW_GROUP"
sudo usermod --append --groups "$NEW_GROUP" "$(whoami)" 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! # no further processing because exec has been called!
else else
echo "user <$USER> already belongs to group <lxd>!" echo "user <$USER> already belongs to group <lxd>!"
@ -49,7 +49,7 @@ function prepare_lxd {
if [[ $(printenv container) == 'lxc' ]]; then if [[ $(printenv container) == 'lxc' ]]; then
echo "nested configuration applying..." echo "nested configuration applying..."
cat <<EOF | lxd init --preseed
cat <<EOF | sg $NEW_GROUP -c 'lxd init --preseed'
config: {} config: {}
networks: networks:
- name: lxdbr0 - name: lxdbr0
@ -57,6 +57,11 @@ networks:
config: config:
ipv4.address: auto ipv4.address: auto
ipv6.address: none ipv6.address: none
storage_pools:
- config: {}
description: ""
name: default
driver: dir
profiles: profiles:
- config: - config:
security.privileged: "true" security.privileged: "true"
@ -135,7 +140,7 @@ EOF
# test environment container hostname # test environment container hostname
local env_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 if [[ -z "$env_container_hostname" ]]; then
env_container_hostname=$(hostname -s) env_container_hostname=$(hostname -s)
if env | grep -q container_hostname; then if env | grep -q container_hostname; then
@ -144,7 +149,7 @@ EOF
fi fi
echo -n "set environment container_hostname to <$env_container_hostname> ... " 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 PREFIX="" echoinfo OK
else else
echo "environment container_hostname <$env_container_hostname> already defined!" echo "environment container_hostname <$env_container_hostname> already defined!"
@ -373,19 +378,19 @@ function preload_bookworm_image {
local PREFIX="preload:bookworm" local PREFIX="preload:bookworm"
if [[ $(lxc image list debian/12/cloud -f csv | wc -l) -lt 1 ]]; then 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 PREFIX="" echoinfo OK
else 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 PREFIX="" echoinfo DONE
fi fi
} }
### MAIN ### MAIN
if [[ "${2:-}" == "SESSION_RELOAD_REQUIRED" ]]; then
if [[ "${1:-}" == "SESSION_RELOAD_REQUIRED" ]]; then
SESSION_RELOAD_REQUIRED=true SESSION_RELOAD_REQUIRED=true
shift shift
else else
@ -426,9 +431,12 @@ else
opt_link opt_link
extra_dev_desktop 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 else
echowarn "please reload your session, .bashrc needs to be reloaded!"
echoinfo "successful installation"
fi fi
fi fi
Loading…
Cancel
Save