wip
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
export SSH_AUTH_SOCK=$HOME/.1password/agent.sock
|
||||
|
||||
# Check if is_wsl function returns true, don't continue if we are not on WSL
|
||||
if ! is_wsl; then
|
||||
@ -6,8 +7,6 @@ if ! is_wsl; then
|
||||
fi
|
||||
|
||||
printfe "%s" "cyan" "Running in WSL, ensuring 1Password SSH-Agent relay is running..."
|
||||
|
||||
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
|
||||
ALREADY_RUNNING=$(ps -auxww | grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?)
|
||||
if [[ $ALREADY_RUNNING != "0" ]]; then
|
||||
if [[ -S $SSH_AUTH_SOCK ]]; then
|
||||
|
@ -6,9 +6,6 @@ printfe "%s\n" "cyan" "Exporting GNOME extensions"
|
||||
source $HOME/dotfiles/bin/helpers/gnome_extensions.sh
|
||||
export_gnome_extensions
|
||||
|
||||
printfe "%s\n" "cyan" "Exporting VSCode extensions"
|
||||
code --list-extensions | jq -R -s -c 'split("\n")[:-1]' > ~/dotfiles/vscode/extensions.json
|
||||
|
||||
printfe "%s\n" "cyan" "Exporting gnome-terminal settings"
|
||||
dconf dump /org/gnome/terminal/ > ~/dotfiles/config/gnome-terminal.dconf
|
||||
|
||||
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
x-terminal-emulator -e $HOME/dotfiles/bin/actions/startup.sh $@
|
@ -1,116 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
countdown() {
|
||||
for i in $(seq $1 -1 1); do
|
||||
printfe "%s" "green" " - Waiting for $i seconds... "
|
||||
echo -en "\r"
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
run_startup_scripts() {
|
||||
if is_wsl; then
|
||||
echo "Running in WSL, skipping startup scripts."
|
||||
return
|
||||
fi
|
||||
|
||||
logo continue
|
||||
echo ""
|
||||
local time_of_day
|
||||
# Time of day (morning, afternoon, evening, night)
|
||||
case $(date +%H) in
|
||||
0[0-9]|1[0-1])
|
||||
time_of_day="morning"
|
||||
emoji="🌅"
|
||||
;;
|
||||
1[2-7])
|
||||
time_of_day="afternoon"
|
||||
emoji="🌞"
|
||||
;;
|
||||
1[8-9]|2[0-3])
|
||||
time_of_day="evening"
|
||||
emoji="🌆"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Run the welcome.py from $HOME/dotfiles/bin/helpers/welcome.py
|
||||
python3 $HOME/dotfiles/bin/helpers/welcome.py
|
||||
echo ""
|
||||
|
||||
# Initialize array to hold commands
|
||||
local startup_commands=()
|
||||
|
||||
# Read each command key and add it to the array
|
||||
while IFS= read -r command; do
|
||||
startup_commands+=("$command")
|
||||
done < <(cat $HOME/dotfiles/config/config.yaml | shyaml keys config.startup.commands)
|
||||
|
||||
# Read delay and delay_between_ms values from YAML
|
||||
local delay=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.startup.delay)
|
||||
local delay_between_ms=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.startup.delay_between_ms)
|
||||
|
||||
printfe "%s\n" "cyan" "Running startup commands... (delay: $delay s, delay_between: $delay_between_ms ms)"
|
||||
|
||||
# Wait for the initial delay
|
||||
countdown $delay
|
||||
|
||||
# Ensure the log folder exists
|
||||
mkdir -p $HOME/dotfiles/logs/startup
|
||||
|
||||
# Execute each command in a new screen window
|
||||
for command_key in "${startup_commands[@]}"; do
|
||||
local command=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.startup.commands.$command_key)
|
||||
|
||||
printfe "%s" "green" " - Running '"
|
||||
printfe "%s" "blue" "$command_key"
|
||||
printfe "%s" "green" "'... ("
|
||||
printfe "%s" "blue" "$command"
|
||||
printfe "%s\n" "green" ")"
|
||||
|
||||
# Check if a screen with the same name already exists, if so log it and don't run the command
|
||||
if screen -list | grep -q $command_key; then
|
||||
printfe "%s" "red" " - Screen session already exists: "
|
||||
printfe "%s" "blue" "$command_key"
|
||||
printfe "%s\n" "red" ""
|
||||
continue
|
||||
fi
|
||||
|
||||
# Ensure the log file exists, if it exists, clear it
|
||||
touch $HOME/dotfiles/logs/startup/$command_key.log
|
||||
|
||||
# Run the command in a new screen session named after the command_key
|
||||
screen -dmS $command_key bash -c "eval $command > $HOME/dotfiles/logs/startup/$command_key.log 2>&1"
|
||||
sleep $(echo "scale=2; $delay_between_ms / 1000" | bc)
|
||||
|
||||
if ! screen -list | grep -q $command_key; then
|
||||
printfe "%s" "red" " - Screen session died immediately: "
|
||||
printfe "%s" "blue" "$command_key"
|
||||
printfe "%s\n" "red" " (Within $delay_between_ms ms, check the logs for more information in $HOME/dotfiles/logs/startup/$command_key.log)"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if command is ok, if not log that it failed
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s" "red" " - Command failed: "
|
||||
printfe "%s" "blue" "$command"
|
||||
printfe "%s\n" "red" ""
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Check if we're in a graphical session
|
||||
if [[ -z "$DISPLAY" && "$XDG_SESSION_TYPE" != "x11" && "$XDG_SESSION_TYPE" != "wayland" ]]; then
|
||||
echo "Not in a graphical session. Exiting."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
run_startup_scripts
|
||||
|
||||
echo ""
|
||||
|
||||
# Show message to press any key to close the terminal window
|
||||
printfe "%s\n" "green" "Press any key to close this window..."
|
||||
read -s -n 1
|
||||
exit 0
|
@ -1,12 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
source $HOME/dotfiles/bin/helpers/keyboard_shortcuts.sh
|
||||
source $HOME/dotfiles/bin/helpers/apt_packages.sh
|
||||
source $HOME/dotfiles/bin/helpers/pipx_packages.sh
|
||||
source $HOME/dotfiles/bin/helpers/cargo_packages.sh
|
||||
source $HOME/dotfiles/bin/helpers/flatpak_packages.sh
|
||||
source $HOME/dotfiles/bin/helpers/vscode-extensions.sh
|
||||
source $HOME/dotfiles/bin/helpers/fonts.sh
|
||||
|
||||
# Check if parameter --verbose was passed
|
||||
@ -18,10 +15,7 @@ fi
|
||||
|
||||
echo -e "\n"
|
||||
|
||||
print_keyboard_shortcuts_status
|
||||
print_fonts_status
|
||||
print_apt_status
|
||||
print_pipx_status
|
||||
print_cargo_status
|
||||
print_flatpak_status
|
||||
print_vsc_status
|
||||
|
@ -16,43 +16,33 @@ if [ ! -x "$(command -v shyaml)" ]; then
|
||||
pipx install shyaml
|
||||
fi
|
||||
|
||||
groups() {
|
||||
####################################################################################################
|
||||
# Ensure user groups
|
||||
####################################################################################################
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring user groups..."
|
||||
source $HOME/dotfiles/bin/helpers/user_groups.sh
|
||||
ensure_user_groups
|
||||
}
|
||||
|
||||
ensure_symlink() {
|
||||
local source
|
||||
local target
|
||||
|
||||
# Fetch target from YAML
|
||||
target=$(shyaml get-value "config.symlinks.$1.target" < "$HOME/dotfiles/config/config.yaml") 2>/dev/null
|
||||
target=$(shyaml get-value "config.symlinks.$1.target" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
|
||||
# Fetch source from YAML based on OS
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Check for WSL2
|
||||
if [[ $(uname -a) == *"microsoft-standard-WSL2"* ]]; then
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.wsl" < "$HOME/dotfiles/config/config.yaml") 2>/dev/null
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.wsl" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
else
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.linux" < "$HOME/dotfiles/config/config.yaml") 2>/dev/null
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.linux" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.macos" < "$HOME/dotfiles/config/config.yaml") 2>/dev/null
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.macos" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Fall back to generic source if OS-specific source is empty
|
||||
if [ -z "$source" ]; then
|
||||
source=$(shyaml get-value "config.symlinks.$1.source" < "$HOME/dotfiles/config/config.yaml") 2>/dev/null
|
||||
source=$(shyaml get-value "config.symlinks.$1.source" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Attempt to use the hostname of the machine if source is still empty
|
||||
if [ -z "$source" ]; then
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.$(hostname)" < "$HOME/dotfiles/config/config.yaml") 2>/dev/null
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.$(hostname)" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Error out if source is still empty
|
||||
@ -80,7 +70,7 @@ ensure_symlink() {
|
||||
resolved_target="$target"
|
||||
fi
|
||||
|
||||
current_chmod=$(stat -c %a "$resolved_target")
|
||||
current_chmod=$(stat -c %a "$resolved_target" 2>/dev/null)
|
||||
if [ "$current_chmod" != "$desired_chmod" ]; then
|
||||
printfe "%s\n" "yellow" " - Changing chmod of $resolved_target to $desired_chmod"
|
||||
chmod "$desired_chmod" "$resolved_target"
|
||||
@ -113,6 +103,11 @@ sys_packages() {
|
||||
brew upgrade
|
||||
brew cleanup
|
||||
else
|
||||
if [ -x "$(command -v nixos-version)" ]; then
|
||||
sudo nixos-rebuild switch
|
||||
return
|
||||
fi
|
||||
|
||||
sudo nala upgrade -y
|
||||
sudo nala autoremove -y --purge
|
||||
fi
|
||||
@ -122,26 +117,18 @@ sys_packages() {
|
||||
# Update packages
|
||||
####################################################################################################
|
||||
|
||||
cargopkgs() {
|
||||
printfe "%s\n" "cyan" "Rust update..."
|
||||
source $HOME/dotfiles/bin/helpers/rust.sh
|
||||
ensure_rust_installed
|
||||
|
||||
cargopkgs() {
|
||||
printfe "%s\n" "cyan" "Ensuring Cargo packages are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/cargo_packages.sh
|
||||
ensure_cargo_packages_installed
|
||||
}
|
||||
|
||||
aptpkgs() {
|
||||
printfe "%s\n" "cyan" "Ensuring APT repositories are added..."
|
||||
source $HOME/dotfiles/bin/helpers/apt_packages.sh
|
||||
ensure_repositories
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring APT packages are installed..."
|
||||
ensure_apt_packages_installed
|
||||
}
|
||||
|
||||
pipxpkgs() {
|
||||
if [ ! -x "$(command -v pipx)" ]; then
|
||||
printfe "%s\n" "yellow" "pipx is not available, skipping pipx packages."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring pyenv is installed..."
|
||||
if [ ! -d "$HOME/.pyenv" ]; then
|
||||
curl https://pyenv.run | bash
|
||||
@ -155,6 +142,11 @@ pipxpkgs() {
|
||||
}
|
||||
|
||||
flatpakpkgs() {
|
||||
if [ ! -x "$(command -v flatpak)" ]; then
|
||||
printfe "%s\n" "yellow" "Flatpak is not available, skipping Flatpak."
|
||||
return
|
||||
fi
|
||||
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping Flatpak."
|
||||
return
|
||||
@ -166,6 +158,12 @@ flatpakpkgs() {
|
||||
}
|
||||
|
||||
dockercmd() {
|
||||
# On NixOS this is managed by the docker.nix module
|
||||
if [ -x "$(command -v nixos-version)" ]; then
|
||||
printfe "%s\n" "yellow" "Detected NixOS, skipping Docker."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring Docker is installed..."
|
||||
source $HOME/dotfiles/bin/helpers/docker.sh
|
||||
ensure_docker_installed
|
||||
@ -191,34 +189,12 @@ extensions() {
|
||||
printfe "%s\n" "cyan" "Ensuring GNOME Extensions are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/gnome_extensions.sh
|
||||
ensure_gnome_extensions_installed
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring VSCode extensions are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/vscode-extensions.sh
|
||||
ensure_vscode_extensions_installed
|
||||
|
||||
if [ ! -f "$HOME/.local/share/nemo/actions/vscode.nemo_action" ]; then
|
||||
printfe "%s\n" "cyan" "Ensuring nemo open with VSCode extension is installed..."
|
||||
wget https://raw.githubusercontent.com/mhsattarian/nemo-open-in-vscode/master/vscode.nemo_action -O $HOME/.local/share/nemo/actions/vscode.nemo_action
|
||||
else
|
||||
printfe "%s\n" "green" " - nemo open with VSCode extension is already installed"
|
||||
fi
|
||||
}
|
||||
|
||||
####################################################################################################
|
||||
# Update system settings
|
||||
####################################################################################################
|
||||
|
||||
keyboard() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping keyboard shortcuts."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Setting up keyboard shortcuts..."
|
||||
source $HOME/dotfiles/bin/helpers/keyboard_shortcuts.sh
|
||||
ensure_keyboard_shortcuts
|
||||
}
|
||||
|
||||
fonts() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping fonts."
|
||||
@ -279,12 +255,16 @@ git_repos() {
|
||||
ensure_git_repos
|
||||
}
|
||||
|
||||
homemanager() {
|
||||
home-manager switch
|
||||
}
|
||||
|
||||
####################################################################################################
|
||||
# Parse arguments
|
||||
####################################################################################################
|
||||
|
||||
# Multiple options can be passed to the script, for example:
|
||||
# ./update.sh --verbose --groups --symlinks --packages --keyboard --fonts --default-terminal --default-shell
|
||||
# ./update.sh --git --symlinks --packages
|
||||
# If no options are passed, the script will run all functions
|
||||
|
||||
# Shift the first argument since this is the script name
|
||||
@ -293,45 +273,39 @@ shift
|
||||
if [ "$#" -eq 0 ]; then
|
||||
printfe "%s\n" "yellow" "No options passed, running full update..."
|
||||
|
||||
git_repos
|
||||
groups
|
||||
symlinks
|
||||
sys_packages
|
||||
aptpkgs
|
||||
homemanager
|
||||
cargopkgs
|
||||
pipxpkgs
|
||||
dockercmd
|
||||
git_repos
|
||||
flatpakpkgs
|
||||
tailscalecmd
|
||||
extensions
|
||||
keyboard
|
||||
fonts
|
||||
terminal
|
||||
default_shell
|
||||
else
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--homemanager)
|
||||
homemanager
|
||||
;;
|
||||
--git)
|
||||
git_repos
|
||||
;;
|
||||
--groups)
|
||||
groups
|
||||
;;
|
||||
--symlinks)
|
||||
symlinks
|
||||
;;
|
||||
--packages)
|
||||
sys_packages
|
||||
cargopkgs
|
||||
aptpkgs
|
||||
pipxpkgs
|
||||
flatpakpkgs
|
||||
dockercmd
|
||||
tailscalecmd
|
||||
;;
|
||||
--apt)
|
||||
aptpkgs
|
||||
;;
|
||||
--pipx)
|
||||
pipxpkgs
|
||||
;;
|
||||
@ -350,9 +324,6 @@ else
|
||||
--extensions)
|
||||
extensions
|
||||
;;
|
||||
--keyboard)
|
||||
keyboard
|
||||
;;
|
||||
--fonts)
|
||||
fonts
|
||||
;;
|
||||
|
3
bin/dotf
3
bin/dotf
@ -72,9 +72,6 @@ case $1 in
|
||||
"secrets")
|
||||
secrets $@
|
||||
;;
|
||||
"startup")
|
||||
$HOME/dotfiles/bin/actions/startup-runner.sh $@
|
||||
;;
|
||||
"term")
|
||||
$HOME/dotfiles/bin/actions/term.sh $@
|
||||
;;
|
||||
|
@ -1,163 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
add_brave_repo() {
|
||||
# Check if we have a brave-browser-release.list file already, if not then create one
|
||||
if [ ! -f /etc/apt/sources.list.d/brave-browser-release.list ]; then
|
||||
sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg
|
||||
echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main"|sudo tee /etc/apt/sources.list.d/brave-browser-release.list
|
||||
result=$(sudo apt update 2>&1)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" " - Failed to add Brave repository"
|
||||
printfe "%s\n" "yellow" "$result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printfe "%s\n" "yellow" " - Added Brave repository"
|
||||
else
|
||||
printfe "%s\n" "green" " - Brave repository already added"
|
||||
fi
|
||||
}
|
||||
|
||||
add_1password_repo() {
|
||||
# Check if we have a 1password.list file already, if not then create one
|
||||
if [ ! -f /etc/apt/sources.list.d/1password.list ]; then
|
||||
curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg
|
||||
echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/1password-archive-keyring.gpg] https://downloads.1password.com/linux/debian/amd64 stable main' | sudo tee /etc/apt/sources.list.d/1password.list
|
||||
sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/
|
||||
curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | sudo tee /etc/debsig/policies/AC2D62742012EA22/1password.pol
|
||||
sudo mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22
|
||||
curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg
|
||||
result=$(sudo apt update 2>&1)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" " - Failed to add 1Password repository"
|
||||
printfe "%s\n" "yellow" "$result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printfe "%s\n" "yellow" " - Added 1Password repository"
|
||||
else
|
||||
printfe "%s\n" "green" " - 1Password repository already added"
|
||||
fi
|
||||
}
|
||||
|
||||
add_vscode_repo() {
|
||||
# Check if we have a vscode.list file already, if not then create one
|
||||
if [ ! -f /etc/apt/sources.list.d/vscode.list ]; then
|
||||
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
|
||||
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
|
||||
echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" |sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null
|
||||
rm -f packages.microsoft.gpg
|
||||
result=$(sudo apt update 2>&1)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" " - Failed to add VSCode repository"
|
||||
printfe "%s\n" "yellow" "$result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printfe "%s\n" "yellow" " - Added VSCode repository"
|
||||
else
|
||||
printfe "%s\n" "green" " - VSCode repository already added"
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_repositories() {
|
||||
add_brave_repo
|
||||
add_1password_repo
|
||||
add_vscode_repo
|
||||
|
||||
repos=($(cat $DOTFILES_CONFIG | shyaml get-values config.packages.apt.repos))
|
||||
for repo in "${repos[@]}"; do
|
||||
repo_name=$(echo $repo | cut -d ":" -f 2)
|
||||
|
||||
# Go through sources.list.d and check if there's a file containing part of URIs: https://ppa.launchpad.net/$repo_name
|
||||
# We have to check the files not the file names since the file names are not always the same as the repo_name
|
||||
result=$(grep -r "$repo_name" /etc/apt/sources.list.d/*)
|
||||
if [ -z "$result" ]; then
|
||||
printfe "%s\n" "yellow" " - Adding $repo_name repository..."
|
||||
clear_line
|
||||
|
||||
sudo add-apt-repository -y $repo
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" " - Failed to add $repo_name repository"
|
||||
exit 1
|
||||
else
|
||||
printfe "%s\n" "green" " - $repo_name repository added successfully"
|
||||
fi
|
||||
else
|
||||
printfe "%s\n" "green" " - $repo_name repository already added"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
ensure_apt_packages_installed() {
|
||||
apt_packages=($(cat $DOTFILES_CONFIG | shyaml get-values config.packages.apt.apps | tr '\n' ' '))
|
||||
|
||||
# Check if apt_packages array contains duplicates
|
||||
if [ $(echo $apt_packages | tr ' ' '\n' | sort | uniq -d | wc -l) -ne 0 ]; then
|
||||
printfe "%s\n" "red" "The apt_packages array contains duplicates"
|
||||
printfe "%s\n" "yellow" "Duplicates:"
|
||||
printfe "%s\n" "blue" $(echo $apt_packages | tr ' ' '\n' | sort | uniq -d)
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for package in "${apt_packages[@]}"; do
|
||||
pkg_status=$(dpkg -s $package 2> /dev/null | grep "Status" | cut -d " " -f 4)
|
||||
|
||||
# If pkg_status is `installed` then we don't need to install the package, otherwise if it's empty then the package is not installed
|
||||
if [ -z $pkg_status ]; then
|
||||
ensure_sudo_privileges "In order to install $package, please provide your password:"
|
||||
|
||||
printfe "%s" "yellow" " - Installing $package..."
|
||||
clear_line
|
||||
|
||||
result=$(sudo apt install -y $package 2>&1)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" " - Failed to install $package"
|
||||
printfe "%s\n" "yellow" "$result"
|
||||
exit 1
|
||||
else
|
||||
printfe "%s\n" "green" " - $package installed successfully"
|
||||
fi
|
||||
else
|
||||
printfe "%s\n" "green" " - $package is already installed"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
print_apt_status() {
|
||||
printfe "%s" "cyan" "Checking APT packages..."
|
||||
clear_line
|
||||
|
||||
apt_packages=($(cat $DOTFILES_CONFIG | shyaml get-values config.packages.apt.apps))
|
||||
|
||||
# count entries in packages
|
||||
count=$(echo $apt_packages | wc -w)
|
||||
installed=0
|
||||
|
||||
for package in "${apt_packages[@]}"; do
|
||||
pkg_status=$(dpkg -s $package 2> /dev/null | grep "Status" | cut -d " " -f 4)
|
||||
|
||||
if [ "$pkg_status" = "installed" ]; then
|
||||
installed=$((installed + 1))
|
||||
else
|
||||
if [ "$verbose" = true ]; then
|
||||
printfe "%s\n" "red" "$package is not installed"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
printfe "%s" "cyan" "APT"
|
||||
if [ $installed -eq $count ]; then
|
||||
printfe "%s" "green" " $installed/$count "
|
||||
else
|
||||
printfe "%s" "red" " $installed/$count "
|
||||
fi
|
||||
printfe "%s\n" "cyan" "packages installed"
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ensure_docker_installed() {
|
||||
# if docker is already installed, skip the installation
|
||||
if [ -x "$(command -v docker)" ]; then
|
||||
printfe "%s\n" "green" " - Docker is already installed"
|
||||
return
|
||||
fi
|
||||
|
||||
# Add Docker's official GPG key
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||
|
||||
# Add Docker's repository
|
||||
sudo add-apt-repository \
|
||||
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
|
||||
$(lsb_release -cs) \
|
||||
stable"
|
||||
|
||||
sudo apt update
|
||||
sudo apt install -y docker-ce docker-ce-cli containerd.io
|
||||
|
||||
# Check if it successfully installed
|
||||
if [ -x "$(command -v docker)" ]; then
|
||||
printfe "%s\n" "green" " - Docker is installed"
|
||||
else
|
||||
printfe "%s\n" "red" " - Docker is not installed"
|
||||
printfe "%s\n" "red" " Something went wrong while installing Docker, investigate the issue"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo usermod -aG docker $USER
|
||||
sudo systemctl start docker
|
||||
sudo systemctl enable docker
|
||||
}
|
@ -7,8 +7,7 @@ println() {
|
||||
}
|
||||
|
||||
is_wsl() {
|
||||
unameres=$(uname -a | grep -i "microsoft" | wc -l)
|
||||
if [ -n "$unameres" ]; then
|
||||
if [ -f "/proc/sys/fs/binfmt_misc/WSLInterop" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
@ -142,11 +141,87 @@ add_to_hosts() {
|
||||
fi
|
||||
}
|
||||
|
||||
function exesudo ()
|
||||
{
|
||||
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
|
||||
#
|
||||
# LOCAL VARIABLES:
|
||||
#
|
||||
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
|
||||
|
||||
#
|
||||
# I use underscores to remember it's been passed
|
||||
local _funcname_="$1"
|
||||
|
||||
local params=( "$@" ) ## array containing all params passed here
|
||||
local tmpfile="/dev/shm/$RANDOM" ## temporary file
|
||||
local content ## content of the temporary file
|
||||
local regex ## regular expression
|
||||
|
||||
|
||||
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
|
||||
#
|
||||
# MAIN CODE:
|
||||
#
|
||||
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
|
||||
|
||||
#
|
||||
# WORKING ON PARAMS:
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
#
|
||||
# Shift the first param (which is the name of the function)
|
||||
unset params[0] ## remove first element
|
||||
# params=( "${params[@]}" ) ## repack array
|
||||
|
||||
|
||||
#
|
||||
# WORKING ON THE TEMPORARY FILE:
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
content="#!/bin/bash\n\n"
|
||||
|
||||
#
|
||||
# Write the params array
|
||||
content="${content}params=(\n"
|
||||
|
||||
regex="\s+"
|
||||
for param in "${params[@]}"
|
||||
do
|
||||
if [[ "$param" =~ $regex ]]
|
||||
then
|
||||
content="${content}\t\"${param}\"\n"
|
||||
else
|
||||
content="${content}\t${param}\n"
|
||||
fi
|
||||
done
|
||||
|
||||
content="$content)\n"
|
||||
echo -e "$content" > "$tmpfile"
|
||||
|
||||
#
|
||||
# Append the function source
|
||||
echo "#$( type "$_funcname_" )" >> "$tmpfile"
|
||||
|
||||
#
|
||||
# Append the call to the function
|
||||
echo -e "\n$_funcname_ \"\${params[@]}\"\n" >> "$tmpfile"
|
||||
|
||||
|
||||
#
|
||||
# DONE: EXECUTE THE TEMPORARY FILE WITH SUDO
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
sudo bash "$tmpfile"
|
||||
rm "$tmpfile"
|
||||
}
|
||||
|
||||
resolve_path() {
|
||||
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
|
||||
}
|
||||
|
||||
check_or_make_symlink() {
|
||||
source /home/menno/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
SOURCE="$1"
|
||||
TARGET="$2"
|
||||
|
||||
@ -157,6 +232,22 @@ check_or_make_symlink() {
|
||||
SOURCE=$(resolve_path "$SOURCE")
|
||||
TARGET=$(resolve_path "$TARGET")
|
||||
|
||||
# Check if we have permissions to create the symlink
|
||||
if [ ! -w "$(dirname "$TARGET")" ]; then
|
||||
# Check if link exists
|
||||
if [ -L "$TARGET" ]; then
|
||||
# Check if it points to the correct location
|
||||
if [ "$(readlink "$TARGET")" != "$SOURCE" ]; then
|
||||
exesudo check_or_make_symlink "$SOURCE" "$TARGET"
|
||||
return
|
||||
fi
|
||||
else
|
||||
# Link doesn't exist but we don't have permissions to create it, so we should try to create it with sudosudo
|
||||
exesudo check_or_make_symlink "$SOURCE" "$TARGET"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
# If target is already a symlink, we should check if it points to the correct location
|
||||
if [ -L "$TARGET" ]; then
|
||||
if [ "$(readlink "$TARGET")" != "$SOURCE" ]; then
|
||||
|
@ -1,119 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
# Ensure jq is installed
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "jq could not be found, please install it."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse JSON file
|
||||
shortcuts_file=~/dotfiles/gnome/keyboard-shortcuts.json
|
||||
if [ ! -f "${shortcuts_file}" ]; then
|
||||
echo "Shortcuts file not found: ${shortcuts_file}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shortcuts=$(jq -r '.shortcuts' "${shortcuts_file}")
|
||||
|
||||
ensure_swhkd() {
|
||||
shortcuts_keys=($(cat "$DOTFILES_CONFIG" | shyaml keys config.keybinds))
|
||||
file_contents=""
|
||||
for key in "${shortcuts_keys[@]}"; do
|
||||
shortcut=$(cat "$DOTFILES_CONFIG" | shyaml get-value config.keybinds.$key.shortcut)
|
||||
command=$(cat "$DOTFILES_CONFIG" | shyaml get-value config.keybinds.$key.command)
|
||||
file_contents="${file_contents}\n${shortcut}\n ${command}\n\n"
|
||||
printfe "%s\n" "green" " - Ensuring swhkd shortcut ${shortcut} command ${command}"
|
||||
done
|
||||
echo -e "${file_contents}" > $HOME/.config/swhkdrc
|
||||
}
|
||||
|
||||
ensure_keyboard_shortcuts() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping keyboard shortcuts."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "green" " - Setting up swhkd configuration..."
|
||||
ensure_swhkd
|
||||
|
||||
# If swhkd is running, kill it
|
||||
if pgrep -x "swhkd" > /dev/null; then
|
||||
printfe "%s\n" "yellow" " - swhkd is running, killing it..."
|
||||
sudo pkill swhkd
|
||||
fi
|
||||
|
||||
# Same for swhks
|
||||
if pgrep -x "swhks" > /dev/null; then
|
||||
printfe "%s\n" "yellow" " - swhks is running, killing it..."
|
||||
sudo pkill swhks
|
||||
fi
|
||||
|
||||
# Start swhkd
|
||||
printfe "%s\n" "green" " - starting swhkd..."
|
||||
printfe "%s\n" "yellow" " Note: this will likely show a password prompt, please enter your password"
|
||||
screen -dmS swhkd bash -c "$HOME/dotfiles/bin/actions/hotkey-daemon.sh"
|
||||
|
||||
# Check if this is gnome DESKTOP_SESSION is gnome, if not we can stop here
|
||||
# The next part is just for setting up custom shortcuts in GNOME
|
||||
if [ "$XDG_CURRENT_DESKTOP" != "GNOME" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# Retrieve current custom keybindings
|
||||
existing_bindings=$(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings | tr -d "[]'")
|
||||
new_bindings=()
|
||||
index=0
|
||||
|
||||
# Iterate over parsed JSON shortcuts
|
||||
for key_combination in $(echo "$shortcuts" | jq -r 'keys[]'); do
|
||||
command=$(echo "$shortcuts" | jq -r ".[\"$key_combination\"]")
|
||||
|
||||
printfe '%s\n' "green" " - Ensuring GNOME shortcut ${key_combination} command ${command}"
|
||||
|
||||
custom_binding="/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom${index}/"
|
||||
new_bindings+=("$custom_binding")
|
||||
|
||||
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:"${custom_binding}" name "${key_combination} to run ${command}"
|
||||
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:"${custom_binding}" command "${command}"
|
||||
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:"${custom_binding}" binding "${key_combination}"
|
||||
dconf write "${custom_binding}enabled" true
|
||||
|
||||
((index++))
|
||||
done
|
||||
|
||||
new_bindings_string=$(printf "'%s', " "${new_bindings[@]}")
|
||||
new_bindings_string="[${new_bindings_string%, }]"
|
||||
|
||||
gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "${new_bindings_string}"
|
||||
}
|
||||
|
||||
print_keyboard_shortcuts_status() {
|
||||
printfe "%s" "cyan" "Checking keyboard shortcuts..."
|
||||
clear_line
|
||||
|
||||
# Retrieve current custom keybindings
|
||||
existing_bindings=$(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings | tr -d "[]'")
|
||||
existing_count=$(echo $existing_bindings | tr -cd , | wc -c)
|
||||
|
||||
# Iterate over parsed JSON shortcuts
|
||||
for key_combination in $(echo "$shortcuts" | jq -r 'keys[]'); do
|
||||
command=$(echo "$shortcuts" | jq -r ".[\"$key_combination\"]")
|
||||
|
||||
if [[ ! $existing_bindings =~ "custom${index}" ]]; then
|
||||
printfe "%s\n" "red" " - Custom shortcut ${key_combination} is missing"
|
||||
fi
|
||||
|
||||
((index++))
|
||||
done
|
||||
|
||||
json_count=$(echo $shortcuts | jq 'keys | length')
|
||||
printfe "%s" "cyan" "Keyboard shortcuts"
|
||||
if [ $index -eq $json_count ]; then
|
||||
printfe "%s" "green" " $index/$json_count "
|
||||
else
|
||||
printfe "%s" "red" " $index/$json_count "
|
||||
fi
|
||||
printfe "%s\n" "cyan" "shortcuts installed"
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
ensure_rust_installed() {
|
||||
if [ -x "$(command -v rustc)" ]; then
|
||||
printfe "%s\n" "green" " - Rust is already installed"
|
||||
|
||||
# Update Rust
|
||||
printfe "%s" "yellow" " - Updating Rust..."
|
||||
echo -en "\r"
|
||||
|
||||
rustup update
|
||||
else
|
||||
printfe "%s\n" "yellow" " - Installing Rust..."
|
||||
echo -en "\r"
|
||||
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Failed to install Rust"
|
||||
exit 1
|
||||
fi
|
||||
rustup default stable
|
||||
|
||||
printfe "%s\n" "green" " - Rust installed successfully"
|
||||
fi
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
ensure_user_groups() {
|
||||
# Load yaml file
|
||||
users=($(cat $DOTFILES_CONFIG | shyaml keys config.user_groups))
|
||||
|
||||
# For each user, ensure they are in the correct groups
|
||||
for user in "${users[@]}"; do
|
||||
# Ensure this user exists
|
||||
if [[ ! $(id -u $user) ]]; then
|
||||
printfe "%s\n" "red" " - User $user does not exist"
|
||||
continue
|
||||
fi
|
||||
|
||||
ensure_user_in_groups $user
|
||||
done
|
||||
}
|
||||
|
||||
ensure_user_in_groups() {
|
||||
user=$1
|
||||
groups=($(cat $DOTFILES_CONFIG | shyaml get-values config.user_groups.$user))
|
||||
|
||||
printfe "%s\n" "cyan" " - For user $user..."
|
||||
|
||||
# For each group, ensure the user is in it
|
||||
for group in "${groups[@]}"; do
|
||||
# Check if the group exists at all, otherwise skip
|
||||
if [[ ! $(getent group $group) ]]; then
|
||||
printfe "%s\n" "red" " Group $group does not exist"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ ! $groups == *$group* ]]; then
|
||||
printfe "%s\n" "green" " Adding $user to group $group"
|
||||
sudo usermod -aG $group $user
|
||||
else
|
||||
printfe "%s\n" "green" " $user is already in group $group"
|
||||
fi
|
||||
done
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
load_vscode_extensions() {
|
||||
# Clear the array before populating it
|
||||
arr=()
|
||||
while IFS= read -r line; do
|
||||
arr+=("$line")
|
||||
done < <(jq -r '.[]' ~/dotfiles/vscode/extensions.json)
|
||||
# Export the array
|
||||
export extensionList=("${arr[@]}")
|
||||
}
|
||||
|
||||
ensure_vscode_extensions_installed() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping VSCode extensions."
|
||||
return
|
||||
fi
|
||||
|
||||
# Load extensions list from jq in ~/dotfiles/vscode/extensions.json
|
||||
load_vscode_extensions
|
||||
|
||||
for extension in "${extensionList[@]}"; do
|
||||
result=$(code --list-extensions | grep -E "^${extension}$")
|
||||
if [ -z "$result" ]; then
|
||||
printfe "%s" "yellow" " - Installing $extension..."
|
||||
code --install-extension $extension
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" " - Failed to install $extension"
|
||||
exit 1
|
||||
fi
|
||||
printfe "%s\n" "green" " - Installed $extension"
|
||||
else
|
||||
printfe "%s\n" "green" " - $extension is already installed"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
print_vsc_status() {
|
||||
printfe "%s" "cyan" "Checking VSCode extensions..."
|
||||
clear_line
|
||||
|
||||
load_vscode_extensions
|
||||
count_installed_extensions=0
|
||||
|
||||
# Loop through each extension and check if it's installed
|
||||
for extension in "${extensionList[@]}"; do
|
||||
result=$(code --list-extensions | grep -E "^${extension}$")
|
||||
if [ -z "$result" ]; then
|
||||
if [ "$verbose" = true ]; then
|
||||
printfe "%s" "yellow" "Extension $extension is not installed\n"
|
||||
fi
|
||||
else
|
||||
count_installed_extensions=$((count_installed_extensions + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$verbose" = true ]; then
|
||||
printfe "%s\n" "yellow" "Expected extensions:"
|
||||
for ext in "${extensionList[@]}"; do
|
||||
printfe "%s\n" "blue" "$ext"
|
||||
done
|
||||
|
||||
printfe "%s\n" "yellow" "Installed extensions:"
|
||||
while IFS= read -r installed_ext; do
|
||||
printfe "%s\n" "blue" "$installed_ext"
|
||||
done < <(code --list-extensions)
|
||||
fi
|
||||
|
||||
count=${#extensionList[@]}
|
||||
|
||||
printfe "%s" "cyan" "VSCode"
|
||||
if [ $count_installed_extensions -eq $count ]; then
|
||||
printfe "%s" "green" " $count_installed_extensions/$count "
|
||||
else
|
||||
printfe "%s" "red" " $count_installed_extensions/$count "
|
||||
fi
|
||||
printfe "%s\n" "cyan" "extensions installed"
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import os
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
def get_weather():
|
||||
response = requests.get("https://wttr.in/beverwijk?n")
|
||||
return response.text.strip()
|
||||
|
||||
def get_moon_phase():
|
||||
response = requests.get("https://wttr.in/moon?format=F")
|
||||
return response.text.strip()
|
||||
|
||||
def read_prompt(file_path):
|
||||
with open(file_path, 'r') as file:
|
||||
return file.read()
|
||||
|
||||
def get_hostname():
|
||||
with open("/etc/hostname", 'r') as file:
|
||||
return file.read().strip()
|
||||
|
||||
def replace_wildcards(prompt, weather, moon_phase, time, date, hostname):
|
||||
prompt = prompt.replace("$TIME", time)
|
||||
prompt = prompt.replace("$DATE", date)
|
||||
prompt = prompt.replace("$HOSTNAME", hostname)
|
||||
prompt = prompt.replace("$WEATHER", weather)
|
||||
prompt = prompt.replace("$MOON_PHASE", moon_phase)
|
||||
return prompt
|
||||
|
||||
def main():
|
||||
home_directory = os.path.expanduser('~')
|
||||
AI_ENDPOINT = "https://api.openai.com/v1/chat/completions"
|
||||
OPENAI_API_KEY = ""
|
||||
PROMPT_FILE_PATH = home_directory + "/dotfiles/bin/resources/welcome_prompt.txt"
|
||||
|
||||
# Load api key from disk
|
||||
with open(home_directory + "/dotfiles/secrets/openai_api_key.secret", 'r') as file:
|
||||
OPENAI_API_KEY = file.read().strip()
|
||||
|
||||
weather = get_weather()
|
||||
moon_phase = get_moon_phase()
|
||||
hostname = get_hostname()
|
||||
time = datetime.now().strftime("%H:%M")
|
||||
date = datetime.now().strftime("%A, %d %B %Y")
|
||||
|
||||
openai_prompt = read_prompt(PROMPT_FILE_PATH)
|
||||
prompt = replace_wildcards(openai_prompt, weather, moon_phase, time, date, hostname)
|
||||
|
||||
data = {
|
||||
"max_tokens": 200,
|
||||
"messages": [
|
||||
{"role": "system", "content": prompt},
|
||||
],
|
||||
"model": "gpt-4o-mini",
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
||||
}
|
||||
|
||||
response = requests.post(AI_ENDPOINT, headers=headers, data=json.dumps(data))
|
||||
response_data = response.json()
|
||||
|
||||
completion = response_data['choices'][0]['message']['content']
|
||||
|
||||
print(completion)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user