generate_config.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. #!/usr/bin/env bash
  2. # Ensure the script is run from the directory that contains a link of .env
  3. # Resolve the directory this script lives in for consistent behavior when invoked from elsewhere
  4. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
  5. # Ensure script is executed in the mailcow installation directory by checking for a .env symlink that points to mailcow.conf
  6. if [ ! -L "${PWD}/.env" ]; then
  7. echo -e "\e[33mPlease run this script from the mailcow installation directory.\e[0m"
  8. echo -e " \e[36mcd /path/to/mailcow && ./generate_config.sh\e[0m"
  9. exit 1
  10. fi
  11. # Verify the .env symlink points to a mailcow.conf file
  12. env_target="$(readlink -f "${PWD}/.env" 2>/dev/null || true)"
  13. if [ -z "$env_target" ] || [ "$(basename "$env_target")" != "mailcow.conf" ]; then
  14. echo -e "\e[31mThe found .env symlink does not point to a mailcow.conf file.\e[0m"
  15. echo -e "\e[33mPlease create a symbolic link .env -> mailcow.conf inside the mailcow directory and run this script there.\e[0m"
  16. echo -e "\e[33mNote: 'ln -s mailcow.conf .env' will create the symlink even if mailcow.conf does not yet exist.\e[0m"
  17. echo -e " \e[36mcd /path/to/mailcow && ln -s mailcow.conf .env && ./generate_config.sh\e[0m"
  18. exit 1
  19. fi
  20. # Load mailcow Generic Scripts
  21. source _modules/scripts/core.sh
  22. source _modules/scripts/ipv6_controller.sh
  23. set -o pipefail
  24. get_installed_tools
  25. get_docker_version
  26. if [[ $docker_version -lt 24 ]]; then
  27. echo -e "\e[31mCannot find Docker with a Version higher or equals 24.0.0\e[0m"
  28. echo -e "\e[33mmailcow needs a newer Docker version to work properly...\e[0m"
  29. echo -e "\e[31mPlease update your Docker installation... exiting\e[0m"
  30. exit 1
  31. fi
  32. detect_bad_asn
  33. ### If generate_config.sh is started with --dev or -d it will not check out nightly or master branch and will keep on the current branch
  34. if [[ ${1} == "--dev" || ${1} == "-d" ]]; then
  35. SKIP_BRANCH=y
  36. else
  37. SKIP_BRANCH=n
  38. fi
  39. if [ -f mailcow.conf ]; then
  40. read -r -p "A config file exists and will be overwritten, are you sure you want to continue? [y/N] " response
  41. case $response in
  42. [yY][eE][sS]|[yY])
  43. mv mailcow.conf mailcow.conf_backup
  44. chmod 600 mailcow.conf_backup
  45. ;;
  46. *)
  47. exit 1
  48. ;;
  49. esac
  50. fi
  51. echo "Press enter to confirm the detected value '[value]' where applicable or enter a custom value."
  52. while [ -z "${MAILCOW_HOSTNAME}" ]; do
  53. read -p "Mail server hostname (FQDN) - this is not your mail domain, but your mail servers hostname: " -e MAILCOW_HOSTNAME
  54. DOTS=${MAILCOW_HOSTNAME//[^.]};
  55. if [ ${#DOTS} -lt 1 ]; then
  56. echo -e "\e[31mMAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) is not a FQDN!\e[0m"
  57. sleep 1
  58. echo "Please change it to a FQDN and redeploy the stack with docker(-)compose up -d"
  59. exit 1
  60. elif [[ "${MAILCOW_HOSTNAME: -1}" == "." ]]; then
  61. echo "MAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) is ending with a dot. This is not a valid FQDN!"
  62. exit 1
  63. elif [ ${#DOTS} -eq 1 ]; then
  64. echo -e "\e[33mMAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) does not contain a Subdomain. This is not fully tested and may cause issues.\e[0m"
  65. echo "Find more information about why this message exists here: https://github.com/mailcow/mailcow-dockerized/issues/1572"
  66. read -r -p "Do you want to proceed anyway? [y/N] " response
  67. if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  68. echo "OK. Procceding."
  69. else
  70. echo "OK. Exiting."
  71. exit 1
  72. fi
  73. fi
  74. done
  75. if [ -a /etc/timezone ]; then
  76. DETECTED_TZ=$(cat /etc/timezone)
  77. elif [ -a /etc/localtime ]; then
  78. DETECTED_TZ=$(readlink /etc/localtime|sed -n 's|^.*zoneinfo/||p')
  79. fi
  80. while [ -z "${MAILCOW_TZ}" ]; do
  81. if [ -z "${DETECTED_TZ}" ]; then
  82. read -p "Timezone: " -e MAILCOW_TZ
  83. else
  84. read -p "Timezone [${DETECTED_TZ}]: " -e MAILCOW_TZ
  85. [ -z "${MAILCOW_TZ}" ] && MAILCOW_TZ=${DETECTED_TZ}
  86. fi
  87. done
  88. MEM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
  89. if [ -z "${SKIP_CLAMD}" ]; then
  90. if [ "${MEM_TOTAL}" -le "2621440" ]; then
  91. echo "Installed memory is <= 2.5 GiB. It is recommended to disable ClamAV to prevent out-of-memory situations."
  92. echo "ClamAV can be re-enabled by setting SKIP_CLAMD=n in mailcow.conf."
  93. read -r -p "Do you want to disable ClamAV now? [Y/n] " response
  94. case $response in
  95. [nN][oO]|[nN])
  96. SKIP_CLAMD=n
  97. ;;
  98. *)
  99. SKIP_CLAMD=y
  100. ;;
  101. esac
  102. else
  103. SKIP_CLAMD=n
  104. fi
  105. fi
  106. if [[ ${SKIP_BRANCH} != y ]]; then
  107. echo "Which branch of mailcow do you want to use?"
  108. echo ""
  109. echo "Available Branches:"
  110. echo "- master branch (stable updates) | default, recommended [1]"
  111. echo "- nightly branch (unstable updates, testing) | not-production ready [2]"
  112. echo "- legacy branch (supported until February 2026) | deprecated, security updates only [3]"
  113. sleep 1
  114. while [ -z "${MAILCOW_BRANCH}" ]; do
  115. read -r -p "Choose the Branch with it's number [1/2/3] " branch
  116. case $branch in
  117. [3])
  118. MAILCOW_BRANCH="legacy"
  119. ;;
  120. [2])
  121. MAILCOW_BRANCH="nightly"
  122. ;;
  123. *)
  124. MAILCOW_BRANCH="master"
  125. ;;
  126. esac
  127. done
  128. git fetch --all
  129. git checkout -f "$MAILCOW_BRANCH"
  130. elif [[ ${SKIP_BRANCH} == y ]]; then
  131. echo -e "\033[33mEnabled Dev Mode.\033[0m"
  132. echo -e "\033[33mNot checking out a different branch!\033[0m"
  133. MAILCOW_BRANCH=$(git rev-parse --short $(git rev-parse @{upstream}))
  134. else
  135. echo -e "\033[31mCould not determine branch input..."
  136. echo -e "\033[31mExiting."
  137. exit 1
  138. fi
  139. if [ ! -z "${MAILCOW_BRANCH}" ]; then
  140. git_branch=${MAILCOW_BRANCH}
  141. fi
  142. configure_ipv6
  143. [ ! -f ./data/conf/rspamd/override.d/worker-controller-password.inc ] && echo '# Placeholder' > ./data/conf/rspamd/override.d/worker-controller-password.inc
  144. cat << EOF > mailcow.conf
  145. # ------------------------------
  146. # mailcow web ui configuration
  147. # ------------------------------
  148. # example.org is _not_ a valid hostname, use a fqdn here.
  149. # Default admin user is "admin"
  150. # Default password is "moohoo"
  151. MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME}
  152. # Password hash algorithm
  153. # Only certain password hash algorithm are supported. For a fully list of supported schemes,
  154. # see https://docs.mailcow.email/models/model-passwd/
  155. MAILCOW_PASS_SCHEME=BLF-CRYPT
  156. # ------------------------------
  157. # SQL database configuration
  158. # ------------------------------
  159. DBNAME=mailcow
  160. DBUSER=mailcow
  161. # Please use long, random alphanumeric strings (A-Za-z0-9)
  162. DBPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 28)
  163. DBROOT=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 28)
  164. # ------------------------------
  165. # REDIS configuration
  166. # ------------------------------
  167. REDISPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 28)
  168. # ------------------------------
  169. # HTTP/S Bindings
  170. # ------------------------------
  171. # You should use HTTPS, but in case of SSL offloaded reverse proxies:
  172. # Might be important: This will also change the binding within the container.
  173. # If you use a proxy within Docker, point it to the ports you set below.
  174. # Do _not_ use IP:PORT in HTTP(S)_BIND or HTTP(S)_PORT
  175. # IMPORTANT: Do not use port 8081, 9081, 9082 or 65510!
  176. # Example: HTTP_BIND=1.2.3.4
  177. # For IPv4 leave it as it is: HTTP_BIND= & HTTPS_PORT=
  178. # For IPv6 see https://docs.mailcow.email/post_installation/firststeps-ip_bindings/
  179. HTTP_PORT=80
  180. HTTP_BIND=
  181. HTTPS_PORT=443
  182. HTTPS_BIND=
  183. # Redirect HTTP connections to HTTPS - y/n
  184. HTTP_REDIRECT=n
  185. # ------------------------------
  186. # Other bindings
  187. # ------------------------------
  188. # You should leave that alone
  189. # Format: 11.22.33.44:25 or 12.34.56.78:465 etc.
  190. SMTP_PORT=25
  191. SMTPS_PORT=465
  192. SUBMISSION_PORT=587
  193. IMAP_PORT=143
  194. IMAPS_PORT=993
  195. POP_PORT=110
  196. POPS_PORT=995
  197. SIEVE_PORT=4190
  198. DOVEADM_PORT=127.0.0.1:19991
  199. SQL_PORT=127.0.0.1:13306
  200. REDIS_PORT=127.0.0.1:7654
  201. # Your timezone
  202. # See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of timezones
  203. # Use the column named 'TZ identifier' + pay attention for the column named 'Notes'
  204. TZ=${MAILCOW_TZ}
  205. # Fixed project name
  206. # Please use lowercase letters only
  207. COMPOSE_PROJECT_NAME=mailcowdockerized
  208. # Used Docker Compose version
  209. # Switch here between native (compose plugin) and standalone
  210. # For more informations take a look at the mailcow docs regarding the configuration options.
  211. # Normally this should be untouched but if you decided to use either of those you can switch it manually here.
  212. # Please be aware that at least one of those variants should be installed on your machine or mailcow will fail.
  213. DOCKER_COMPOSE_VERSION=${COMPOSE_VERSION}
  214. # Set this to "allow" to enable the anyone pseudo user. Disabled by default.
  215. # When enabled, ACL can be created, that apply to "All authenticated users"
  216. # This should probably only be activated on mail hosts, that are used exclusivly by one organisation.
  217. # Otherwise a user might share data with too many other users.
  218. ACL_ANYONE=disallow
  219. # Garbage collector cleanup
  220. # Deleted domains and mailboxes are moved to /var/vmail/_garbage/timestamp_sanitizedstring
  221. # How long should objects remain in the garbage until they are being deleted? (value in minutes)
  222. # Check interval is hourly
  223. MAILDIR_GC_TIME=7200
  224. # Additional SAN for the certificate
  225. #
  226. # You can use wildcard records to create specific names for every domain you add to mailcow.
  227. # Example: Add domains "example.com" and "example.net" to mailcow, change ADDITIONAL_SAN to a value like:
  228. #ADDITIONAL_SAN=imap.*,smtp.*
  229. # This will expand the certificate to "imap.example.com", "smtp.example.com", "imap.example.net", "smtp.example.net"
  230. # plus every domain you add in the future.
  231. #
  232. # You can also just add static names...
  233. #ADDITIONAL_SAN=srv1.example.net
  234. # ...or combine wildcard and static names:
  235. #ADDITIONAL_SAN=imap.*,srv1.example.com
  236. #
  237. ADDITIONAL_SAN=
  238. # Obtain certificates for autodiscover.* and autoconfig.* domains.
  239. # This can be useful to switch off in case you are in a scenario where a reverse proxy already handles those.
  240. # There are mixed scenarios where ports 80,443 are occupied and you do not want to share certs
  241. # between services. So acme-mailcow obtains for maildomains and all web-things get handled
  242. # in the reverse proxy.
  243. AUTODISCOVER_SAN=y
  244. # Additional server names for mailcow UI
  245. #
  246. # Specify alternative addresses for the mailcow UI to respond to
  247. # This is useful when you set mail.* as ADDITIONAL_SAN and want to make sure mail.maildomain.com will always point to the mailcow UI.
  248. # If the server name does not match a known site, Nginx decides by best-guess and may redirect users to the wrong web root.
  249. # You can understand this as server_name directive in Nginx.
  250. # Comma separated list without spaces! Example: ADDITIONAL_SERVER_NAMES=a.b.c,d.e.f
  251. ADDITIONAL_SERVER_NAMES=
  252. # Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n
  253. SKIP_LETS_ENCRYPT=n
  254. # Create seperate certificates for all domains - y/n
  255. # this will allow adding more than 100 domains, but some email clients will not be able to connect with alternative hostnames
  256. # see https://doc.dovecot.org/admin_manual/ssl/sni_support
  257. ENABLE_SSL_SNI=n
  258. # Skip IPv4 check in ACME container - y/n
  259. SKIP_IP_CHECK=n
  260. # Skip HTTP verification in ACME container - y/n
  261. SKIP_HTTP_VERIFICATION=n
  262. # Skip Unbound (DNS Resolver) Healthchecks (NOT Recommended!) - y/n
  263. SKIP_UNBOUND_HEALTHCHECK=n
  264. # Skip ClamAV (clamd-mailcow) anti-virus (Rspamd will auto-detect a missing ClamAV container) - y/n
  265. SKIP_CLAMD=${SKIP_CLAMD}
  266. # Skip Olefy (olefy-mailcow) anti-virus for Office documents (Rspamd will auto-detect a missing Olefy container) - y/n
  267. SKIP_OLEFY=n
  268. # Skip SOGo: Will disable SOGo integration and therefore webmail, DAV protocols and ActiveSync support (experimental, unsupported, not fully implemented) - y/n
  269. SKIP_SOGO=n
  270. # Skip FTS (Fulltext Search) for Dovecot on low-memory, low-threaded systems or if you simply want to disable it.
  271. # Dovecot inside mailcow use Flatcurve as FTS Backend.
  272. SKIP_FTS=n
  273. # Dovecot Indexing (FTS) Process maximum heap size in MB, there is no recommendation, please see Dovecot docs.
  274. # Flatcurve (Xapian backend) is used as the FTS Indexer. It is supposed to be efficient in CPU and RAM consumption.
  275. # However: Please always monitor your Resource consumption!
  276. FTS_HEAP=128
  277. # Controls how many processes the Dovecot indexing process can spawn at max.
  278. # Too many indexing processes can use a lot of CPU and Disk I/O.
  279. # Please visit: https://doc.dovecot.org/configuration_manual/service_configuration/#indexer-worker for more informations
  280. FTS_PROCS=1
  281. # Allow admins to log into SOGo as email user (without any password)
  282. ALLOW_ADMIN_EMAIL_LOGIN=n
  283. # Enable watchdog (watchdog-mailcow) to restart unhealthy containers
  284. USE_WATCHDOG=y
  285. # Send watchdog notifications by mail (sent from watchdog@MAILCOW_HOSTNAME)
  286. # CAUTION:
  287. # 1. You should use external recipients
  288. # 2. Mails are sent unsigned (no DKIM)
  289. # 3. If you use DMARC, create a separate DMARC policy ("v=DMARC1; p=none;" in _dmarc.MAILCOW_HOSTNAME)
  290. # Multiple rcpts allowed, NO quotation marks, NO spaces
  291. #WATCHDOG_NOTIFY_EMAIL=a@example.com,b@example.com,c@example.com
  292. #WATCHDOG_NOTIFY_EMAIL=
  293. # Send notifications to a webhook URL that receives a POST request with the content type "application/json".
  294. # You can use this to send notifications to services like Discord, Slack and others.
  295. #WATCHDOG_NOTIFY_WEBHOOK=https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  296. # JSON body included in the webhook POST request. Needs to be in single quotes.
  297. # Following variables are available: SUBJECT, BODY
  298. #WATCHDOG_NOTIFY_WEBHOOK_BODY='{"username": "mailcow Watchdog", "content": "**${SUBJECT}**\n${BODY}"}'
  299. # Notify about banned IP (includes whois lookup)
  300. WATCHDOG_NOTIFY_BAN=n
  301. # Send a notification when the watchdog is started.
  302. WATCHDOG_NOTIFY_START=y
  303. # Subject for watchdog mails. Defaults to "Watchdog ALERT" followed by the error message.
  304. #WATCHDOG_SUBJECT=
  305. # Checks if mailcow is an open relay. Requires a SAL. More checks will follow.
  306. # https://www.servercow.de/mailcow?lang=en
  307. # https://www.servercow.de/mailcow?lang=de
  308. # No data is collected. Opt-in and anonymous.
  309. # Will only work with unmodified mailcow setups.
  310. WATCHDOG_EXTERNAL_CHECKS=n
  311. # Enable watchdog verbose logging
  312. WATCHDOG_VERBOSE=n
  313. # Max log lines per service to keep in Redis logs
  314. LOG_LINES=9999
  315. # Internal IPv4 /24 subnet, format n.n.n (expands to n.n.n.0/24)
  316. # Use private IPv4 addresses only, see https://en.wikipedia.org/wiki/Private_network#Private_IPv4_addresses
  317. IPV4_NETWORK=172.22.1
  318. # Internal IPv6 subnet in fc00::/7
  319. # Use private IPv6 addresses only, see https://en.wikipedia.org/wiki/Private_network#Private_IPv6_addresses
  320. IPV6_NETWORK=fd4d:6169:6c63:6f77::/64
  321. # Use this IPv4 for outgoing connections (SNAT)
  322. #SNAT_TO_SOURCE=
  323. # Use this IPv6 for outgoing connections (SNAT)
  324. #SNAT6_TO_SOURCE=
  325. # Create or override an API key for the web UI
  326. # You _must_ define API_ALLOW_FROM, which is a comma separated list of IPs
  327. # An API key defined as API_KEY has read-write access
  328. # An API key defined as API_KEY_READ_ONLY has read-only access
  329. # Allowed chars for API_KEY and API_KEY_READ_ONLY: a-z, A-Z, 0-9, -
  330. # You can define API_KEY and/or API_KEY_READ_ONLY
  331. #API_KEY=
  332. #API_KEY_READ_ONLY=
  333. #API_ALLOW_FROM=172.22.1.1,127.0.0.1
  334. # mail_home is ~/Maildir
  335. MAILDIR_SUB=Maildir
  336. # SOGo session timeout in minutes
  337. SOGO_EXPIRE_SESSION=480
  338. # DOVECOT_MASTER_USER and DOVECOT_MASTER_PASS must both be provided. No special chars.
  339. # Empty by default to auto-generate master user and password on start.
  340. # User expands to DOVECOT_MASTER_USER@mailcow.local
  341. # LEAVE EMPTY IF UNSURE
  342. DOVECOT_MASTER_USER=
  343. # LEAVE EMPTY IF UNSURE
  344. DOVECOT_MASTER_PASS=
  345. # WebAuthn device manufacturer verification
  346. # After setting WEBAUTHN_ONLY_TRUSTED_VENDORS=y only devices from trusted manufacturers are allowed
  347. # root certificates can be placed for validation under mailcow-dockerized/data/web/inc/lib/WebAuthn/rootCertificates
  348. WEBAUTHN_ONLY_TRUSTED_VENDORS=n
  349. # Spamhaus Data Query Service Key
  350. # Optional: Leave empty for none
  351. # Enter your key here if you are using a blocked ASN (OVH, AWS, Cloudflare e.g) for the unregistered Spamhaus Blocklist.
  352. # If empty, it will completely disable Spamhaus blocklists if it detects that you are running on a server using a blocked AS.
  353. # Otherwise it will work normally.
  354. SPAMHAUS_DQS_KEY=
  355. # IPv6 Controller Section
  356. # This variable controls the usage of IPv6 within mailcow.
  357. # Can either be true or false | Defaults to true
  358. # WARNING: MAKE SURE TO PROPERLY CONFIGURE IPv6 ON YOUR HOST FIRST BEFORE ENABLING THIS AS FAULTY CONFIGURATIONS CAN LEAD TO OPEN RELAYS!
  359. # A COMPLETE DOCKER STACK REBUILD (compose down && compose up -d) IS NEEDED TO APPLY THIS.
  360. ENABLE_IPV6=${IPV6_BOOL}
  361. # Prevent netfilter from setting an iptables/nftables rule to isolate the mailcow docker network - y/n
  362. # CAUTION: Disabling this may expose container ports to other neighbors on the same subnet, even if the ports are bound to localhost
  363. DISABLE_NETFILTER_ISOLATION_RULE=n
  364. EOF
  365. mkdir -p data/assets/ssl
  366. chmod 600 mailcow.conf
  367. # copy but don't overwrite existing certificate
  368. echo "Generating snake-oil certificate..."
  369. # Making Willich more popular
  370. openssl req -x509 -newkey rsa:4096 -keyout data/assets/ssl-example/key.pem -out data/assets/ssl-example/cert.pem -days 365 -subj "/C=DE/ST=NRW/L=Willich/O=mailcow/OU=mailcow/CN=${MAILCOW_HOSTNAME}" -sha256 -nodes
  371. echo "Copying snake-oil certificate..."
  372. cp -n -d data/assets/ssl-example/*.pem data/assets/ssl/
  373. # Set app_info.inc.php
  374. case ${git_branch} in
  375. master)
  376. mailcow_git_version=$(git describe --tags `git rev-list --tags --max-count=1`)
  377. ;;
  378. nightly)
  379. mailcow_git_version=$(git rev-parse --short $(git rev-parse @{upstream}))
  380. mailcow_last_git_version=""
  381. ;;
  382. legacy)
  383. mailcow_git_version=$(git rev-parse --short $(git rev-parse @{upstream}))
  384. mailcow_last_git_version=""
  385. ;;
  386. *)
  387. mailcow_git_version=$(git rev-parse --short HEAD)
  388. mailcow_last_git_version=""
  389. ;;
  390. esac
  391. # if [ ${git_branch} == "master" ]; then
  392. # mailcow_git_version=$(git describe --tags `git rev-list --tags --max-count=1`)
  393. # elif [ ${git_branch} == "nightly" ]; then
  394. # mailcow_git_version=$(git rev-parse --short $(git rev-parse @{upstream}))
  395. # mailcow_last_git_version=""
  396. # else
  397. # mailcow_git_version=$(git rev-parse --short HEAD)
  398. # mailcow_last_git_version=""
  399. # fi
  400. if [[ $SKIP_BRANCH != "y" ]]; then
  401. mailcow_git_commit=$(git rev-parse origin/${git_branch})
  402. mailcow_git_commit_date=$(git log -1 --format=%ci @{upstream} )
  403. else
  404. mailcow_git_commit=$(git rev-parse ${git_branch})
  405. mailcow_git_commit_date=$(git log -1 --format=%ci @{upstream} )
  406. git_branch=$(git rev-parse --abbrev-ref HEAD)
  407. fi
  408. if [ $? -eq 0 ]; then
  409. echo '<?php' > data/web/inc/app_info.inc.php
  410. echo ' $MAILCOW_GIT_VERSION="'$mailcow_git_version'";' >> data/web/inc/app_info.inc.php
  411. echo ' $MAILCOW_LAST_GIT_VERSION="";' >> data/web/inc/app_info.inc.php
  412. echo ' $MAILCOW_GIT_OWNER="mailcow";' >> data/web/inc/app_info.inc.php
  413. echo ' $MAILCOW_GIT_REPO="mailcow-dockerized";' >> data/web/inc/app_info.inc.php
  414. echo ' $MAILCOW_GIT_URL="https://github.com/mailcow/mailcow-dockerized";' >> data/web/inc/app_info.inc.php
  415. echo ' $MAILCOW_GIT_COMMIT="'$mailcow_git_commit'";' >> data/web/inc/app_info.inc.php
  416. echo ' $MAILCOW_GIT_COMMIT_DATE="'$mailcow_git_commit_date'";' >> data/web/inc/app_info.inc.php
  417. echo ' $MAILCOW_BRANCH="'$git_branch'";' >> data/web/inc/app_info.inc.php
  418. echo ' $MAILCOW_UPDATEDAT='$(date +%s)';' >> data/web/inc/app_info.inc.php
  419. echo '?>' >> data/web/inc/app_info.inc.php
  420. else
  421. echo '<?php' > data/web/inc/app_info.inc.php
  422. echo ' $MAILCOW_GIT_VERSION="'$mailcow_git_version'";' >> data/web/inc/app_info.inc.php
  423. echo ' $MAILCOW_LAST_GIT_VERSION="";' >> data/web/inc/app_info.inc.php
  424. echo ' $MAILCOW_GIT_OWNER="mailcow";' >> data/web/inc/app_info.inc.php
  425. echo ' $MAILCOW_GIT_REPO="mailcow-dockerized";' >> data/web/inc/app_info.inc.php
  426. echo ' $MAILCOW_GIT_URL="https://github.com/mailcow/mailcow-dockerized";' >> data/web/inc/app_info.inc.php
  427. echo ' $MAILCOW_GIT_COMMIT="";' >> data/web/inc/app_info.inc.php
  428. echo ' $MAILCOW_GIT_COMMIT_DATE="";' >> data/web/inc/app_info.inc.php
  429. echo ' $MAILCOW_BRANCH="'$git_branch'";' >> data/web/inc/app_info.inc.php
  430. echo ' $MAILCOW_UPDATEDAT='$(date +%s)';' >> data/web/inc/app_info.inc.php
  431. echo '?>' >> data/web/inc/app_info.inc.php
  432. echo -e "\e[33mCannot determine current git repository version...\e[0m"
  433. fi