Add formatting check for shell scripts (#106)
This commit is contained in:
committed by
GitHub
parent
1e7f91231c
commit
1e3bd2b04b
6
.github/workflows/ci.yaml
vendored
6
.github/workflows/ci.yaml
vendored
@@ -20,6 +20,8 @@ jobs:
|
|||||||
- uses: oven-sh/setup-bun@v1
|
- uses: oven-sh/setup-bun@v1
|
||||||
with:
|
with:
|
||||||
bun-version: latest
|
bun-version: latest
|
||||||
|
- name: Setup
|
||||||
|
run: bun install
|
||||||
- run: bun test
|
- run: bun test
|
||||||
pretty:
|
pretty:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -28,7 +30,9 @@ jobs:
|
|||||||
- uses: oven-sh/setup-bun@v1
|
- uses: oven-sh/setup-bun@v1
|
||||||
with:
|
with:
|
||||||
bun-version: latest
|
bun-version: latest
|
||||||
|
- name: Setup
|
||||||
|
run: bun install
|
||||||
- name: Format
|
- name: Format
|
||||||
run: bun fmt:ci
|
run: bun fmt:ci
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: bun install && bun lint
|
run: bun lint
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# Convert templated variables to shell variables
|
||||||
|
# shellcheck disable=SC2269
|
||||||
|
LOG_PATH=${LOG_PATH}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
BOLD='\033[0;1m'
|
BOLD='\033[0;1m'
|
||||||
|
|
||||||
|
# shellcheck disable=SC2059
|
||||||
printf "$${BOLD}Installing MODULE_NAME ...\n\n"
|
printf "$${BOLD}Installing MODULE_NAME ...\n\n"
|
||||||
|
|
||||||
# Add code here
|
# Add code here
|
||||||
# Use varibles from the templatefile function in main.tf
|
# Use varibles from the templatefile function in main.tf
|
||||||
# e.g. LOG_PATH, PORT, etc.
|
# e.g. LOG_PATH, PORT, etc.
|
||||||
@@ -13,6 +21,6 @@ printf "👷 Starting MODULE_NAME in background...\n\n"
|
|||||||
# 1. Use & to run it in background
|
# 1. Use & to run it in background
|
||||||
# 2. redirct stdout and stderr to log files
|
# 2. redirct stdout and stderr to log files
|
||||||
|
|
||||||
./app >${LOG_PATH} 2>&1 &
|
./app > "$${LOG_PATH}" 2>&1 &
|
||||||
|
|
||||||
printf "check logs at ${LOG_PATH} \n\n"
|
printf "check logs at %s\n\n" "$${LOG_PATH}"
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ done
|
|||||||
if [ ! -f ~/.local/share/code-server/Machine/settings.json ]; then
|
if [ ! -f ~/.local/share/code-server/Machine/settings.json ]; then
|
||||||
echo "⚙️ Creating settings file..."
|
echo "⚙️ Creating settings file..."
|
||||||
mkdir -p ~/.local/share/code-server/Machine
|
mkdir -p ~/.local/share/code-server/Machine
|
||||||
echo "${SETTINGS}" >~/.local/share/code-server/Machine/settings.json
|
echo "${SETTINGS}" > ~/.local/share/code-server/Machine/settings.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "👷 Running code-server in the background..."
|
echo "👷 Running code-server in the background..."
|
||||||
echo "Check logs at ${LOG_PATH}!"
|
echo "Check logs at ${LOG_PATH}!"
|
||||||
$CODE_SERVER --auth none --port ${PORT} >${LOG_PATH} 2>&1 &
|
$CODE_SERVER --auth none --port ${PORT} > ${LOG_PATH} 2>&1 &
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ BOLD='\033[0;1m'
|
|||||||
|
|
||||||
printf "$${BOLD}Logging into Coder...\n\n$${RESET}"
|
printf "$${BOLD}Logging into Coder...\n\n$${RESET}"
|
||||||
|
|
||||||
if ! coder list >/dev/null 2>&1; then
|
if ! coder list > /dev/null 2>&1; then
|
||||||
set +x; coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}"
|
set +x
|
||||||
|
coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}"
|
||||||
else
|
else
|
||||||
echo "You are already authenticated with coder."
|
echo "You are already authenticated with coder."
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n"
|
|||||||
|
|
||||||
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
|
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
|
||||||
|
|
||||||
filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} >${LOG_PATH} 2>&1 &
|
filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} > ${LOG_PATH} 2>&1 &
|
||||||
|
|
||||||
printf "📝 Logs at ${LOG_PATH} \n\n"
|
printf "📝 Logs at ${LOG_PATH} \n\n"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ if [ -z "$CLONE_PATH" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if `git` is installed...
|
# Check if `git` is installed...
|
||||||
if ! command -v git >/dev/null; then
|
if ! command -v git > /dev/null; then
|
||||||
echo "Git is not installed!"
|
echo "Git is not installed!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
if ! command -v git > /dev/null; then
|
if ! command -v git > /dev/null; then
|
||||||
echo "git is not installed"
|
echo "git is not installed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v curl > /dev/null; then
|
if ! command -v curl > /dev/null; then
|
||||||
echo "curl is not installed"
|
echo "curl is not installed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v jq > /dev/null; then
|
if ! command -v jq > /dev/null; then
|
||||||
echo "jq is not installed"
|
echo "jq is not installed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p ~/.ssh/git-commit-signing
|
mkdir -p ~/.ssh/git-commit-signing
|
||||||
@@ -20,14 +20,14 @@ mkdir -p ~/.ssh/git-commit-signing
|
|||||||
echo "Downloading SSH key"
|
echo "Downloading SSH key"
|
||||||
|
|
||||||
ssh_key=$(curl --request GET \
|
ssh_key=$(curl --request GET \
|
||||||
--url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \
|
--url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \
|
||||||
--header "Coder-Session-Token: ${CODER_AGENT_TOKEN}")
|
--header "Coder-Session-Token: ${CODER_AGENT_TOKEN}")
|
||||||
|
|
||||||
jq --raw-output ".public_key" > ~/.ssh/git-commit-signing/coder.pub <<EOF
|
jq --raw-output ".public_key" > ~/.ssh/git-commit-signing/coder.pub << EOF
|
||||||
$ssh_key
|
$ssh_key
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
jq --raw-output ".private_key" > ~/.ssh/git-commit-signing/coder <<EOF
|
jq --raw-output ".private_key" > ~/.ssh/git-commit-signing/coder << EOF
|
||||||
$ssh_key
|
$ssh_key
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -38,4 +38,4 @@ echo "Configuring git to use the SSH key"
|
|||||||
|
|
||||||
git config --global gpg.format ssh
|
git config --global gpg.format ssh
|
||||||
git config --global commit.gpgsign true
|
git config --global commit.gpgsign true
|
||||||
git config --global user.signingkey ~/.ssh/git-commit-signing/coder
|
git config --global user.signingkey ~/.ssh/git-commit-signing/coder
|
||||||
|
|||||||
@@ -4,20 +4,20 @@ BOLD='\033[0;1m'
|
|||||||
printf "$${BOLD}Checking git-config!\n"
|
printf "$${BOLD}Checking git-config!\n"
|
||||||
|
|
||||||
# Check if git is installed
|
# Check if git is installed
|
||||||
command -v git >/dev/null 2>&1 || {
|
command -v git > /dev/null 2>&1 || {
|
||||||
echo "Git is not installed!"
|
echo "Git is not installed!"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set git username and email if missing
|
# Set git username and email if missing
|
||||||
if [ -z $(git config --get user.email) ]; then
|
if [ -z $(git config --get user.email) ]; then
|
||||||
printf "git-config: No user.email found, setting to ${GIT_EMAIL}\n"
|
printf "git-config: No user.email found, setting to ${GIT_EMAIL}\n"
|
||||||
git config --global user.email "${GIT_EMAIL}"
|
git config --global user.email "${GIT_EMAIL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z $(git config --get user.name) ]; then
|
if [ -z $(git config --get user.name) ]; then
|
||||||
printf "git-config: No user.name found, setting to ${GIT_USERNAME}\n"
|
printf "git-config: No user.name found, setting to ${GIT_USERNAME}\n"
|
||||||
git config --global user.name "${GIT_USERNAME}"
|
git config --global user.name "${GIT_USERNAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "\n$${BOLD}git-config: using email: $(git config --get user.email)\n"
|
printf "\n$${BOLD}git-config: using email: $(git config --get user.email)\n"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
BOLD='\033[0;1m'
|
BOLD='\033[0;1m'
|
||||||
|
|
||||||
# check if JFrog CLI is already installed
|
# check if JFrog CLI is already installed
|
||||||
if command -v jf >/dev/null 2>&1; then
|
if command -v jf > /dev/null 2>&1; then
|
||||||
echo "✅ JFrog CLI is already installed, skipping installation."
|
echo "✅ JFrog CLI is already installed, skipping installation."
|
||||||
else
|
else
|
||||||
echo "📦 Installing JFrog CLI..."
|
echo "📦 Installing JFrog CLI..."
|
||||||
@@ -23,15 +23,15 @@ if [ -z "${REPOSITORY_NPM}" ]; then
|
|||||||
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
|
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
|
||||||
else
|
else
|
||||||
# check if npm is installed and configure it to use the Artifactory "npm" repository.
|
# check if npm is installed and configure it to use the Artifactory "npm" repository.
|
||||||
if command -v npm >/dev/null 2>&1; then
|
if command -v npm > /dev/null 2>&1; then
|
||||||
echo "📦 Configuring npm..."
|
echo "📦 Configuring npm..."
|
||||||
jf npmc --global --repo-resolve "${REPOSITORY_NPM}"
|
jf npmc --global --repo-resolve "${REPOSITORY_NPM}"
|
||||||
fi
|
fi
|
||||||
cat <<EOF >~/.npmrc
|
cat << EOF > ~/.npmrc
|
||||||
email = ${ARTIFACTORY_EMAIL}
|
email = ${ARTIFACTORY_EMAIL}
|
||||||
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
|
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
|
||||||
EOF
|
EOF
|
||||||
jf rt curl /api/npm/auth >>~/.npmrc
|
jf rt curl /api/npm/auth >> ~/.npmrc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Configure the `pip` to use the Artifactory "python" repository.
|
# Configure the `pip` to use the Artifactory "python" repository.
|
||||||
@@ -41,7 +41,7 @@ else
|
|||||||
echo "🐍 Configuring pip..."
|
echo "🐍 Configuring pip..."
|
||||||
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}"
|
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}"
|
||||||
mkdir -p ~/.pip
|
mkdir -p ~/.pip
|
||||||
cat <<EOF >~/.pip/pip.conf
|
cat << EOF > ~/.pip/pip.conf
|
||||||
[global]
|
[global]
|
||||||
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
|
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
BOLD='\033[0;1m'
|
BOLD='\033[0;1m'
|
||||||
|
|
||||||
# check if JFrog CLI is already installed
|
# check if JFrog CLI is already installed
|
||||||
if command -v jf >/dev/null 2>&1; then
|
if command -v jf > /dev/null 2>&1; then
|
||||||
echo "✅ JFrog CLI is already installed, skipping installation."
|
echo "✅ JFrog CLI is already installed, skipping installation."
|
||||||
else
|
else
|
||||||
echo "📦 Installing JFrog CLI..."
|
echo "📦 Installing JFrog CLI..."
|
||||||
@@ -23,15 +23,15 @@ if [ -z "${REPOSITORY_NPM}" ]; then
|
|||||||
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
|
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
|
||||||
else
|
else
|
||||||
# check if npm is installed and configure it to use the Artifactory "npm" repository.
|
# check if npm is installed and configure it to use the Artifactory "npm" repository.
|
||||||
if command -v npm >/dev/null 2>&1; then
|
if command -v npm > /dev/null 2>&1; then
|
||||||
echo "📦 Configuring npm..."
|
echo "📦 Configuring npm..."
|
||||||
jf npmc --global --repo-resolve "${REPOSITORY_NPM}"
|
jf npmc --global --repo-resolve "${REPOSITORY_NPM}"
|
||||||
fi
|
fi
|
||||||
cat <<EOF >~/.npmrc
|
cat << EOF > ~/.npmrc
|
||||||
email = ${ARTIFACTORY_EMAIL}
|
email = ${ARTIFACTORY_EMAIL}
|
||||||
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
|
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
|
||||||
EOF
|
EOF
|
||||||
jf rt curl /api/npm/auth >>~/.npmrc
|
jf rt curl /api/npm/auth >> ~/.npmrc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Configure the `pip` to use the Artifactory "python" repository.
|
# Configure the `pip` to use the Artifactory "python" repository.
|
||||||
@@ -41,7 +41,7 @@ else
|
|||||||
echo "🐍 Configuring pip..."
|
echo "🐍 Configuring pip..."
|
||||||
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}"
|
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}"
|
||||||
mkdir -p ~/.pip
|
mkdir -p ~/.pip
|
||||||
cat <<EOF >~/.pip/pip.conf
|
cat << EOF > ~/.pip/pip.conf
|
||||||
[global]
|
[global]
|
||||||
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
|
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -5,21 +5,21 @@ BOLD='\033[0;1m'
|
|||||||
printf "$${BOLD}Installing jupyter-notebook!\n"
|
printf "$${BOLD}Installing jupyter-notebook!\n"
|
||||||
|
|
||||||
# check if jupyter-notebook is installed
|
# check if jupyter-notebook is installed
|
||||||
if ! command -v jupyter-notebook >/dev/null 2>&1; then
|
if ! command -v jupyter-notebook > /dev/null 2>&1; then
|
||||||
# install jupyter-notebook
|
# install jupyter-notebook
|
||||||
# check if python3 pip is installed
|
# check if python3 pip is installed
|
||||||
if ! command -v pip3 >/dev/null 2>&1; then
|
if ! command -v pip3 > /dev/null 2>&1; then
|
||||||
echo "pip3 is not installed"
|
echo "pip3 is not installed"
|
||||||
echo "Please install pip3 in your Dockerfile/VM image before running this script"
|
echo "Please install pip3 in your Dockerfile/VM image before running this script"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# install jupyter-notebook
|
# install jupyter-notebook
|
||||||
pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyter
|
pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyter
|
||||||
echo "🥳 jupyter-notebook has been installed\n\n"
|
echo "🥳 jupyter-notebook has been installed\n\n"
|
||||||
else
|
else
|
||||||
echo "🥳 jupyter-notebook is already installed\n\n"
|
echo "🥳 jupyter-notebook is already installed\n\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "👷 Starting jupyter-notebook in background..."
|
echo "👷 Starting jupyter-notebook in background..."
|
||||||
echo "check logs at ${LOG_PATH}"
|
echo "check logs at ${LOG_PATH}"
|
||||||
$HOME/.local/bin/jupyter notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' >${LOG_PATH} 2>&1 &
|
$HOME/.local/bin/jupyter notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &
|
||||||
|
|||||||
@@ -5,21 +5,21 @@ BOLD='\033[0;1m'
|
|||||||
printf "$${BOLD}Installing jupyterlab!\n"
|
printf "$${BOLD}Installing jupyterlab!\n"
|
||||||
|
|
||||||
# check if jupyterlab is installed
|
# check if jupyterlab is installed
|
||||||
if ! command -v jupyterlab >/dev/null 2>&1; then
|
if ! command -v jupyterlab > /dev/null 2>&1; then
|
||||||
# install jupyterlab
|
# install jupyterlab
|
||||||
# check if python3 pip is installed
|
# check if python3 pip is installed
|
||||||
if ! command -v pip3 >/dev/null 2>&1; then
|
if ! command -v pip3 > /dev/null 2>&1; then
|
||||||
echo "pip3 is not installed"
|
echo "pip3 is not installed"
|
||||||
echo "Please install pip3 in your Dockerfile/VM image before running this script"
|
echo "Please install pip3 in your Dockerfile/VM image before running this script"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# install jupyterlab
|
# install jupyterlab
|
||||||
pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyterlab
|
pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyterlab
|
||||||
echo "🥳 jupyterlab has been installed\n\n"
|
echo "🥳 jupyterlab has been installed\n\n"
|
||||||
else
|
else
|
||||||
echo "🥳 jupyterlab is already installed\n\n"
|
echo "🥳 jupyterlab is already installed\n\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "👷 Starting jupyterlab in background..."
|
echo "👷 Starting jupyterlab in background..."
|
||||||
echo "check logs at ${LOG_PATH}"
|
echo "check logs at ${LOG_PATH}"
|
||||||
$HOME/.local/bin/jupyter lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' >${LOG_PATH} 2>&1 &
|
$HOME/.local/bin/jupyter lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &
|
||||||
|
|||||||
22
new.sh
22
new.sh
@@ -7,15 +7,15 @@ MODULE_NAME=$1
|
|||||||
|
|
||||||
# Check if module name is provided
|
# Check if module name is provided
|
||||||
if [ -z "$MODULE_NAME" ]; then
|
if [ -z "$MODULE_NAME" ]; then
|
||||||
echo "Usage: ./new.sh <module_name>"
|
echo "Usage: ./new.sh <module_name>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create module directory and exit if it alredy exists
|
# Create module directory and exit if it alredy exists
|
||||||
if [ -d "$MODULE_NAME" ]; then
|
if [ -d "$MODULE_NAME" ]; then
|
||||||
echo "Module with name $MODULE_NAME already exists"
|
echo "Module with name $MODULE_NAME already exists"
|
||||||
echo "Please choose a different name"
|
echo "Please choose a different name"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
mkdir -p "${MODULE_NAME}"
|
mkdir -p "${MODULE_NAME}"
|
||||||
|
|
||||||
@@ -27,13 +27,13 @@ cd "${MODULE_NAME}"
|
|||||||
|
|
||||||
# Detect OS
|
# Detect OS
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
# macOS
|
# macOS
|
||||||
sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" main.tf
|
sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" main.tf
|
||||||
sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" README.md
|
sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" README.md
|
||||||
else
|
else
|
||||||
# Linux
|
# Linux
|
||||||
sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf
|
sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf
|
||||||
sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md
|
sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make run.sh executable
|
# Make run.sh executable
|
||||||
|
|||||||
11
package.json
11
package.json
@@ -2,16 +2,17 @@
|
|||||||
"name": "modules",
|
"name": "modules",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun test",
|
"test": "bun test",
|
||||||
"fmt": "bun x prettier -w **/*.ts **/*.md *.md && terraform fmt **/*.tf",
|
"fmt": "bun x prettier --plugin prettier-plugin-sh -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf",
|
||||||
"fmt:ci": "bun x prettier --check **/*.ts **/*.md *.md && terraform fmt -check **/*.tf",
|
"fmt:ci": "bun x prettier --plugin prettier-plugin-sh --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf",
|
||||||
"lint": "bun run lint.ts"
|
"lint": "bun run lint.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bun-types": "^1.0.3",
|
"bun-types": "^1.0.18",
|
||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"marked": "^9.0.3"
|
"marked": "^11.1.0",
|
||||||
|
"prettier-plugin-sh": "^0.13.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,18 +9,18 @@ SCRIPT="$${SCRIPT/#\~/$${HOME}}"
|
|||||||
# If the personalize script doesn't exist, educate
|
# If the personalize script doesn't exist, educate
|
||||||
# the user how they can customize their environment!
|
# the user how they can customize their environment!
|
||||||
if [ ! -f $SCRIPT ]; then
|
if [ ! -f $SCRIPT ]; then
|
||||||
printf "✨ $${BOLD}You don't have a personalize script!\n\n"
|
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 "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"
|
printf "It will run every time your workspace starts. Use it to install personal packages!\n\n"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the personalize script is executable, if not,
|
# Check if the personalize script is executable, if not,
|
||||||
# try to make it executable and educate the user if it fails.
|
# try to make it executable and educate the user if it fails.
|
||||||
if [ ! -x $SCRIPT ]; then
|
if [ ! -x $SCRIPT ]; then
|
||||||
echo "🔐 Your personalize script isn't executable!"
|
echo "🔐 Your personalize script isn't executable!"
|
||||||
printf "Run $CODE\`chmod +x $SCRIPT\`$RESET to make it executable.\n"
|
printf "Run $CODE\`chmod +x $SCRIPT\`$RESET to make it executable.\n"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the personalize script!
|
# Run the personalize script!
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
PROVIDER_ID=${PROVIDER_ID}
|
PROVIDER_ID=${PROVIDER_ID}
|
||||||
SLACK_MESSAGE=$(cat << "EOF"
|
SLACK_MESSAGE=$(
|
||||||
|
cat << "EOF"
|
||||||
${SLACK_MESSAGE}
|
${SLACK_MESSAGE}
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
SLACK_URL=$${SLACK_URL:-https://slack.com}
|
SLACK_URL=$${SLACK_URL:-https://slack.com}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat << EOF
|
||||||
slackme — Send a Slack notification when a command finishes
|
slackme — Send a Slack notification when a command finishes
|
||||||
Usage: slackme <command>
|
Usage: slackme <command>
|
||||||
|
|
||||||
@@ -17,45 +18,45 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
pretty_duration() {
|
pretty_duration() {
|
||||||
local duration_ms=$1
|
local duration_ms=$1
|
||||||
|
|
||||||
# If the duration is less than 1 second, display in milliseconds
|
# If the duration is less than 1 second, display in milliseconds
|
||||||
if [ $duration_ms -lt 1000 ]; then
|
if [ $duration_ms -lt 1000 ]; then
|
||||||
echo "$${duration_ms}ms"
|
echo "$${duration_ms}ms"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Convert the duration to seconds
|
# Convert the duration to seconds
|
||||||
local duration_sec=$((duration_ms / 1000))
|
local duration_sec=$((duration_ms / 1000))
|
||||||
local remaining_ms=$((duration_ms % 1000))
|
local remaining_ms=$((duration_ms % 1000))
|
||||||
|
|
||||||
# If the duration is less than 1 minute, display in seconds (with ms)
|
# If the duration is less than 1 minute, display in seconds (with ms)
|
||||||
if [ $duration_sec -lt 60 ]; then
|
if [ $duration_sec -lt 60 ]; then
|
||||||
echo "$${duration_sec}.$${remaining_ms}s"
|
echo "$${duration_sec}.$${remaining_ms}s"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Convert the duration to minutes
|
# Convert the duration to minutes
|
||||||
local duration_min=$((duration_sec / 60))
|
local duration_min=$((duration_sec / 60))
|
||||||
local remaining_sec=$((duration_sec % 60))
|
local remaining_sec=$((duration_sec % 60))
|
||||||
|
|
||||||
# If the duration is less than 1 hour, display in minutes and seconds
|
# If the duration is less than 1 hour, display in minutes and seconds
|
||||||
if [ $duration_min -lt 60 ]; then
|
if [ $duration_min -lt 60 ]; then
|
||||||
echo "$${duration_min}m $${remaining_sec}.$${remaining_ms}s"
|
echo "$${duration_min}m $${remaining_sec}.$${remaining_ms}s"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Convert the duration to hours
|
# Convert the duration to hours
|
||||||
local duration_hr=$((duration_min / 60))
|
local duration_hr=$((duration_min / 60))
|
||||||
local remaining_min=$((duration_min % 60))
|
local remaining_min=$((duration_min % 60))
|
||||||
|
|
||||||
# Display in hours, minutes, and seconds
|
# Display in hours, minutes, and seconds
|
||||||
echo "$${duration_hr}hr $${remaining_min}m $${remaining_sec}.$${remaining_ms}s"
|
echo "$${duration_hr}hr $${remaining_min}m $${remaining_sec}.$${remaining_ms}s"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BOT_TOKEN=$(coder external-auth access-token $PROVIDER_ID)
|
BOT_TOKEN=$(coder external-auth access-token $PROVIDER_ID)
|
||||||
@@ -74,7 +75,7 @@ START=$(date +%s%N)
|
|||||||
# Run all arguments as a command
|
# Run all arguments as a command
|
||||||
$@
|
$@
|
||||||
END=$(date +%s%N)
|
END=$(date +%s%N)
|
||||||
DURATION_MS=$${DURATION_MS:-$(( (END - START) / 1000000 ))}
|
DURATION_MS=$${DURATION_MS:-$(((END - START) / 1000000))}
|
||||||
PRETTY_DURATION=$(pretty_duration $DURATION_MS)
|
PRETTY_DURATION=$(pretty_duration $DURATION_MS)
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
@@ -83,5 +84,5 @@ SLACK_MESSAGE=$(echo "$SLACK_MESSAGE" | sed "s|\\$COMMAND|$COMMAND|g")
|
|||||||
SLACK_MESSAGE=$(echo "$SLACK_MESSAGE" | sed "s|\\$DURATION|$PRETTY_DURATION|g")
|
SLACK_MESSAGE=$(echo "$SLACK_MESSAGE" | sed "s|\\$DURATION|$PRETTY_DURATION|g")
|
||||||
|
|
||||||
curl --silent -o /dev/null --header "Authorization: Bearer $BOT_TOKEN" \
|
curl --silent -o /dev/null --header "Authorization: Bearer $BOT_TOKEN" \
|
||||||
-G --data-urlencode "text=$${SLACK_MESSAGE}" \
|
-G --data-urlencode "text=$${SLACK_MESSAGE}" \
|
||||||
"$SLACK_URL/api/chat.postMessage?channel=$USER_ID&pretty=1"
|
"$SLACK_URL/api/chat.postMessage?channel=$USER_ID&pretty=1"
|
||||||
|
|||||||
@@ -18,4 +18,4 @@ printf "🥳 vscode-cli has been installed.\n\n"
|
|||||||
|
|
||||||
echo "👷 Running ${INSTALL_DIR}/bin/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms in the background..."
|
echo "👷 Running ${INSTALL_DIR}/bin/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms in the background..."
|
||||||
echo "Check logs at ${LOG_PATH}!"
|
echo "Check logs at ${LOG_PATH}!"
|
||||||
${INSTALL_DIR}/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms >${LOG_PATH} 2>&1 &
|
${INSTALL_DIR}/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms > ${LOG_PATH} 2>&1 &
|
||||||
|
|||||||
Reference in New Issue
Block a user