├── .dockerignore
├── .env.example
├── .github
├── dependabot.yml
└── workflows
│ ├── create-release.yaml
│ ├── docker-build-push-dockerhub.yml
│ ├── scarf-data-export.yml
│ └── update-submodules.yml
├── .gitignore
├── .gitmodules
├── Dockerfile
├── Dockerfile.render
├── LICENSE
├── README.md
├── SECURITY.md
├── docker-compose.yaml
├── render.yaml
└── scripts
├── replace-placeholder.sh
├── start.sh
└── wait-for-it.sh
/.dockerignore:
--------------------------------------------------------------------------------
1 | .git
2 | .github
3 | .env.example
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | # Set this value to 'agree' to accept our license:
2 | # LICENSE: https://github.com/calendso/calendso/blob/main/LICENSE
3 | #
4 | # Summary of terms:
5 | # - The codebase has to stay open source, whether it was modified or not
6 | # - You can not repackage or sell the codebase
7 | # - Acquire a commercial license to remove these terms by emailing: license@cal.com
8 | NEXT_PUBLIC_LICENSE_CONSENT=
9 | LICENSE=
10 |
11 | # BASE_URL and NEXT_PUBLIC_APP_URL are both deprecated. Both are replaced with one variable, NEXT_PUBLIC_WEBAPP_URL
12 | # BASE_URL=http://localhost:3000
13 | # NEXT_PUBLIC_APP_URL=http://localhost:3000
14 |
15 | NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
16 | NEXT_PUBLIC_API_V2_URL=http://localhost:5555/api/v2
17 |
18 | # Configure NEXTAUTH_URL manually if needed, otherwise it will resolve to {NEXT_PUBLIC_WEBAPP_URL}/api/auth
19 | # NEXTAUTH_URL=http://localhost:3000/api/auth
20 |
21 | # It is highly recommended that the NEXTAUTH_SECRET must be overridden and very unique
22 | # Use `openssl rand -base64 32` to generate a key
23 | NEXTAUTH_SECRET=secret
24 |
25 | # Encryption key that will be used to encrypt CalDAV credentials, choose a random string, for example with `dd if=/dev/urandom bs=1K count=1 | md5sum`
26 | CALENDSO_ENCRYPTION_KEY=secret
27 |
28 | # Deprecation note: JWT_SECRET is no longer used
29 | # JWT_SECRET=secret
30 |
31 | POSTGRES_USER=unicorn_user
32 | POSTGRES_PASSWORD=magical_password
33 | POSTGRES_DB=calendso
34 | DATABASE_HOST=database:5432
35 | DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
36 | # Needed to run migrations while using a connection pooler like PgBouncer
37 | # Use the same one as DATABASE_URL if you're not using a connection pooler
38 | DATABASE_DIRECT_URL=${DATABASE_URL}
39 | GOOGLE_API_CREDENTIALS={}
40 |
41 | # Set this to '1' if you don't want Cal to collect anonymous usage
42 | CALCOM_TELEMETRY_DISABLED=
43 |
44 | # Used for the Office 365 / Outlook.com Calendar integration
45 | MS_GRAPH_CLIENT_ID=
46 | MS_GRAPH_CLIENT_SECRET=
47 |
48 | # Used for the Zoom integration
49 | ZOOM_CLIENT_ID=
50 | ZOOM_CLIENT_SECRET=
51 |
52 | # E-mail settings
53 | # Configures the global From: header whilst sending emails.
54 | EMAIL_FROM_NAME=YourOrganizationName
55 | EMAIL_FROM=notifications@example.com
56 |
57 | # Configure SMTP settings (@see https://nodemailer.com/smtp/).
58 | EMAIL_SERVER_HOST=smtp.example.com
59 | EMAIL_SERVER_PORT=587
60 | EMAIL_SERVER_USER=email_user
61 | EMAIL_SERVER_PASSWORD=email_password
62 |
63 | NODE_ENV=production
64 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | # Maintain dependencies for GitHub Actions
4 | - package-ecosystem: "github-actions"
5 | directory: "/"
6 | schedule:
7 | interval: "daily"
--------------------------------------------------------------------------------
/.github/workflows/create-release.yaml:
--------------------------------------------------------------------------------
1 | name: "Create Release"
2 |
3 | on: # yamllint disable-line rule:truthy
4 | workflow_dispatch:
5 | inputs:
6 | RELEASE_TAG:
7 | description: 'v{Major}.{Minor}.{Patch}'
8 |
9 | jobs:
10 | release:
11 | name: "Release"
12 | permissions:
13 | contents: write
14 | runs-on: "ubuntu-latest"
15 |
16 | steps:
17 |
18 | - name: Checkout source
19 | uses: actions/checkout@v3
20 | with:
21 | token: ${{ secrets.ACTIONS_ACCESS_TOKEN }}
22 | submodules: true
23 |
24 | - name: Create branch and tag submodule
25 | run: |
26 | git config user.email "actions@github.com"
27 | git config user.name "actions-user"
28 | git submodule update --init --remote
29 | git checkout -b 'release-${{ inputs.RELEASE_TAG }}'
30 | (cd calcom && git fetch --tags origin && git checkout 'refs/tags/${{ inputs.RELEASE_TAG }}')
31 | git add calcom
32 | git commit -m "tag version Cal.com version ${{ inputs.RELEASE_TAG }}"
33 | git push origin 'release-${{ inputs.RELEASE_TAG }}'
34 |
35 | # note: instead of secrets.GITHUB_TOKEN here, we need to use a PAT
36 | # so that the release creation triggers the image build workflow
37 | - name: "Create release"
38 | uses: "actions/github-script@v6"
39 | with:
40 | github-token: "${{ secrets.ACTIONS_ACCESS_TOKEN }}"
41 | script: |
42 | const isPreRelease = '${{ inputs.RELEASE_TAG }}'.includes('-rc');
43 | try {
44 | const response = await github.rest.repos.createRelease({
45 | draft: false,
46 | generate_release_notes: true,
47 | body: 'For Cal.com release details, see: https://github.com/calcom/cal.com/releases/tag/${{ inputs.RELEASE_TAG }}',
48 | name: '${{ inputs.RELEASE_TAG }}',
49 | target_commitish: 'release-${{ inputs.RELEASE_TAG }}',
50 | owner: context.repo.owner,
51 | prerelease: isPreRelease,
52 | repo: context.repo.repo,
53 | tag_name: '${{ inputs.RELEASE_TAG }}',
54 | });
55 |
56 | core.exportVariable('RELEASE_ID', response.data.id);
57 | core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url);
58 | } catch (error) {
59 | core.setFailed(error.message);
60 | }
61 |
--------------------------------------------------------------------------------
/.github/workflows/docker-build-push-dockerhub.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: Build and push image to DockerHub
4 |
5 | # Controls when the workflow will run
6 | on:
7 | push:
8 | branches:
9 | - 'main'
10 | tags:
11 | - 'v*'
12 | # update on run of Update Calendso nightly submodule update
13 | workflow_run:
14 | workflows: ["Update Calendso"]
15 | branches: [main]
16 | types:
17 | - completed
18 | # Allow running workflow manually from the Actions tab
19 | workflow_dispatch:
20 | # Uncomment below to allow specific version workflow run
21 | # inputs:
22 | # version:
23 | # description: 'Version to build'
24 | # required: true
25 |
26 | # Leaving in example for releases. Initially we simply push to 'latest'
27 | # on:
28 | # release:
29 | # types: [ created ]
30 |
31 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
32 | jobs:
33 | # This workflow contains a single job called "build"
34 | build:
35 | # The type of runner that the job will run on
36 | runs-on: ubuntu-latest
37 |
38 | # Steps represent a sequence of tasks that will be executed as part of the job
39 | steps:
40 | - name: Free Disk Space (Ubuntu)
41 | uses: jlumbroso/free-disk-space@main
42 | with:
43 | # Free about 4.5 GB, elminating our disk space issues
44 | tool-cache: true
45 |
46 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it, uncomment below
47 | # - name: Checkout code at specified version
48 | # uses: actions/checkout@v2
49 | # with:
50 | # ref: ${{ github.event.inputs.version }}
51 |
52 | - name: checkout
53 | uses: actions/checkout@v4
54 |
55 | - name: Git submodule update
56 | run: |
57 | git submodule update --init
58 |
59 | - name: Log in to the Docker Hub registry
60 | uses: docker/login-action@v3
61 | with:
62 | # Username used to log against the Docker registry
63 | username: ${{ secrets.DOCKER_HUB_USERNAME }}
64 | # Password or personal access token used to log against the Docker registry
65 | password: ${{ secrets.DOCKER_HUB_TOKEN }}
66 | # Log out from the Docker registry at the end of a job
67 | logout: true # optional, default is true
68 |
69 | - name: Log in to the Github Container registry
70 | uses: docker/login-action@v3
71 | with:
72 | registry: ghcr.io
73 | username: ${{ github.actor }}
74 | password: ${{ secrets.GITHUB_TOKEN }}
75 |
76 | - name: Docker meta
77 | id: meta
78 | uses: docker/metadata-action@v5
79 | with:
80 | images: |
81 | docker.io/calendso/calendso
82 | docker.io/calcom/cal.com
83 | ghcr.io/calcom/cal.com
84 | # Add flavor latest only on full releases, not on pre-releases
85 | flavor: |
86 | latest=${{ !github.event.release.prerelease }}
87 |
88 | - name: Copy env
89 | run: |
90 | grep -o '^[^#]*' .env.example > .env
91 | cat .env >> $GITHUB_ENV
92 | echo "DATABASE_HOST=localhost:5432" >> $GITHUB_ENV
93 | eval $(sed -e '/^#/d' -e 's/^/export /' -e 's/$/;/' .env) ;
94 |
95 | # Temporarily disable ARM build due to runner performance issues
96 | # - name: Set up QEMU
97 | # uses: docker/setup-qemu-action@v2
98 |
99 | - name: Start database
100 | run: |
101 | docker compose up -d database
102 |
103 | - name: Set up Docker Buildx
104 | uses: docker/setup-buildx-action@v3
105 | with:
106 | driver-opts: |
107 | network=container:database
108 | buildkitd-flags: |
109 | --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
110 | # config-inline: |
111 | # [worker.oci]
112 | # max-parallelism = 1
113 |
114 | - name: Build image
115 | id: docker_build
116 | uses: docker/build-push-action@v5
117 | with:
118 | context: ./
119 | file: ./Dockerfile
120 | load: true # Load the image into the Docker daemon
121 | push: false # Do not push the image at this stage
122 | platforms: linux/amd64
123 | tags: ${{ steps.meta.outputs.tags }}
124 | labels: ${{ steps.meta.outputs.labels }}
125 | build-args: |
126 | NEXT_PUBLIC_WEBAPP_URL=${{ env.NEXT_PUBLIC_WEBAPP_URL }}
127 | NEXT_PUBLIC_API_V2_URL=${{ env.NEXT_PUBLIC_API_V2_URL }}
128 | NEXT_PUBLIC_LICENSE_CONSENT=${{ env.NEXT_PUBLIC_LICENSE_CONSENT }}
129 | NEXT_PUBLIC_TELEMETRY_KEY=${{ env.NEXT_PUBLIC_TELEMETRY_KEY }}
130 | DATABASE_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }}
131 | DATABASE_DIRECT_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }}
132 |
133 | - name: Test runtime
134 | run: |
135 | tags="${{ steps.meta.outputs.tags }}"
136 | IFS=',' read -ra ADDR <<< "$tags" # Convert string to array using ',' as delimiter
137 | tag=${ADDR[0]} # Get the first tag
138 |
139 | docker run --rm --network stack \
140 | -p 3000:3000 \
141 | -e DATABASE_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@database/${{ env.POSTGRES_DB }} \
142 | -e DATABASE_DIRECT_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@database/${{ env.POSTGRES_DB }} \
143 | -e NEXTAUTH_SECRET=${{ env.NEXTAUTH_SECRET }} \
144 | -e CALENDSO_ENCRYPTION_KEY=${{ env.CALENDSO_ENCRYPTION_KEY }} \
145 | $tag &
146 |
147 | server_pid=$!
148 |
149 |
150 | echo "Waiting for the server to start..."
151 | sleep 120
152 |
153 | echo ${{ env.NEXT_PUBLIC_WEBAPP_URL }}/auth/login
154 |
155 | for i in {1..60}; do
156 | echo "Checking server health ($i/60)..."
157 | response=$(curl -o /dev/null -s -w "%{http_code}" ${{ env.NEXT_PUBLIC_WEBAPP_URL }}/auth/login)
158 | echo "HTTP Status Code: $response"
159 | if [[ "$response" == "200" ]] || [[ "$response" == "307" ]]; then
160 | echo "Server is healthy"
161 | # Now, shutdown the server
162 | kill $server_pid
163 | exit 0
164 | fi
165 | sleep 1
166 | done
167 |
168 | echo "Server health check failed"
169 | kill $server_pid
170 | exit 1
171 | env:
172 | NEXTAUTH_SECRET: 'EI4qqDpcfdvf4A+0aQEEx8JjHxHSy4uWiZw/F32K+pA='
173 | CALENDSO_ENCRYPTION_KEY: '0zfLtY99wjeLnsM7qsa8xsT+Q0oSgnOL'
174 |
175 | - name: Push image
176 | id: docker_push
177 | uses: docker/build-push-action@v5
178 | with:
179 | context: ./
180 | file: ./Dockerfile
181 | push: true
182 | platforms: linux/amd64
183 | tags: ${{ steps.meta.outputs.tags }}
184 | labels: ${{ steps.meta.outputs.labels }}
185 | build-args: |
186 | NEXT_PUBLIC_WEBAPP_URL=${{ env.NEXT_PUBLIC_WEBAPP_URL }}
187 | NEXT_PUBLIC_API_V2_URL=${{ env.NEXT_PUBLIC_API_V2_URL }}
188 | NEXT_PUBLIC_LICENSE_CONSENT=${{ env.NEXT_PUBLIC_LICENSE_CONSENT }}
189 | NEXT_PUBLIC_TELEMETRY_KEY=${{ env.NEXT_PUBLIC_TELEMETRY_KEY }}
190 | DATABASE_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }}
191 | DATABASE_DIRECT_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }}
192 | if: ${{ !github.event.release.prerelease }}
193 |
194 | - name: Image digest
195 | run: echo ${{ steps.docker_build.outputs.digest }}
196 |
197 | - name: Cleanup
198 | run: |
199 | docker compose down
200 |
--------------------------------------------------------------------------------
/.github/workflows/scarf-data-export.yml:
--------------------------------------------------------------------------------
1 | name: Export Scarf data
2 | on:
3 | schedule:
4 | - cron: '0 0 * * *'
5 |
6 | jobs:
7 | export-scarf-data:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: docker://scarf.docker.scarf.sh/scarf-sh/scarf-postgres-exporter:latest
11 | env:
12 | SCARF_API_TOKEN: ${{ secrets.SCARF_API_TOKEN }}
13 | SCARF_ENTITY_NAME: Calcom
14 | PSQL_CONN_STRING: ${{ secrets.PSQL_CONN_STRING }}
15 |
--------------------------------------------------------------------------------
/.github/workflows/update-submodules.yml:
--------------------------------------------------------------------------------
1 | name: Update Calendso
2 | on:
3 | schedule:
4 | - cron: "0 4 * * *"
5 | workflow_dispatch: ~
6 |
7 | jobs:
8 | sync:
9 | name: 'Submodules Sync'
10 | runs-on: ubuntu-latest
11 | defaults:
12 | run:
13 | shell: bash
14 | steps:
15 | - name: checkout
16 | uses: actions/checkout@v3
17 |
18 | - name: Git submodule update
19 | run: |
20 | git submodule update --remote --init
21 |
22 | - name: Commit
23 | run: |
24 | git config user.email "actions@github.com"
25 | git config user.name "actions-user"
26 | git commit -am "Auto updated submodule references" && git push || echo "No changes to commit"
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # .env file
4 | .env
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "calcom"]
2 | path = calcom
3 | url = https://github.com/calcom/cal.com.git
4 | branch = main
5 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:18 AS builder
2 |
3 | WORKDIR /calcom
4 |
5 | ARG NEXT_PUBLIC_LICENSE_CONSENT
6 | ARG NEXT_PUBLIC_WEBSITE_TERMS_URL
7 | ARG NEXT_PUBLIC_WEBSITE_PRIVACY_POLICY_URL
8 | ARG CALCOM_TELEMETRY_DISABLED
9 | ARG DATABASE_URL
10 | ARG NEXTAUTH_SECRET=secret
11 | ARG CALENDSO_ENCRYPTION_KEY=secret
12 | ARG MAX_OLD_SPACE_SIZE=4096
13 | ARG NEXT_PUBLIC_API_V2_URL
14 |
15 | ENV NEXT_PUBLIC_WEBAPP_URL=http://NEXT_PUBLIC_WEBAPP_URL_PLACEHOLDER \
16 | NEXT_PUBLIC_API_V2_URL=$NEXT_PUBLIC_API_V2_URL \
17 | NEXT_PUBLIC_LICENSE_CONSENT=$NEXT_PUBLIC_LICENSE_CONSENT \
18 | NEXT_PUBLIC_WEBSITE_TERMS_URL=$NEXT_PUBLIC_WEBSITE_TERMS_URL \
19 | NEXT_PUBLIC_WEBSITE_PRIVACY_POLICY_URL=$NEXT_PUBLIC_WEBSITE_PRIVACY_POLICY_URL \
20 | CALCOM_TELEMETRY_DISABLED=$CALCOM_TELEMETRY_DISABLED \
21 | DATABASE_URL=$DATABASE_URL \
22 | DATABASE_DIRECT_URL=$DATABASE_URL \
23 | NEXTAUTH_SECRET=${NEXTAUTH_SECRET} \
24 | CALENDSO_ENCRYPTION_KEY=${CALENDSO_ENCRYPTION_KEY} \
25 | NODE_OPTIONS=--max-old-space-size=${MAX_OLD_SPACE_SIZE} \
26 | BUILD_STANDALONE=true
27 |
28 | COPY calcom/package.json calcom/yarn.lock calcom/.yarnrc.yml calcom/playwright.config.ts calcom/turbo.json calcom/git-init.sh calcom/git-setup.sh calcom/i18n.json ./
29 | COPY calcom/.yarn ./.yarn
30 | COPY calcom/apps/web ./apps/web
31 | COPY calcom/apps/api/v2 ./apps/api/v2
32 | COPY calcom/packages ./packages
33 | COPY calcom/tests ./tests
34 |
35 | RUN yarn config set httpTimeout 1200000
36 | RUN npx turbo prune --scope=@calcom/web --scope=@calcom/trpc --docker
37 | RUN yarn install
38 | RUN yarn db-deploy
39 | RUN yarn --cwd packages/prisma seed-app-store
40 | # Build and make embed servable from web/public/embed folder
41 | RUN yarn workspace @calcom/trpc run build
42 | RUN yarn --cwd packages/embeds/embed-core workspace @calcom/embed-core run build
43 | RUN yarn --cwd apps/web workspace @calcom/web run build
44 |
45 | # RUN yarn plugin import workspace-tools && \
46 | # yarn workspaces focus --all --production
47 | RUN rm -rf node_modules/.cache .yarn/cache apps/web/.next/cache
48 |
49 | FROM node:18 AS builder-two
50 |
51 | WORKDIR /calcom
52 | ARG NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
53 |
54 | ENV NODE_ENV=production
55 |
56 | COPY calcom/package.json calcom/.yarnrc.yml calcom/turbo.json calcom/i18n.json ./
57 | COPY calcom/.yarn ./.yarn
58 | COPY --from=builder /calcom/yarn.lock ./yarn.lock
59 | COPY --from=builder /calcom/node_modules ./node_modules
60 | COPY --from=builder /calcom/packages ./packages
61 | COPY --from=builder /calcom/apps/web ./apps/web
62 | COPY --from=builder /calcom/packages/prisma/schema.prisma ./prisma/schema.prisma
63 | COPY scripts scripts
64 |
65 | # Save value used during this build stage. If NEXT_PUBLIC_WEBAPP_URL and BUILT_NEXT_PUBLIC_WEBAPP_URL differ at
66 | # run-time, then start.sh will find/replace static values again.
67 | ENV NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL \
68 | BUILT_NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL
69 |
70 | RUN scripts/replace-placeholder.sh http://NEXT_PUBLIC_WEBAPP_URL_PLACEHOLDER ${NEXT_PUBLIC_WEBAPP_URL}
71 |
72 | FROM node:18 AS runner
73 |
74 |
75 | WORKDIR /calcom
76 | COPY --from=builder-two /calcom ./
77 | ARG NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
78 | ENV NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL \
79 | BUILT_NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL
80 |
81 | ENV NODE_ENV=production
82 | EXPOSE 3000
83 |
84 | HEALTHCHECK --interval=30s --timeout=30s --retries=5 \
85 | CMD wget --spider http://localhost:3000 || exit 1
86 |
87 | CMD ["/calcom/scripts/start.sh"]
88 |
--------------------------------------------------------------------------------
/Dockerfile.render:
--------------------------------------------------------------------------------
1 | FROM calcom.docker.scarf.sh/calcom/cal.com
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2021 Calendso
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
19 | OR OTHER DEALINGS IN THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
Cal.com (formerly Calendso)
9 |
10 |
11 | The open-source Calendly alternative. (Docker Edition)
12 |
13 | Learn more »
14 |
15 |
16 | Slack
17 | ·
18 | Website
19 | ·
20 | Core Cal.com related Issues
21 | ·
22 | Docker specific Issues
23 | ·
24 | Roadmap
25 |
26 |
27 |
28 | # Docker
29 |
30 | This image can be found on DockerHub at [https://hub.docker.com/r/calcom/cal.com](https://hub.docker.com/r/calcom/cal.com)
31 |
32 | The Docker configuration for Cal.com is an effort powered by people within the community. Cal.com, Inc. does not yet provide official support for Docker, but we will accept fixes and documentation at this time. Use at your own risk.
33 |
34 | ## Important Notes
35 |
36 | This Docker Image is managed by the Cal.com Community. Join the team [here](https://github.com/calcom/docker/discussions/32). Support for this image can be found via the repository, located at [https://github.com/calcom/docker](https://github.com/calcom/docker)
37 |
38 | **Currently, this image is intended for local development/evaluation use only, as there are specific requirements for providing environmental variables at build-time in order to specify a non-localhost BASE_URL. (this is due to the nature of the static site compilation, which embeds the variable values). The ability to update these variables at runtime is in-progress and will be available in the future.**
39 |
40 | For Production, for the time being, please checkout the repository and build/push your own image privately.
41 |
42 | ## Requirements
43 |
44 | Make sure you have `docker` & `docker compose` installed on the server / system. Both are installed by most docker utilities, including Docker Desktop and Rancher Desktop.
45 |
46 | Note: `docker compose` without the hyphen is now the primary method of using docker-compose, per the Docker documentation.
47 |
48 | ## (Most users) Running Cal.com with Docker Compose
49 |
50 | If you are evaluating Cal.com or running with minimal to no modifications, this option is for you.
51 |
52 | 1. Clone calcom/docker
53 |
54 | ```bash
55 | git clone --recursive https://github.com/calcom/docker.git
56 | ```
57 |
58 | 2. Change into the directory
59 |
60 | ```bash
61 | cd docker
62 | ```
63 |
64 | 3. Prepare your configuration: Rename `.env.example` to `.env` and then update `.env`
65 |
66 | ```bash
67 | cp .env.example .env
68 | ```
69 |
70 | Most configurations can be left as-is, but for configuration options see [Important Run-time variables](#important-run-time-variables) below.
71 |
72 | Update the appropriate values in your .env file, then proceed.
73 |
74 | 4. (optional) Pre-Pull the images by running the following command:
75 |
76 | ```bash
77 | docker compose pull
78 | ```
79 |
80 | This will use the default image locations as specified by `image:` in the docker-compose.yaml file.
81 |
82 | Note: To aid with support, by default Scarf.sh is used as registry proxy for download metrics.
83 |
84 | 5. Start Cal.com via docker compose
85 |
86 | (Most basic users, and for First Run) To run the complete stack, which includes a local Postgres database, Cal.com web app, and Prisma Studio:
87 |
88 | ```bash
89 | docker compose up -d
90 | ```
91 |
92 | To run Cal.com web app and Prisma Studio against a remote database, ensure that DATABASE_URL is configured for an available database and run:
93 |
94 | ```bash
95 | docker compose up -d calcom studio
96 | ```
97 |
98 | To run only the Cal.com web app, ensure that DATABASE_URL is configured for an available database and run:
99 |
100 | ```bash
101 | docker compose up -d calcom
102 | ```
103 |
104 | **Note: to run in attached mode for debugging, remove `-d` from your desired run command.**
105 |
106 | 6. Open a browser to [http://localhost:3000](http://localhost:3000), or your defined NEXT_PUBLIC_WEBAPP_URL. The first time you run Cal.com, a setup wizard will initialize. Define your first user, and you're ready to go!
107 |
108 | ## Updating Cal.com
109 |
110 | 1. Stop the Cal.com stack
111 |
112 | ```bash
113 | docker compose down
114 | ```
115 |
116 | 2. Pull the latest changes
117 |
118 | ```bash
119 | docker compose pull
120 | ```
121 | 3. Update env vars as necessary.
122 | 4. Re-start the Cal.com stack
123 |
124 | ```bash
125 | docker compose up -d
126 | ```
127 |
128 | ## (Advanced users) Build and Run Cal.com
129 |
130 | 1. Clone calcom/docker
131 |
132 | ```bash
133 | git clone https://github.com/calcom/docker.git calcom-docker
134 | ```
135 |
136 | 2. Change into the directory
137 |
138 | ```bash
139 | cd calcom-docker
140 | ```
141 |
142 | 3. Update the calcom submodule.
143 |
144 | ```bash
145 | git submodule update --remote --init
146 | ```
147 |
148 | Note: DO NOT use recursive submodule update, otherwise you will receive a git authentication error.
149 |
150 | 4. Rename `.env.example` to `.env` and then update `.env`
151 |
152 | For configuration options see [Build-time variables](#build-time-variables) below. Update the appropriate values in your .env file, then proceed.
153 |
154 | 5. Build the Cal.com docker image:
155 |
156 | Note: Due to application configuration requirements, an available database is currently required during the build process.
157 |
158 | a) If hosting elsewhere, configure the `DATABASE_URL` in the .env file, and skip the next step
159 |
160 | b) If a local or temporary database is required, start a local database via docker compose.
161 |
162 | ```bash
163 | docker compose up -d database
164 | ```
165 |
166 | 6. Build Cal.com via docker compose (DOCKER_BUILDKIT=0 must be provided to allow a network bridge to be used at build time. This requirement will be removed in the future)
167 |
168 | ```bash
169 | DOCKER_BUILDKIT=0 docker compose build calcom
170 | ```
171 |
172 | 7. Start Cal.com via docker compose
173 |
174 | (Most basic users, and for First Run) To run the complete stack, which includes a local Postgres database, Cal.com web app, and Prisma Studio:
175 |
176 | ```bash
177 | docker compose up -d
178 | ```
179 |
180 | To run Cal.com web app and Prisma Studio against a remote database, ensure that DATABASE_URL is configured for an available database and run:
181 |
182 | ```bash
183 | docker compose up -d calcom studio
184 | ```
185 |
186 | To run only the Cal.com web app, ensure that DATABASE_URL is configured for an available database and run:
187 |
188 | ```bash
189 | docker compose up -d calcom
190 | ```
191 |
192 | **Note: to run in attached mode for debugging, remove `-d` from your desired run command.**
193 |
194 | 8. Open a browser to [http://localhost:3000](http://localhost:3000), or your defined NEXT_PUBLIC_WEBAPP_URL. The first time you run Cal.com, a setup wizard will initialize. Define your first user, and you're ready to go!
195 |
196 | ## Configuration
197 |
198 | ### Important Run-time variables
199 |
200 | These variables must also be provided at runtime
201 |
202 | | Variable | Description | Required | Default |
203 | | --- | --- | --- | --- |
204 | | CALCOM_LICENSE_KEY | Enterprise License Key | optional | |
205 | | NEXT_PUBLIC_WEBAPP_URL | Base URL of the site. NOTE: if this value differs from the value used at build-time, there will be a slight delay during container start (to update the statically built files). | optional | `http://localhost:3000` |
206 | | NEXTAUTH_URL | Location of the auth server. By default, this is the Cal.com docker instance itself. | optional | `{NEXT_PUBLIC_WEBAPP_URL}/api/auth` |
207 | | NEXTAUTH_SECRET | must match build variable | required | `secret` |
208 | | CALENDSO_ENCRYPTION_KEY | must match build variable | required | `secret` |
209 | | DATABASE_URL | database url with credentials - if using a connection pooler, this setting should point there | required | `postgresql://unicorn_user:magical_password@database:5432/calendso` |
210 | | DATABASE_DIRECT_URL | direct database url with credentials if using a connection pooler (e.g. PgBouncer, Prisma Accelerate, etc.) | optional | |
211 |
212 | ### Build-time variables
213 |
214 | If building the image yourself, these variables must be provided at the time of the docker build, and can be provided by updating the .env file. Currently, if you require changes to these variables, you must follow the instructions to build and publish your own image.
215 |
216 | Updating these variables is not required for evaluation, but is required for running in production. Instructions for generating variables can be found in the [cal.com instructions](https://github.com/calcom/cal.com)
217 |
218 | | Variable | Description | Required | Default |
219 | | --- | --- | --- | --- |
220 | | NEXT_PUBLIC_WEBAPP_URL | Base URL injected into static files | optional | `http://localhost:3000` |
221 | | NEXT_PUBLIC_LICENSE_CONSENT | license consent - true/false | | |
222 | | NEXT_PUBLIC_WEBSITE_TERMS_URL | custom URL for terms and conditions website | optional | `https://cal.com/terms` |
223 | | NEXT_PUBLIC_WEBSITE_PRIVACY_POLICY_URL | custom URL for privacy policy website | optional | `https://cal.com/privacy` |
224 | | CALCOM_TELEMETRY_DISABLED | Allow cal.com to collect anonymous usage data (set to `1` to disable) | | |
225 | | DATABASE_URL | database url with credentials - if using a connection pooler, this setting should point there | required | `postgresql://unicorn_user:magical_password@database:5432/calendso` |
226 | | DATABASE_DIRECT_URL | direct database url with credentials if using a connection pooler (e.g. PgBouncer, Prisma Accelerate, etc.) | optional | |
227 | | NEXTAUTH_SECRET | Cookie encryption key | required | `secret` |
228 | | CALENDSO_ENCRYPTION_KEY | Authentication encryption key | required | `secret` |
229 |
230 | ## Git Submodules
231 |
232 | This repository uses a git submodule.
233 |
234 | For users building their own images, to update the calcom submodule, use the following command:
235 |
236 | ```bash
237 | git submodule update --remote --init
238 | ```
239 |
240 | For more advanced usage, please refer to the git documentation: [https://git-scm.com/book/en/v2/Git-Tools-Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules)
241 |
242 | ## Troubleshooting
243 |
244 | ### SSL edge termination
245 |
246 | If running behind a load balancer which handles SSL certificates, you will need to add the environmental variable `NODE_TLS_REJECT_UNAUTHORIZED=0` to prevent requests from being rejected. Only do this if you know what you are doing and trust the services/load-balancers directing traffic to your service.
247 |
248 | ### Failed to commit changes: Invalid 'prisma.user.create()'
249 |
250 | Certain versions may have trouble creating a user if the field `metadata` is empty. Using an empty json object `{}` as the field value should resolve this issue. Also, the `id` field will autoincrement, so you may also try leaving the value of `id` as empty.
251 |
252 | ### CLIENT_FETCH_ERROR
253 |
254 | If you experience this error, it may be the way the default Auth callback in the server is using the WEBAPP_URL as a base url. The container does not necessarily have access to the same DNS as your local machine, and therefor needs to be configured to resolve to itself. You may be able to correct this by configuring `NEXTAUTH_URL=http://localhost:3000/api/auth`, to help the backend loop back to itself.
255 | ```
256 | docker-calcom-1 | @calcom/web:start: [next-auth][error][CLIENT_FETCH_ERROR]
257 | docker-calcom-1 | @calcom/web:start: https://next-auth.js.org/errors#client_fetch_error request to http://testing.localhost:3000/api/auth/session failed, reason: getaddrinfo ENOTFOUND testing.localhost {
258 | docker-calcom-1 | @calcom/web:start: error: {
259 | docker-calcom-1 | @calcom/web:start: message: 'request to http://testing.localhost:3000/api/auth/session failed, reason: getaddrinfo ENOTFOUND testing.localhost',
260 | docker-calcom-1 | @calcom/web:start: stack: 'FetchError: request to http://testing.localhost:3000/api/auth/session failed, reason: getaddrinfo ENOTFOUND testing.localhost\n' +
261 | docker-calcom-1 | @calcom/web:start: ' at ClientRequest. (/calcom/node_modules/next/dist/compiled/node-fetch/index.js:1:65756)\n' +
262 | docker-calcom-1 | @calcom/web:start: ' at ClientRequest.emit (node:events:513:28)\n' +
263 | docker-calcom-1 | @calcom/web:start: ' at ClientRequest.emit (node:domain:489:12)\n' +
264 | docker-calcom-1 | @calcom/web:start: ' at Socket.socketErrorListener (node:_http_client:494:9)\n' +
265 | docker-calcom-1 | @calcom/web:start: ' at Socket.emit (node:events:513:28)\n' +
266 | docker-calcom-1 | @calcom/web:start: ' at Socket.emit (node:domain:489:12)\n' +
267 | docker-calcom-1 | @calcom/web:start: ' at emitErrorNT (node:internal/streams/destroy:157:8)\n' +
268 | docker-calcom-1 | @calcom/web:start: ' at emitErrorCloseNT (node:internal/streams/destroy:122:3)\n' +
269 | docker-calcom-1 | @calcom/web:start: ' at processTicksAndRejections (node:internal/process/task_queues:83:21)',
270 | docker-calcom-1 | @calcom/web:start: name: 'FetchError'
271 | docker-calcom-1 | @calcom/web:start: },
272 | docker-calcom-1 | @calcom/web:start: url: 'http://testing.localhost:3000/api/auth/session',
273 | docker-calcom-1 | @calcom/web:start: message: 'request to http://testing.localhost:3000/api/auth/session failed, reason: getaddrinfo ENOTFOUND testing.localhost'
274 | docker-calcom-1 | @calcom/web:start: }
275 | ```
276 |
277 |
278 |
279 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security
2 | Contact: security@cal.com
3 |
4 | Based on [https://supabase.com/.well-known/security.txt](https://supabase.com/.well-known/security.txt)
5 |
6 | At Cal.com, we consider the security of our systems a top priority. But no matter how much effort we put into system security, there can still be vulnerabilities present.
7 |
8 | If you discover a vulnerability, we would like to know about it so we can take steps to address it as quickly as possible. We would like to ask you to help us better protect our clients and our systems.
9 |
10 | ## Out of scope vulnerabilities:
11 |
12 | * Clickjacking on pages with no sensitive actions.
13 | * Unauthenticated/logout/login CSRF.
14 | * Attacks requiring MITM or physical access to a user's device.
15 | * Any activity that could lead to the disruption of our service (DoS).
16 | * Content spoofing and text injection issues without showing an attack vector/without being able to modify HTML/CSS.
17 | * Email spoofing
18 | * Missing DNSSEC, CAA, CSP headers
19 | * Lack of Secure or HTTP only flag on non-sensitive cookies
20 | * Deadlinks
21 |
22 | ## Please do the following:
23 |
24 | * E-mail your findings to [security@cal.com](mailto:security@cal.com).
25 | * Do not run automated scanners on our infrastructure or dashboard. If you wish to do this, contact us and we will set up a sandbox for you.
26 | * Do not take advantage of the vulnerability or problem you have discovered, for example by downloading more data than necessary to demonstrate the vulnerability or deleting or modifying other people's data,
27 | * Do not reveal the problem to others until it has been resolved,
28 | * Do not use attacks on physical security, social engineering, distributed denial of service, spam or applications of third parties,
29 | * Do provide sufficient information to reproduce the problem, so we will be able to resolve it as quickly as possible. Usually, the IP address or the URL of the affected system and a description of the vulnerability will be sufficient, but complex vulnerabilities may require further explanation.
30 |
31 | ## What we promise:
32 |
33 | * We will respond to your report within 3 business days with our evaluation of the report and an expected resolution date,
34 | * If you have followed the instructions above, we will not take any legal action against you in regard to the report,
35 | * We will handle your report with strict confidentiality, and not pass on your personal details to third parties without your permission,
36 | * We will keep you informed of the progress towards resolving the problem,
37 | * In the public information concerning the problem reported, we will give your name as the discoverer of the problem (unless you desire otherwise), and
38 | * We strive to resolve all problems as quickly as possible, and we would like to play an active role in the ultimate publication on the problem after it is resolved.
39 |
--------------------------------------------------------------------------------
/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | # Use postgres/example user/password credentials
2 |
3 | volumes:
4 | database-data:
5 |
6 | networks:
7 | stack:
8 | name: stack
9 | external: false
10 |
11 | services:
12 | database:
13 | container_name: database
14 | image: postgres
15 | restart: always
16 | volumes:
17 | - database-data:/var/lib/postgresql/data/
18 | env_file: .env
19 | networks:
20 | - stack
21 |
22 | calcom:
23 | image: calcom.docker.scarf.sh/calcom/cal.com
24 | build:
25 | context: .
26 | dockerfile: Dockerfile
27 | args:
28 | NEXT_PUBLIC_WEBAPP_URL: ${NEXT_PUBLIC_WEBAPP_URL}
29 | NEXT_PUBLIC_API_V2_URL: ${NEXT_PUBLIC_API_V2_URL}
30 | NEXT_PUBLIC_LICENSE_CONSENT: ${NEXT_PUBLIC_LICENSE_CONSENT}
31 | NEXT_PUBLIC_WEBSITE_TERMS_URL: ${EXT_PUBLIC_WEBSITE_TERMS_URL}
32 | NEXT_PUBLIC_WEBSITE_PRIVACY_POLICY_URL: ${NEXT_PUBLIC_WEBSITE_PRIVACY_POLICY_URL}
33 | CALCOM_TELEMETRY_DISABLED: ${CALCOM_TELEMETRY_DISABLED}
34 | NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
35 | CALENDSO_ENCRYPTION_KEY: ${CALENDSO_ENCRYPTION_KEY}
36 | DATABASE_URL: ${DATABASE_URL}
37 | DATABASE_DIRECT_URL: ${DATABASE_URL}
38 | network: stack
39 | restart: always
40 | networks:
41 | - stack
42 | ports:
43 | - 3000:3000
44 | env_file: .env
45 | environment:
46 | - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
47 | - DATABASE_DIRECT_URL=${DATABASE_URL}
48 | depends_on:
49 | - database
50 |
51 | # Optional use of Prisma Studio. In production, comment out or remove the section below to prevent unwanted access to your database.
52 | studio:
53 | image: calcom.docker.scarf.sh/calcom/cal.com
54 | restart: always
55 | networks:
56 | - stack
57 | ports:
58 | - 5555:5555
59 | env_file: .env
60 | environment:
61 | - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
62 | - DATABASE_DIRECT_URL=${DATABASE_URL}
63 | depends_on:
64 | - database
65 | command:
66 | - npx
67 | - prisma
68 | - studio
69 | # END SECTION: Optional use of Prisma Studio.
70 |
--------------------------------------------------------------------------------
/render.yaml:
--------------------------------------------------------------------------------
1 | services:
2 | - type: web
3 | name: cal-web
4 | plan: standard
5 | repo: https://github.com/calcom/docker.git
6 | dockerfilePath: ./Dockerfile.render
7 | env: docker
8 | envVars:
9 |
10 | - key: DATABASE_URL
11 | fromDatabase:
12 | name: cal-postgres
13 | property: connectionString
14 |
15 | - key: CALENDSO_ENCRYPTION_KEY
16 | value: secret
17 |
18 | - key: NEXTAUTH_SECRET
19 | value: secret
20 |
21 | - key: CRON_API_KEY
22 | value: 0cc0e6c35519bba620c9360cfe3e68d0
23 |
24 | databases:
25 | - name: cal-postgres
26 | plan: basic-1gb
27 |
--------------------------------------------------------------------------------
/scripts/replace-placeholder.sh:
--------------------------------------------------------------------------------
1 | FROM=$1
2 | TO=$2
3 |
4 | if [ "${FROM}" = "${TO}" ]; then
5 | echo "Nothing to replace, the value is already set to ${TO}."
6 |
7 | exit 0
8 | fi
9 |
10 | # Only peform action if $FROM and $TO are different.
11 | echo "Replacing all statically built instances of $FROM with $TO."
12 |
13 | for file in $(egrep -r -l "${FROM}" apps/web/.next/ apps/web/public/); do
14 | sed -i -e "s|$FROM|$TO|g" "$file"
15 | done
16 |
--------------------------------------------------------------------------------
/scripts/start.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -x
3 |
4 | # Replace the statically built BUILT_NEXT_PUBLIC_WEBAPP_URL with run-time NEXT_PUBLIC_WEBAPP_URL
5 | # NOTE: if these values are the same, this will be skipped.
6 | scripts/replace-placeholder.sh "$BUILT_NEXT_PUBLIC_WEBAPP_URL" "$NEXT_PUBLIC_WEBAPP_URL"
7 |
8 | scripts/wait-for-it.sh ${DATABASE_HOST} -- echo "database is up"
9 | npx prisma migrate deploy --schema /calcom/packages/prisma/schema.prisma
10 | npx ts-node --transpile-only /calcom/packages/prisma/seed-app-store.ts
11 | yarn start
12 |
--------------------------------------------------------------------------------
/scripts/wait-for-it.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # The MIT License (MIT)
4 | #
5 | # Copyright (c) 2017 Eficode Oy
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in all
15 | # copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | # SOFTWARE.
24 |
25 | set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result"
26 | TIMEOUT=15
27 | QUIET=0
28 | # The protocol to make the request with, either "tcp" or "http"
29 | PROTOCOL="tcp"
30 |
31 | echoerr() {
32 | if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
33 | }
34 |
35 | usage() {
36 | exitcode="$1"
37 | cat << USAGE >&2
38 | Usage:
39 | $0 host:port|url [-t timeout] [-- command args]
40 | -q | --quiet Do not output any status messages
41 | -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
42 | -- COMMAND ARGS Execute command with args after the test finishes
43 | USAGE
44 | exit "$exitcode"
45 | }
46 |
47 | wait_for() {
48 | case "$PROTOCOL" in
49 | tcp)
50 | if ! command -v nc >/dev/null; then
51 | echoerr 'nc command is missing!'
52 | exit 1
53 | fi
54 | ;;
55 | wget)
56 | if ! command -v wget >/dev/null; then
57 | echoerr 'wget command is missing!'
58 | exit 1
59 | fi
60 | ;;
61 | esac
62 |
63 | while :; do
64 | case "$PROTOCOL" in
65 | tcp)
66 | nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
67 | ;;
68 | http)
69 | wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1
70 | ;;
71 | *)
72 | echoerr "Unknown protocol '$PROTOCOL'"
73 | exit 1
74 | ;;
75 | esac
76 |
77 | result=$?
78 |
79 | if [ $result -eq 0 ] ; then
80 | if [ $# -gt 7 ] ; then
81 | for result in $(seq $(($# - 7))); do
82 | result=$1
83 | shift
84 | set -- "$@" "$result"
85 | done
86 |
87 | TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7
88 | shift 7
89 | exec "$@"
90 | fi
91 | exit 0
92 | fi
93 |
94 | if [ "$TIMEOUT" -le 0 ]; then
95 | break
96 | fi
97 | TIMEOUT=$((TIMEOUT - 1))
98 |
99 | sleep 1
100 | done
101 | echo "Operation timed out" >&2
102 | exit 1
103 | }
104 |
105 | while :; do
106 | case "$1" in
107 | http://*|https://*)
108 | HOST="$1"
109 | PROTOCOL="http"
110 | shift 1
111 | ;;
112 | *:* )
113 | HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
114 | PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
115 | shift 1
116 | ;;
117 | -q | --quiet)
118 | QUIET=1
119 | shift 1
120 | ;;
121 | -q-*)
122 | QUIET=0
123 | echoerr "Unknown option: $1"
124 | usage 1
125 | ;;
126 | -q*)
127 | QUIET=1
128 | result=$1
129 | shift 1
130 | set -- -"${result#-q}" "$@"
131 | ;;
132 | -t | --timeout)
133 | TIMEOUT="$2"
134 | shift 2
135 | ;;
136 | -t*)
137 | TIMEOUT="${1#-t}"
138 | shift 1
139 | ;;
140 | --timeout=*)
141 | TIMEOUT="${1#*=}"
142 | shift 1
143 | ;;
144 | --)
145 | shift
146 | break
147 | ;;
148 | --help)
149 | usage 0
150 | ;;
151 | -*)
152 | QUIET=0
153 | echoerr "Unknown option: $1"
154 | usage 1
155 | ;;
156 | *)
157 | QUIET=0
158 | echoerr "Unknown argument: $1"
159 | usage 1
160 | ;;
161 | esac
162 | done
163 |
164 | if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
165 | echoerr "Error: invalid timeout '$TIMEOUT'"
166 | usage 3
167 | fi
168 |
169 | case "$PROTOCOL" in
170 | tcp)
171 | if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then
172 | echoerr "Error: you need to provide a host and port to test."
173 | usage 2
174 | fi
175 | ;;
176 | http)
177 | if [ "$HOST" = "" ]; then
178 | echoerr "Error: you need to provide a host to test."
179 | usage 2
180 | fi
181 | ;;
182 | esac
183 |
184 | wait_for "$@"
185 |
--------------------------------------------------------------------------------