-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(brew): Automatically install and maintain brew package list (#347) #348
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,11 @@ if [[ -z "${BREW_ANALYTICS}" || "${BREW_ANALYTICS}" == "null" ]]; then | |
BREW_ANALYTICS=true | ||
fi | ||
|
||
INSTALL_PACKAGES=$(echo "${1}" | yq -I=0 ".install[]") | ||
if [[ -z "${INSTALL_PACKAGES}" || "${INSTALL_PACKAGES}" == "null" ]]; then | ||
INSTALL_PACKAGES=() | ||
fi | ||
|
||
# Create necessary directories | ||
mkdir -p /var/home | ||
mkdir -p /var/roothome | ||
|
@@ -277,4 +282,64 @@ if [[ "${BREW_ANALYTICS}" == false ]]; then | |
fi | ||
fi | ||
|
||
# Create directory for brew configuration | ||
mkdir -p /usr/share/bluebuild/brew | ||
|
||
# Create repo-info.yml file with install packages if specified | ||
if [[ -n "${INSTALL_PACKAGES}" ]]; then | ||
echo "install:" > /usr/share/bluebuild/brew/repo-info.yml | ||
echo "${INSTALL_PACKAGES}" | sed 's/^/ - /' >> /usr/share/bluebuild/brew/repo-info.yml | ||
echo "The following Brew packages will be installed when the system is live:" | ||
echo "${INSTALL_PACKAGES}" | sed 's/^/ - /' | ||
|
||
# Write brew-packages-setup script | ||
cat > /usr/bin/brew-packages-setup <<EOF | ||
Comment on lines
+295
to
+296
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be just a file in the module's directory that is |
||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Source the Brew environment | ||
eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" | ||
|
||
# Install the Brew packages | ||
if [[ -n "\${INSTALL_PACKAGES[@]}" ]]; then | ||
echo "Installing Brew packages..." | ||
for package in "\${INSTALL_PACKAGES[@]}"; do | ||
if ! brew list --formula "\$package" &> /dev/null; then | ||
brew install "\$package" | ||
else | ||
fiftydinar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "Package \$package is already installed." | ||
fi | ||
done | ||
else | ||
echo "No Brew packages specified for installation." | ||
fi | ||
EOF | ||
|
||
chmod +x /usr/bin/brew-packages-setup | ||
|
||
# Write brew-packages-setup service | ||
cat > /usr/lib/systemd/system/brew-packages-setup.service <<EOF | ||
[Unit] | ||
Description=Setup Brew Packages | ||
After=brew-setup.service | ||
Requires=brew-setup.service | ||
ConditionPathExists=!/var/lib/brew-packages-setup.stamp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition makes this execute only once. It should execute every boot, to install packages from updated install list over time. If there are no packages, it will just say To make logs more sane in this scenario (when there are no new packages to install), |
||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/bin/brew-packages-setup | ||
ExecStartPost=/usr/bin/touch /var/lib/brew-packages-setup.stamp | ||
User=1000 | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
EOF | ||
|
||
# Enable the brew-packages-setup service | ||
systemctl enable brew-packages-setup.service | ||
else | ||
echo "No Brew packages specified for installation." | ||
fi | ||
|
||
echo "Brew setup completed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.