fix shellcheck errors

pull/106/head
Muhammad Atif Ali 2 years ago
parent af302bb587
commit fd99376f5a

@ -26,7 +26,7 @@ CODE_SERVER="${INSTALL_PREFIX}/bin/code-server"
# Install each extension... # Install each extension...
IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}" IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}"
for extension in "$${EXTENSIONLIST[@]}"; do for extension in $${EXTENSIONLIST[@]}; do
if [ -z "$extension" ]; then if [ -z "$extension" ]; then
continue continue
fi fi

@ -4,12 +4,17 @@
# logged in to another deployment # logged in to another deployment
BOLD='\033[0;1m' BOLD='\033[0;1m'
RESET='\033[0m'
# Convert templated variables to shell variables
CODER_DEPLOYMENT_URL=${CODER_DEPLOYMENT_URL}
CODER_USER_TOKEN=${CODER_USER_TOKEN}
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 set +x
coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}" 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

@ -9,18 +9,20 @@ printf "🥳 Installation comlete! \n\n"
printf "👷 Starting filebrowser in background... \n\n" printf "👷 Starting filebrowser in background... \n\n"
# Convert templated variables to shell variables
ROOT_DIR=${FOLDER} ROOT_DIR=${FOLDER}
ROOT_DIR=$${ROOT_DIR/\~/$HOME} ROOT_DIR=$${ROOT_DIR/\~/$HOME}
PORT=${PORT}
DB_PATH=${DB_PATH}
LOG_PATH=${LOG_PATH}
DB_FLAG="" DB_FLAG=""
if [ "${DB_PATH}" != "filebrowser.db" ]; then if [ "$${DB_PATH}" != "filebrowser.db" ]; then
DB_FLAG=" -d ${DB_PATH}" DB_FLAG="-d $${DB_PATH}"
fi fi
printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n" 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 %s \n\n" "$${LOG_PATH}"
printf "📝 Logs at ${LOG_PATH} \n\n"

@ -1,5 +1,9 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# Convert templated variables to shell variables
CODER_AGENT_URL=${CODER_AGENT_URL}
CODER_AGENT_TOKEN=${CODER_AGENT_TOKEN}
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
@ -20,8 +24,8 @@ 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

@ -1,7 +1,11 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# Convert templated variables to shell variables
GIT_EMAIL=${GIT_EMAIL}
GIT_USERNAME=${GIT_USERNAME}
BOLD='\033[0;1m' BOLD='\033[0;1m'
printf "$${BOLD}Checking git-config!\n" printf "$${BOLD}Checking git-config!\n\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 || {
@ -10,15 +14,15 @@ command -v git > /dev/null 2>&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 %s\n" "$${GIT_EMAIL}"
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\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 "$${BOLD}git-config: using email: $(git config --get user.email)\n"
printf "$${BOLD}git-config: using username: $(git config --get user.name)\n\n" printf "$${BOLD}git-config: using username: $(git config --get user.name)\n\n"

@ -4,7 +4,7 @@
"test": "bun test", "test": "bun test",
"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": "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", "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 && bun x shellcheck **/*.sh .sample/run.sh new.sh" "lint": "bun run lint.ts && bun x shellcheck -S error **/*.sh .sample/run.sh new.sh"
}, },
"devDependencies": { "devDependencies": {
"bun-types": "^1.0.3", "bun-types": "^1.0.3",

@ -73,13 +73,13 @@ fi
START=$(date +%s%N) 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
COMMAND=$(echo $@) COMMAND=$("$@")
SLACK_MESSAGE=$(echo "$SLACK_MESSAGE" | sed "s|\\$COMMAND|$COMMAND|g") 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")

@ -36,11 +36,12 @@ unzip() {
if [ "$${INSTALL_VERSION}" = "latest" ]; then if [ "$${INSTALL_VERSION}" = "latest" ]; then
LATEST_VERSION=$(curl -s https://releases.hashicorp.com/vault/ | grep -oP 'vault/\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1) LATEST_VERSION=$(curl -s https://releases.hashicorp.com/vault/ | grep -oP 'vault/\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1)
printf "Latest version of Vault is %s.\n\n" "$${LATEST_VERSION}" printf "Latest version of Vault is %s.\n\n" "$${LATEST_VERSION}"
if [ -z "$${LATEST_VERSION}" ]; then # check if the latest version is empty
if [ "$${LATEST_VERSION}" = "" ]; then
printf "Failed to determine the latest Vault version.\n" printf "Failed to determine the latest Vault version.\n"
exit 1 exit 1
fi fi
VERSION=$${LATEST_VERSION} VERSION="$${LATEST_VERSION}"
fi fi
# Check if the vault CLI is installed and has the correct version # Check if the vault CLI is installed and has the correct version
@ -53,9 +54,10 @@ if command -v vault > /dev/null 2>&1; then
fi fi
fi fi
if [ $${installation_needed} -eq 1 ]; then if [ "$${installation_needed}" = 1 ]; then
# Download and install Vault # Download and install Vault
if [ -z "$${CURRENT_VERSION}" ]; then # if the current version is not the same as the version we want to install
if [ "$CURRENT_VERSION" = "" ]; then
printf "Installing Vault CLI ...\n\n" printf "Installing Vault CLI ...\n\n"
else else
printf "Upgrading Vault CLI from version %s to %s ...\n\n" "$${CURRENT_VERSION}" "$${VERSION}" printf "Upgrading Vault CLI from version %s to %s ...\n\n" "$${CURRENT_VERSION}" "$${VERSION}"
@ -96,6 +98,6 @@ export VAULT_ADDR="$${VAULT_ADDR}"
# Login to vault using the GitHub token # Login to vault using the GitHub token
printf "🔑 Logging in to Vault ...\n\n" printf "🔑 Logging in to Vault ...\n\n"
vault login -no-print -method=github -path=/$${AUTH_PATH} token="$${GITHUB_TOKEN}" vault login -no-print -method=github -path="/$${AUTH_PATH}" token="$${GITHUB_TOKEN}"
printf "🥳 Vault authentication complete!\n\n" printf "🥳 Vault authentication complete!\n\n"
printf "You can now use Vault CLI to access secrets.\n" printf "You can now use Vault CLI to access secrets.\n"

@ -2,13 +2,19 @@
BOLD='\033[0;1m' BOLD='\033[0;1m'
# Convert templated variables to shell variables
PORT=${PORT}
LOG_PATH=${LOG_PATH}
INSTALL_DIR=${INSTALL_DIR}
# Create install directory if it doesn't exist # Create install directory if it doesn't exist
mkdir -p ${INSTALL_DIR} mkdir -p "$${INSTALL_DIR}"
printf "$${BOLD}Installing vscode-cli!\n" printf "$${BOLD}Installing vscode-cli!\n"
# Download and extract code-cli tarball # Download and extract code-cli tarball
output=$(curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz && tar -xf vscode_cli.tar.gz -C ${INSTALL_DIR} && rm vscode_cli.tar.gz) output=$(curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz && tar -xf vscode_cli.tar.gz -C "$${INSTALL_DIR}" && rm vscode_cli.tar.gz)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to install vscode-cli: $output" echo "Failed to install vscode-cli: $output"
@ -16,6 +22,5 @@ if [ $? -ne 0 ]; then
fi fi
printf "🥳 vscode-cli has been installed.\n\n" 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..." printf "Check logs at %s\n\n" "$${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 &

Loading…
Cancel
Save