feat: adds very useless welcome thing with openai, this is so fucking useless XD
feat: adds secrets folder with GPG/1Password
This commit is contained in:
parent
2d71007b45
commit
6fdb84ce50
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
config/ssh/config.d/*
|
||||
!config/ssh/config.d/*.gpg
|
||||
logs/*
|
||||
logs/*
|
||||
secrets/*
|
||||
!secrets/*.gpg
|
@ -55,3 +55,33 @@ else
|
||||
printfe "%s\n" "red" "Invalid argument. Use 'decrypt' or 'encrypt'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Do the same for files under $HOME/dotfiles/secrets/ (These can be any file type, not just .conf so keep the extension)
|
||||
if [[ "$2" == "decrypt" ]]; then
|
||||
printfe "%s\n" "cyan" "Decrypting secrets..."
|
||||
echo -en '\r'
|
||||
|
||||
for file in $HOME/dotfiles/secrets/*.gpg; do
|
||||
filename=$(basename $file .gpg)
|
||||
|
||||
gpg --quiet --batch --yes --decrypt --passphrase="$password" --output $HOME/dotfiles/secrets/$filename $file
|
||||
done
|
||||
elif [[ "$2" == "encrypt" ]]; then
|
||||
printfe "%s\n" "cyan" "Encrypting secrets..."
|
||||
echo -en '\r'
|
||||
|
||||
for file in $HOME/dotfiles/secrets/*; do
|
||||
# Skip if current file is a .gpg file
|
||||
if [[ $file == *.gpg ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# If the file has a accompanying .gpg file, remove it
|
||||
if [[ -f $file.gpg ]]; then
|
||||
rm $file.gpg
|
||||
fi
|
||||
|
||||
gpg --quiet --batch --yes --symmetric --cipher-algo AES256 --armor --passphrase="$password" --output $file.gpg $file
|
||||
done
|
||||
fi
|
||||
|
@ -29,7 +29,9 @@ run_startup_scripts() {
|
||||
emoji="🌆"
|
||||
;;
|
||||
esac
|
||||
printfe "%s" "cyan" "Hi $(whoami), good $time_of_day! $emoji"
|
||||
|
||||
# Run the welcome.py from $HOME/dotfiles/bin/helpers/welcome.py
|
||||
python3 $HOME/dotfiles/bin/helpers/welcome.py
|
||||
echo ""
|
||||
|
||||
# Initialize array to hold commands
|
||||
|
72
bin/helpers/welcome.py
Executable file
72
bin/helpers/welcome.py
Executable file
@ -0,0 +1,72 @@
|
||||
#!/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", '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()
|
28
bin/resources/welcome_prompt.txt
Normal file
28
bin/resources/welcome_prompt.txt
Normal file
@ -0,0 +1,28 @@
|
||||
You are an assistant, you are getting prompted by an automated bash script on boot-up of Menno's computer $HOSTNAME. Menno is a software engineer who loves to automate everything. (Menno van Leeuwen)
|
||||
This script starts up all his stuff on the PC and your task is quite silly but simple:
|
||||
- Give menno a nice and comedy welcome.
|
||||
- Keep it short and concise but funny.
|
||||
|
||||
Rules:
|
||||
- Do not actually output any bash/zsh scripting, just a message to Menno for his entertainment.
|
||||
- No open and closing quotes, tags or any syntax that would indicate this is a script.
|
||||
- Be creative, Menno loves a good laugh.
|
||||
- Output in a nice format that's easily to read.
|
||||
- Make sure to include the forecast.
|
||||
- You don't have to always make it centered about code, but it's a good start.
|
||||
- You don't have to include every topic mentioned, just pick a couple and make it funny.
|
||||
|
||||
Topics:
|
||||
- Weekend coming up (If it's Friday or half way through the week and desperate for the weekend)
|
||||
- A beer is always a good idea in the weekend (Only applicable on Friday, Saturday or Sunday)
|
||||
- The weather (Menno loves to know the weather)
|
||||
- Space, stars, planets, etc
|
||||
- Programming
|
||||
- Gaming
|
||||
- Astrophotography
|
||||
- Trying to avoid death scrolling on Reddit, Youtube, etc
|
||||
|
||||
For funs here is some maybe or maybe not so relevant info:
|
||||
- The time now is $TIME ($DATE)
|
||||
- The current weather and moon phase follows: $WEATHER
|
||||
- The moon phase is as follows: $MOON_PHASE
|
9
secrets/openai_api_key.gpg
Normal file
9
secrets/openai_api_key.gpg
Normal file
@ -0,0 +1,9 @@
|
||||
-----BEGIN PGP MESSAGE-----
|
||||
|
||||
jA0ECQMC0bXPusSXNbv/0sADARKkLT5V2vgHy84nrHw/oZRfduZXXVF2fexBcgj8
|
||||
Q45bAtlEKkh6uE3SCLPys4RnZVlCUT3nfKcxkj18uL/U4nbMWiijdnRwCL70SGVn
|
||||
x+ZqGO5kUZIW+6tzEjcnWw+ES2jEy6v0+MHUau47ShgtSINjH8jCYyt/zLbVeh4S
|
||||
LBKORh15pkoPCA3on1Tefsn5pjDZ6HxqbqBkYZxcmylmcs4CjgmGc5SA+3yHyXIb
|
||||
BRIGVSa/HCOuUKtznVvEr79HfbTT
|
||||
=7tLO
|
||||
-----END PGP MESSAGE-----
|
Loading…
x
Reference in New Issue
Block a user