-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply
executable file
·42 lines (34 loc) · 1.26 KB
/
apply
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
set -xeuo pipefail
# This script can be used from a Fedora container to add myself as a user,
# install a few bare neccesities, apply my chezmoi configuration and transform
# into a shell.
SUDO=sudo
if [[ $(id -u) = 0 ]]; then
SUDO=
fi
install_specs=()
for cmd in sudo git passwd tmux; do
if ! command -v "${cmd}" &>/dev/null; then
install_specs+=("/usr/bin/${cmd}")
fi
done
if [ ${#install_specs[@]} -ne 0 ]; then
# minimize impact of crazy rpmmd sizes
disable_repos=(fedora-modular updates-modular fedora-cisco-openh264)
$SUDO dnf install -y "${install_specs[@]}" --disablerepo "$(IFS=, ; echo "${disable_repos[*]}")"
fi
TARGET_USER=$(id -un)
if [[ $TARGET_USER = root ]]; then
useradd -G wheel jlebon
passwd --delete jlebon
TARGET_USER=jlebon
fi
eval "cd ~${TARGET_USER}"
sudo -u "${TARGET_USER}" sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply jlebon
# Assume we're already in a tmux session. This file is used by `.tmux.conf`.
# Ideally we would detect automatically and get rid of this ($TMUX isn't what
# we need, since here we're running in a container).
sudo -u "${TARGET_USER}" touch .tmux.conf.nested
# enter user shell; this ensures a bashrc reload if we're already that user
exec sudo -i -u "${TARGET_USER}"