Skip to content

Commit

Permalink
Merge pull request #117 from entelecheia/main
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia authored Mar 16, 2024
2 parents 7cdfb13 + 51aeab2 commit f5e11b6
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<!--next-version-placeholder-->

## v0.37.3 (2024-02-29)

### Fix

* **chezmoi:** Update version retrieval in .chezmoidata.yaml and executable_install-go.tmpl ([`9bd3f86`](https://github.com/entelecheia/dotfiles/commit/9bd3f86e113e159f337c9e04552ec2de16b516e2))

## v0.37.2 (2024-02-28)

### Fix
Expand Down
18 changes: 18 additions & 0 deletions chezmoi/.chezmoi.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@
# {{- $use_code = .code.enabled -}}
# {{- end -}}

# {{- $python_version := or (env "DOTFILES_PYTHON_VERSION") "3.10" -}}
# {{- if and (hasKey . "python") (hasKey .python "version") .python.version -}}
# {{- $python_version = .python.version -}}
# {{- end -}}

# {{- $use_python_tools := true -}}
# {{- if eq (env "DOTFILES_USE_PYTHON_TOOLS") "false" "False" "FALSE" "0" -}}
# {{- $use_python_tools = false -}}
Expand Down Expand Up @@ -979,6 +984,18 @@
# {{- writeToStdout "❎ visual studio code disabled\n" -}}
# {{- end -}}

# {{- if $interactive -}}
# {{- $question := "❔ What version of Python do you want to use" -}}
# {{- $answer := "" -}}
# {{- if $python_version -}}
# {{- $answer = promptString $question $python_version -}}
# {{- else -}}
# {{- $answer = promptString $question -}}
# {{- end -}}
# {{- $python_version = $answer -}}
# {{- end -}}
# {{- writeToStdout (printf "✅ Python version set as '%s'\n" $python_version) -}}

# {{- if $use_python_tools -}}
# {{- writeToStdout "✅ python tools enabled\n" -}}
# {{- else -}}
Expand Down Expand Up @@ -1216,6 +1233,7 @@ data:
install_packages:
user: {{ $pkgs_user }}
python:
version: {{ $python_version | quote }}
tools_enabled: {{ $use_python_tools }}
workon_home: {{ $python_workon_home | quote }}
ruby:
Expand Down
2 changes: 1 addition & 1 deletion chezmoi/.chezmoidata.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DOTFILES_VERSION: 0.37.2
DOTFILES_VERSION: 0.37.3
packages:
- name: 1password-cli
apt: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# {{- if and (eq .chezmoi.os "linux") (.system.apply_rootmoi) (.system.is_sudoer) }}
# {{- template "scripts-library" }}
# {{- template "install-apt-prerequisites" }}
c sudo apt-get install --yes -qq -o=Dpkg::Use-Pty=0 --no-install-recommends "python{{ .python.version }}"
# {{- end }}
10 changes: 7 additions & 3 deletions chezmoi/.chezmoitemplates/install-apt-prerequisites
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ else
echo "${output}"
exit 1
fi
c sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes -qq -o=Dpkg::Use-Pty=0 --no-install-recommends ca-certificates
c sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes -qq -o=Dpkg::Use-Pty=0 --no-install-recommends curl wget gnupg \
c sudo apt-get install --yes -qq -o=Dpkg::Use-Pty=0 --no-install-recommends ca-certificates
c sudo apt-get install --yes -qq -o=Dpkg::Use-Pty=0 --no-install-recommends curl wget gnupg \
software-properties-common zsh locales locales-all jq gettext autoconf apt-transport-https zip bzip2 unzip

# Add APT repositories for newer versions of Git.
Expand All @@ -24,7 +24,11 @@ c sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes -qq -o=Dpkg::Use-Pty
c sudo rm -f etc/apt/sources.list.d/git-core-*.list*
c sudo add-apt-repository ppa:git-core/ppa --yes
c sudo apt-get update --yes
c sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes -qq -o=Dpkg::Use-Pty=0 --no-install-recommends git
c sudo apt-get install --yes -qq -o=Dpkg::Use-Pty=0 --no-install-recommends git

# Add the Deadsnakes PPA for older or newer Python versions.
c sudo add-apt-repository ppa:deadsnakes/ppa --yes
c sudo apt-get update --yes

# Set up locales
# check if locale is already set up by running locale | grep LC_ALL | grep en_US.UTF-8
Expand Down
1 change: 1 addition & 0 deletions chezmoi/dot_config/shrc/00-dotfiles-export.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export WORKSPACE_REFERENCE_DIR="{{ .workspace.reference_dir }}"
export WORKSPACE_CONTAINER_DIR="{{ .workspace.container_dir }}"
export WORKSPACE_MODEL_DIR="{{ .workspace.model_dir }}"
export WORKSPACE_DATASET_DIR="{{ .workspace.dataset_dir }}"
export DOTFILES_PYTHON_VERSION="{{ .python.version }}"

export DOTFILES_USE_CLOUDFLARED="{{ .cloudflared.enabled }}"
export CLOUDFLARED_CONFIG="{{ .cloudflared.config_file }}"
Expand Down
57 changes: 57 additions & 0 deletions chezmoi/dot_local/bin/executable_create-user.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Function to create user and set password
create_user() {
local username=$1
local password=$2

sudo useradd -m -s /bin/bash "$username"
echo "$username:$password" | sudo chpasswd
}

# Function to add user to groups
add_user_to_groups() {
local username=$1
shift
local groups=("$@")

for group in "${groups[@]}"; do
sudo usermod -aG "$group" "$username"
done
}

# Function to create data directory and symlink
create_data_directory() {
local username=$1
local data_root=$2

local data_directory="$data_root/$username"
sudo mkdir -p "$data_directory"
sudo chown "$username:$username" "$data_directory"

local home_directory="/home/$username"
ln -s "$data_directory" "$home_directory/data"
}

# Main script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root or with sudo."
exit 1
fi

read -rp "Enter the username: " username
read -s -rp "Enter the password: " password
echo
read -rp "Enter the groups (separated by space): " -a groups
read -rp "Enter the root directory for data (e.g., /raid/data): " data_root

echo "Creating user $username..."
create_user "$username" "$password"

echo "Adding user $username to groups: ${groups[*]}"
add_user_to_groups "$username" "${groups[@]}"

echo "Creating data directory and symlink for user $username..."
create_data_directory "$username" "$data_root"

echo "User $username created successfully."
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ done
if [[ ${#missing_packages[@]} -gt 0 ]] || [[ ${#upgrade_packages[@]} -gt 0 ]]; then
# This script also gets called when running rootmoi
if [ "$USER" = "root" ]; then
apt_command=(DEBIAN_FRONTEND=noninteractive apt-get)
apt_command=(apt-get)
else
apt_command=(sudo DEBIAN_FRONTEND=noninteractive apt-get)
apt_command=(sudo apt-get)
fi

c "${apt_command[@]}" update --yes -qq -o=Dpkg::Use-Pty=0
Expand Down
54 changes: 54 additions & 0 deletions chezmoi/dot_local/bin/executable_install-python.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Function to install Python dependencies
install_dependencies() {
sudo apt update
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev \
libssl-dev libreadline-dev libffi-dev wget
}

# Function to download and install Python
install_python() {
local python_version=$1
local python_url="https://www.python.org/ftp/python/${python_version}/Python-${python_version}.tgz"

wget "$python_url"
tar -xf "Python-${python_version}.tgz"
cd "Python-${python_version}" || exit

./configure --enable-optimizations
make -j "$(nproc)"
sudo make altinstall

cd ..
rm -rf "Python-${python_version}" "Python-${python_version}.tgz"
}

# Function to update alternatives for Python
update_alternatives() {
local python_version=$1
local python_priority=$2

sudo update-alternatives --install /usr/bin/python python "/usr/local/bin/python${python_version%.*}" "$python_priority"
sudo update-alternatives --install /usr/bin/pip pip "/usr/local/bin/pip${python_version%.*}" "$python_priority"
}

# Main script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root or with sudo."
exit 1
fi

read -rp "Enter the Python version to install (e.g., 3.9.7): " python_version
read -rp "Enter the priority for the Python version (e.g., 1): " python_priority

echo "Installing Python dependencies..."
install_dependencies

echo "Installing Python $python_version..."
install_python "$python_version"

echo "Updating alternatives for Python..."
update_alternatives "$python_version" "$python_priority"

echo "Python $python_version installation completed."
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dotfiles"
version = "0.37.2"
version = "0.37.3"
description = "Easily manage and synchronize your dotfiles across multiple environments with the Dotfiles project, streamlining your development setup and CI/CD pipeline."
authors = ["Young Joon Lee <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit f5e11b6

Please sign in to comment.