diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 60a760b..660d416 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,6 +20,8 @@ jobs: - uses: oven-sh/setup-bun@v1 with: bun-version: latest + - name: Setup + run: bun install - run: bun test pretty: runs-on: ubuntu-latest @@ -28,7 +30,9 @@ jobs: - uses: oven-sh/setup-bun@v1 with: bun-version: latest + - name: Setup + run: bun install - name: Format run: bun fmt:ci - name: Lint - run: bun install && bun lint + run: bun lint diff --git a/.sample/run.sh b/.sample/run.sh index e0d1afc..f50f6ba 100755 --- a/.sample/run.sh +++ b/.sample/run.sh @@ -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' + +# shellcheck disable=SC2059 printf "$${BOLD}Installing MODULE_NAME ...\n\n" + # Add code here # Use varibles from the templatefile function in main.tf # 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 # 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}" diff --git a/bun.lockb b/bun.lockb index 0d30fe9..f8f4940 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/code-server/run.sh b/code-server/run.sh index 552ced1..8cad538 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -42,9 +42,9 @@ done if [ ! -f ~/.local/share/code-server/Machine/settings.json ]; then echo "⚙️ Creating settings file..." 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 echo "👷 Running code-server in the background..." echo "Check logs at ${LOG_PATH}!" -$CODE_SERVER --auth none --port ${PORT} >${LOG_PATH} 2>&1 & \ No newline at end of file +$CODE_SERVER --auth none --port ${PORT} > ${LOG_PATH} 2>&1 & diff --git a/coder-login/run.sh b/coder-login/run.sh index e5a58ec..c91eb1e 100644 --- a/coder-login/run.sh +++ b/coder-login/run.sh @@ -7,8 +7,9 @@ BOLD='\033[0;1m' printf "$${BOLD}Logging into Coder...\n\n$${RESET}" -if ! coder list >/dev/null 2>&1; then - set +x; coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}" +if ! coder list > /dev/null 2>&1; then + set +x + coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}" else echo "You are already authenticated with coder." fi diff --git a/filebrowser/run.sh b/filebrowser/run.sh index b54a051..0cbf8f4 100644 --- a/filebrowser/run.sh +++ b/filebrowser/run.sh @@ -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" -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" diff --git a/git-clone/run.sh b/git-clone/run.sh index 2b537f4..df647a1 100755 --- a/git-clone/run.sh +++ b/git-clone/run.sh @@ -18,7 +18,7 @@ if [ -z "$CLONE_PATH" ]; then fi # Check if `git` is installed... -if ! command -v git >/dev/null; then +if ! command -v git > /dev/null; then echo "Git is not installed!" exit 1 fi diff --git a/git-commit-signing/run.sh b/git-commit-signing/run.sh index 57c5139..d757179 100755 --- a/git-commit-signing/run.sh +++ b/git-commit-signing/run.sh @@ -1,18 +1,18 @@ #!/usr/bin/env sh if ! command -v git > /dev/null; then - echo "git is not installed" - exit 1 + echo "git is not installed" + exit 1 fi if ! command -v curl > /dev/null; then - echo "curl is not installed" - exit 1 + echo "curl is not installed" + exit 1 fi if ! command -v jq > /dev/null; then - echo "jq is not installed" - exit 1 + echo "jq is not installed" + exit 1 fi mkdir -p ~/.ssh/git-commit-signing @@ -20,14 +20,14 @@ mkdir -p ~/.ssh/git-commit-signing echo "Downloading SSH key" ssh_key=$(curl --request GET \ - --url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \ - --header "Coder-Session-Token: ${CODER_AGENT_TOKEN}") + --url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \ + --header "Coder-Session-Token: ${CODER_AGENT_TOKEN}") -jq --raw-output ".public_key" > ~/.ssh/git-commit-signing/coder.pub < ~/.ssh/git-commit-signing/coder.pub << EOF $ssh_key EOF -jq --raw-output ".private_key" > ~/.ssh/git-commit-signing/coder < ~/.ssh/git-commit-signing/coder << EOF $ssh_key EOF @@ -38,4 +38,4 @@ echo "Configuring git to use the SSH key" git config --global gpg.format ssh git config --global commit.gpgsign true -git config --global user.signingkey ~/.ssh/git-commit-signing/coder \ No newline at end of file +git config --global user.signingkey ~/.ssh/git-commit-signing/coder diff --git a/git-config/run.sh b/git-config/run.sh index 586be4d..36dc768 100644 --- a/git-config/run.sh +++ b/git-config/run.sh @@ -4,20 +4,20 @@ BOLD='\033[0;1m' printf "$${BOLD}Checking git-config!\n" # Check if git is installed -command -v git >/dev/null 2>&1 || { - echo "Git is not installed!" - exit 1 +command -v git > /dev/null 2>&1 || { + echo "Git is not installed!" + exit 1 } # Set git username and email if missing if [ -z $(git config --get user.email) ]; then - printf "git-config: No user.email found, setting to ${GIT_EMAIL}\n" - git config --global user.email "${GIT_EMAIL}" + printf "git-config: No user.email found, setting to ${GIT_EMAIL}\n" + git config --global user.email "${GIT_EMAIL}" fi if [ -z $(git config --get user.name) ]; then - printf "git-config: No user.name found, setting to ${GIT_USERNAME}\n" - git config --global user.name "${GIT_USERNAME}" + printf "git-config: No user.name found, setting to ${GIT_USERNAME}\n" + git config --global user.name "${GIT_USERNAME}" fi printf "\n$${BOLD}git-config: using email: $(git config --get user.email)\n" diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index efba187..8006db9 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -3,7 +3,7 @@ BOLD='\033[0;1m' # 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." else echo "📦 Installing JFrog CLI..." @@ -23,15 +23,15 @@ if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." else # 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..." jf npmc --global --repo-resolve "${REPOSITORY_NPM}" fi - cat <~/.npmrc + cat << EOF > ~/.npmrc email = ${ARTIFACTORY_EMAIL} registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF - jf rt curl /api/npm/auth >>~/.npmrc + jf rt curl /api/npm/auth >> ~/.npmrc fi # Configure the `pip` to use the Artifactory "python" repository. @@ -41,7 +41,7 @@ else echo "🐍 Configuring pip..." jf pipc --global --repo-resolve "${REPOSITORY_PYPI}" mkdir -p ~/.pip - cat <~/.pip/pip.conf + cat << EOF > ~/.pip/pip.conf [global] index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple EOF diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index efba187..8006db9 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -3,7 +3,7 @@ BOLD='\033[0;1m' # 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." else echo "📦 Installing JFrog CLI..." @@ -23,15 +23,15 @@ if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." else # 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..." jf npmc --global --repo-resolve "${REPOSITORY_NPM}" fi - cat <~/.npmrc + cat << EOF > ~/.npmrc email = ${ARTIFACTORY_EMAIL} registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF - jf rt curl /api/npm/auth >>~/.npmrc + jf rt curl /api/npm/auth >> ~/.npmrc fi # Configure the `pip` to use the Artifactory "python" repository. @@ -41,7 +41,7 @@ else echo "🐍 Configuring pip..." jf pipc --global --repo-resolve "${REPOSITORY_PYPI}" mkdir -p ~/.pip - cat <~/.pip/pip.conf + cat << EOF > ~/.pip/pip.conf [global] index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple EOF diff --git a/jupyter-notebook/run.sh b/jupyter-notebook/run.sh index 1f948ab..4f8c4a2 100755 --- a/jupyter-notebook/run.sh +++ b/jupyter-notebook/run.sh @@ -5,21 +5,21 @@ BOLD='\033[0;1m' printf "$${BOLD}Installing jupyter-notebook!\n" # check if jupyter-notebook is installed -if ! command -v jupyter-notebook >/dev/null 2>&1; then - # install jupyter-notebook - # check if python3 pip is installed - if ! command -v pip3 >/dev/null 2>&1; then - echo "pip3 is not installed" - echo "Please install pip3 in your Dockerfile/VM image before running this script" - exit 1 - fi - # install jupyter-notebook - pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyter - echo "🥳 jupyter-notebook has been installed\n\n" +if ! command -v jupyter-notebook > /dev/null 2>&1; then + # install jupyter-notebook + # check if python3 pip is installed + if ! command -v pip3 > /dev/null 2>&1; then + echo "pip3 is not installed" + echo "Please install pip3 in your Dockerfile/VM image before running this script" + exit 1 + fi + # install jupyter-notebook + pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyter + echo "🥳 jupyter-notebook has been installed\n\n" else - echo "🥳 jupyter-notebook is already installed\n\n" + echo "🥳 jupyter-notebook is already installed\n\n" fi echo "👷 Starting jupyter-notebook in background..." 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 & diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh index 8f77cac..b040cec 100755 --- a/jupyterlab/run.sh +++ b/jupyterlab/run.sh @@ -5,21 +5,21 @@ BOLD='\033[0;1m' printf "$${BOLD}Installing jupyterlab!\n" # check if jupyterlab is installed -if ! command -v jupyterlab >/dev/null 2>&1; then - # install jupyterlab - # check if python3 pip is installed - if ! command -v pip3 >/dev/null 2>&1; then - echo "pip3 is not installed" - echo "Please install pip3 in your Dockerfile/VM image before running this script" - exit 1 - fi - # install jupyterlab - pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyterlab - echo "🥳 jupyterlab has been installed\n\n" +if ! command -v jupyterlab > /dev/null 2>&1; then + # install jupyterlab + # check if python3 pip is installed + if ! command -v pip3 > /dev/null 2>&1; then + echo "pip3 is not installed" + echo "Please install pip3 in your Dockerfile/VM image before running this script" + exit 1 + fi + # install jupyterlab + pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyterlab + echo "🥳 jupyterlab has been installed\n\n" else - echo "🥳 jupyterlab is already installed\n\n" + echo "🥳 jupyterlab is already installed\n\n" fi echo "👷 Starting jupyterlab in background..." 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 & diff --git a/new.sh b/new.sh index 29e4f52..e35e860 100755 --- a/new.sh +++ b/new.sh @@ -7,15 +7,15 @@ MODULE_NAME=$1 # Check if module name is provided if [ -z "$MODULE_NAME" ]; then - echo "Usage: ./new.sh " - exit 1 + echo "Usage: ./new.sh " + exit 1 fi # Create module directory and exit if it alredy exists if [ -d "$MODULE_NAME" ]; then - echo "Module with name $MODULE_NAME already exists" - echo "Please choose a different name" - exit 1 + echo "Module with name $MODULE_NAME already exists" + echo "Please choose a different name" + exit 1 fi mkdir -p "${MODULE_NAME}" @@ -27,13 +27,13 @@ cd "${MODULE_NAME}" # Detect OS if [[ "$OSTYPE" == "darwin"* ]]; then - # macOS - sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" main.tf - sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" README.md + # macOS + sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" main.tf + sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" README.md else - # Linux - sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf - sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md + # Linux + sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf + sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md fi # Make run.sh executable diff --git a/package.json b/package.json index c9d3a81..d374122 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,17 @@ "name": "modules", "scripts": { "test": "bun test", - "fmt": "bun x prettier -w **/*.ts **/*.md *.md && terraform fmt **/*.tf", - "fmt:ci": "bun x prettier --check **/*.ts **/*.md *.md && terraform fmt -check **/*.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 --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" }, "devDependencies": { - "bun-types": "^1.0.3", + "bun-types": "^1.0.18", "gray-matter": "^4.0.3", - "marked": "^9.0.3" + "marked": "^11.1.0", + "prettier-plugin-sh": "^0.13.1" }, "peerDependencies": { - "typescript": "^5.0.0" + "typescript": "^5.3.3" } } diff --git a/personalize/run.sh b/personalize/run.sh index 18fea76..dacaf48 100755 --- a/personalize/run.sh +++ b/personalize/run.sh @@ -9,18 +9,18 @@ SCRIPT="$${SCRIPT/#\~/$${HOME}}" # 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 + 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 + 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! diff --git a/slackme/slackme.sh b/slackme/slackme.sh index 17f74ec..e966dcf 100644 --- a/slackme/slackme.sh +++ b/slackme/slackme.sh @@ -1,14 +1,15 @@ #!/usr/bin/env sh PROVIDER_ID=${PROVIDER_ID} -SLACK_MESSAGE=$(cat << "EOF" +SLACK_MESSAGE=$( + cat << "EOF" ${SLACK_MESSAGE} EOF ) SLACK_URL=$${SLACK_URL:-https://slack.com} usage() { - cat < @@ -17,45 +18,45 @@ EOF } pretty_duration() { - local duration_ms=$1 - - # If the duration is less than 1 second, display in milliseconds - if [ $duration_ms -lt 1000 ]; then - echo "$${duration_ms}ms" - return - fi - - # Convert the duration to seconds - local duration_sec=$((duration_ms / 1000)) - local remaining_ms=$((duration_ms % 1000)) - - # If the duration is less than 1 minute, display in seconds (with ms) - if [ $duration_sec -lt 60 ]; then - echo "$${duration_sec}.$${remaining_ms}s" - return - fi - - # Convert the duration to minutes - local duration_min=$((duration_sec / 60)) - local remaining_sec=$((duration_sec % 60)) - - # If the duration is less than 1 hour, display in minutes and seconds - if [ $duration_min -lt 60 ]; then - echo "$${duration_min}m $${remaining_sec}.$${remaining_ms}s" - return - fi - - # Convert the duration to hours - local duration_hr=$((duration_min / 60)) - local remaining_min=$((duration_min % 60)) - - # Display in hours, minutes, and seconds - echo "$${duration_hr}hr $${remaining_min}m $${remaining_sec}.$${remaining_ms}s" + local duration_ms=$1 + + # If the duration is less than 1 second, display in milliseconds + if [ $duration_ms -lt 1000 ]; then + echo "$${duration_ms}ms" + return + fi + + # Convert the duration to seconds + local duration_sec=$((duration_ms / 1000)) + local remaining_ms=$((duration_ms % 1000)) + + # If the duration is less than 1 minute, display in seconds (with ms) + if [ $duration_sec -lt 60 ]; then + echo "$${duration_sec}.$${remaining_ms}s" + return + fi + + # Convert the duration to minutes + local duration_min=$((duration_sec / 60)) + local remaining_sec=$((duration_sec % 60)) + + # If the duration is less than 1 hour, display in minutes and seconds + if [ $duration_min -lt 60 ]; then + echo "$${duration_min}m $${remaining_sec}.$${remaining_ms}s" + return + fi + + # Convert the duration to hours + local duration_hr=$((duration_min / 60)) + local remaining_min=$((duration_min % 60)) + + # Display in hours, minutes, and seconds + echo "$${duration_hr}hr $${remaining_min}m $${remaining_sec}.$${remaining_ms}s" } if [ $# -eq 0 ]; then - usage - exit 1 + usage + exit 1 fi BOT_TOKEN=$(coder external-auth access-token $PROVIDER_ID) @@ -74,7 +75,7 @@ START=$(date +%s%N) # Run all arguments as a command $@ END=$(date +%s%N) -DURATION_MS=$${DURATION_MS:-$(( (END - START) / 1000000 ))} +DURATION_MS=$${DURATION_MS:-$(((END - START) / 1000000))} PRETTY_DURATION=$(pretty_duration $DURATION_MS) 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") curl --silent -o /dev/null --header "Authorization: Bearer $BOT_TOKEN" \ - -G --data-urlencode "text=$${SLACK_MESSAGE}" \ - "$SLACK_URL/api/chat.postMessage?channel=$USER_ID&pretty=1" + -G --data-urlencode "text=$${SLACK_MESSAGE}" \ + "$SLACK_URL/api/chat.postMessage?channel=$USER_ID&pretty=1" diff --git a/vscode-web/run.sh b/vscode-web/run.sh index ddec273..d19be62 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -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 "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 &