Initial commit
This commit is contained in:
31
personalize/main.tf
Normal file
31
personalize/main.tf
Normal file
@@ -0,0 +1,31 @@
|
||||
terraform {
|
||||
required_version = ">= 1.0"
|
||||
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "terraform.local/coder/coder"
|
||||
version = ">= 0.12"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "agent_id" {
|
||||
type = string
|
||||
description = "The ID of a Coder agent."
|
||||
}
|
||||
|
||||
variable "path" {
|
||||
type = string
|
||||
description = "The path to a script that will be ran on start enabling a user to personalize their workspace."
|
||||
default = "~/personalize"
|
||||
}
|
||||
|
||||
resource "coder_script" "personalize" {
|
||||
agent_id = var.agent_id
|
||||
script = templatefile("${path.module}/run.sh", {
|
||||
PERSONALIZE_PATH: var.path,
|
||||
})
|
||||
display_name = "Personalize"
|
||||
icon = "/emojis/1f58c.png"
|
||||
run_on_start = true
|
||||
}
|
||||
26
personalize/run.sh
Executable file
26
personalize/run.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
BOLD='\033[0;1m'
|
||||
CODE='\033[36;40;1m'
|
||||
RESET='\033[0m'
|
||||
SCRIPT="${PERSONALIZE_PATH}"
|
||||
|
||||
# If the personalize script doesn't exist, educate
|
||||
# the user how they can customize their environment!
|
||||
if [ ! -f $SCRIPT ]; then
|
||||
printf "✨ $${BOLD}You don't have a personalize script!\n\n"
|
||||
printf "Run $${CODE}touch $${SCRIPT} && chmod +x $${SCRIPT}$${RESET} to create one.\n"
|
||||
printf "It will run every time your workspace starts. Use it to install personal packages!\n\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if the personalize script is executable, if not,
|
||||
# try to make it executable and educate the user if it fails.
|
||||
if [ ! -x $SCRIPT ]; then
|
||||
echo "🔐 Your personalize script isn't executable!"
|
||||
printf "Run $CODE\`chmod +x $SCRIPT\`$RESET to make it executable.\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Run the personalize script!
|
||||
exec $SCRIPT
|
||||
Reference in New Issue
Block a user