-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
214 lines (188 loc) · 8.84 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#
# Entra ID SSO via Microsoft Identity Broker on Linux
#
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: Copyright (c) Jan Kiszka, 2020-2024
# SPDX-FileCopyrightText: Copyright (c) Siemens AG, 2024
#
# Authors:
# Jan Kiszka <jan.kiszka@siemens.com>
# Felix Moessbauer <felix.moessbauer@siemens.com>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
prefix ?= /usr/local
exec_prefix ?= $(prefix)
libexecdir ?= $(exec_prefix)/libexec
# do not prefix with $(prefix) as these dirs are defined by the browsers
firefox_nm_dir ?= /usr/lib/mozilla/native-messaging-hosts
chrome_nm_dir ?= /etc/opt/chrome/native-messaging-hosts
chrome_ext_dir ?= /usr/share/google-chrome/extensions
chromium_nm_dir ?= /etc/chromium/native-messaging-hosts
# python3 system interpreter for global installs
python3_bin ?= $(shell which python3)
ifeq ($(V),1)
Q =
else
Q = @
endif
PACKAGE_NAME=Linux-Entra-SSO
RELEASE_TAG ?= $(shell git describe --match "v[0-9].[0-9]*" --dirty)
WEBEXT_VERSION=$(shell echo $(RELEASE_TAG) | sed -e s:^v::)
ARCHIVE_NAME=$(PACKAGE_NAME)-$(RELEASE_TAG)
COMMON_INPUT_FILES= \
LICENSES/MPL-2.0.txt \
background.js \
popup/menu.css \
popup/menu.js \
popup/menu.html
CHROME_INPUT_FILES= \
$(COMMON_INPUT_FILES) \
platform/chrome/manifest.json \
platform/chrome/manifest.json.license \
icons/linux-entra-sso_48.png \
icons/linux-entra-sso_48.png.license \
icons/linux-entra-sso_128.png \
icons/linux-entra-sso_128.png.license \
icons/profile-outline_48.png \
icons/profile-outline_48.png.license
FIREFOX_INPUT_FILES= \
$(COMMON_INPUT_FILES) \
platform/firefox/manifest.json \
platform/firefox/manifest.json.license \
icons/linux-entra-sso.svg \
icons/profile-outline.svg
# common files for all platforms (relative to build directory)
CHROME_PACKAGE_FILES= \
$(COMMON_INPUT_FILES) \
manifest.json \
manifest.json.license \
icons/linux-entra-sso_48.png \
icons/linux-entra-sso_48.png.license \
icons/linux-entra-sso_128.png \
icons/linux-entra-sso_128.png.license \
icons/profile-outline_48.png \
icons/profile-outline_48.png.license \
popup/profile-outline.svg
FIREFOX_PACKAGE_FILES= \
$(COMMON_INPUT_FILES) \
manifest.json \
manifest.json.license \
icons/linux-entra-sso.svg \
popup/profile-outline.svg
UPDATE_VERSION='s|"version":.*|"version": "$(VERSION)",|'
UPDATE_VERSION_PY='s|0.0.0-dev|$(WEBEXT_VERSION)|g'
UPDATE_PYTHON_INTERPRETER='1,1s:^\#!.*:\#!$(python3_bin):'
CHROME_EXT_ID=$(shell $(CURDIR)/platform/chrome/get-ext-id.py $(CURDIR)/build/chrome/)
CHROME_EXT_ID_SIGNED=jlnfnnolkbjieggibinobhkjdfbpcohn
# debian package related vars
DEBIAN_PV = $(shell echo $(RELEASE_TAG) | sed -e s:^v::)
DEBIAN_PN = linux-entra-sso
DEBIAN_DESCRIPTION = Entra ID SSO via Microsoft Identity Broker on Linux
DEBIAN_DESTDIR := $(CURDIR)/debuild.d
DEBIAN_ARCH = all
DEBIAN_PKG_DIR = $(CURDIR)/pkgs
DEBIAN_PKG_FILE = $(DEBIAN_PKG_DIR)/$(DEBIAN_PN)_$(DEBIAN_PV)_$(DEBIAN_ARCH).deb
all package: clean $(CHROME_INPUT_FILES) $(FIREFOX_INPUT_FILES)
for P in firefox chrome; do \
mkdir -p build/$$P/icons build/$$P/popup; \
cp platform/$$P/manifest* build/$$P; \
cp -rf LICENSES background.js build/$$P/; \
done
cp icons/*.svg build/firefox/icons/
cp icons/*.png* icons/profile-outline.svg build/chrome/icons/
cp popup/menu.* icons/linux-entra-sso.svg icons/profile-outline.svg build/firefox/popup/
cp popup/menu.* icons/linux-entra-sso.svg icons/profile-outline.svg build/chrome/popup/
cd build/firefox && zip -r ../$(ARCHIVE_NAME).firefox.xpi $(FIREFOX_PACKAGE_FILES) && cd ../../;
cd build/chrome && zip -r ../$(ARCHIVE_NAME).chrome.zip $(CHROME_PACKAGE_FILES) && cd ../../;
deb:
$(MAKE) install DESTDIR=$(DEBIAN_DESTDIR) python3_bin=/usr/bin/python3 prefix=/usr
install --mode 644 -D --target-directory=$(DEBIAN_DESTDIR)/usr/share/doc/$(DEBIAN_PN) README.md CONTRIBUTING.md MAINTAINERS.md PRIVACY.md LICENSES/MPL-2.0.txt
install --mode 755 --directory $(DEBIAN_DESTDIR)/DEBIAN
{ \
echo Package: $(DEBIAN_PN); \
echo Architecture: $(DEBIAN_ARCH); \
echo Section: admin; \
echo Priority: optional; \
echo 'Maintainer: Dr. Johann Pfefferl <johann.pfefferl@siemens.com>'; \
echo Installed-Size: `du --summarize $(DEBIAN_DESTDIR) | cut --fields=1`; \
echo 'Depends: python3-pydbus, python3-gi'; \
echo Version: $(DEBIAN_PV); \
echo Description: $(DEBIAN_DESCRIPTION); \
} > $(DEBIAN_DESTDIR)/DEBIAN/control
install --mode 775 --directory $(DEBIAN_PKG_DIR)
dpkg-deb --deb-format=2.0 --root-owner-group --build $(DEBIAN_DESTDIR) $(DEBIAN_PKG_DIR)
@echo Package can be found here: $(DEBIAN_PKG_FILE)
deb_clean:
rm -rf $(DEBIAN_PKG_DIR) $(DEBIAN_DESTDIR)
clean: deb_clean
rm -rf build
release:
${Q}if [ -z "$(VERSION)" ]; then \
echo "VERSION is not set"; \
exit 1; \
fi
${Q}if [ -n "`git status -s -uno`" ]; then \
echo "Working directory is dirty!"; \
exit 1; \
fi
${Q}sed -i $(UPDATE_VERSION) platform/*/manifest.json
git commit -s platform/firefox/manifest.json platform/chrome/manifest.json -m "Bump version number"
git tag -as v$(VERSION) -m "Release v$(VERSION)"
local-install-firefox:
install -d ~/.mozilla/native-messaging-hosts
install -m 0644 platform/firefox/linux_entra_sso.json ~/.mozilla/native-messaging-hosts
${Q}sed -i 's|/usr/local/lib/linux-entra-sso/|'$(HOME)'/.mozilla/|' ~/.mozilla/native-messaging-hosts/linux_entra_sso.json
install -m 0755 linux-entra-sso.py ~/.mozilla
${Q}sed -i $(UPDATE_VERSION_PY) ~/.mozilla/linux-entra-sso.py
local-install-chrome:
install -d ~/.config/google-chrome/NativeMessagingHosts
install -d ~/.config/chromium/NativeMessagingHosts
install -m 0644 platform/chrome/linux_entra_sso.json ~/.config/google-chrome/NativeMessagingHosts
install -m 0644 platform/chrome/linux_entra_sso.json ~/.config/chromium/NativeMessagingHosts
${Q}sed -i 's|/usr/local/lib/linux-entra-sso/|'$(HOME)'/.config/google-chrome/|' ~/.config/google-chrome/NativeMessagingHosts/linux_entra_sso.json
${Q}sed -i 's|/usr/local/lib/linux-entra-sso/|'$(HOME)'/.config/google-chrome/|' ~/.config/chromium/NativeMessagingHosts/linux_entra_sso.json
# compute extension id and and grant permission
${Q}sed -i 's|{extension_id}|$(CHROME_EXT_ID)|' ~/.config/google-chrome/NativeMessagingHosts/linux_entra_sso.json
${Q}sed -i 's|{extension_id}|$(CHROME_EXT_ID)|' ~/.config/chromium/NativeMessagingHosts/linux_entra_sso.json
install -m 0755 linux-entra-sso.py ~/.config/google-chrome
${Q}sed -i $(UPDATE_VERSION_PY) ~/.config/google-chrome/linux-entra-sso.py
local-install: local-install-firefox local-install-chrome
install:
${Q}[ -z "$(python3_bin)" ] && { echo "python3 not found. Please set 'python3_bin'."; exit 1; } || true
# Host application
install -d $(DESTDIR)/$(libexecdir)/linux-entra-sso
install -m 0755 linux-entra-sso.py $(DESTDIR)/$(libexecdir)/linux-entra-sso
${Q}sed -i $(UPDATE_VERSION_PY) $(DESTDIR)/$(libexecdir)/linux-entra-sso/linux-entra-sso.py
${Q}sed -i $(UPDATE_PYTHON_INTERPRETER) $(DESTDIR)/$(libexecdir)/linux-entra-sso/linux-entra-sso.py
# Firefox
install -d $(DESTDIR)/$(firefox_nm_dir)
install -m 0644 platform/firefox/linux_entra_sso.json $(DESTDIR)/$(firefox_nm_dir)
${Q}sed -i 's|/usr/local/lib/|'$(libexecdir)/'|' $(DESTDIR)/$(firefox_nm_dir)/linux_entra_sso.json
# Chrome
install -d $(DESTDIR)/$(chrome_nm_dir)
install -m 0644 platform/chrome/linux_entra_sso.json $(DESTDIR)/$(chrome_nm_dir)
${Q}sed -i 's|/usr/local/lib/|'$(libexecdir)/'|' $(DESTDIR)/$(chrome_nm_dir)/linux_entra_sso.json
${Q}sed -i '/{extension_id}/d' $(DESTDIR)/$(chrome_nm_dir)/linux_entra_sso.json
install -d $(DESTDIR)/$(chrome_ext_dir)
install -m 0644 platform/chrome/extension.json $(DESTDIR)/$(chrome_ext_dir)/$(CHROME_EXT_ID_SIGNED).json
# Chromium
install -d $(DESTDIR)/$(chromium_nm_dir)
install -m 0644 platform/chrome/linux_entra_sso.json $(DESTDIR)/$(chromium_nm_dir)
${Q}sed -i 's|/usr/local/lib/|'$(libexecdir)/'|' $(DESTDIR)/$(chromium_nm_dir)/linux_entra_sso.json
${Q}sed -i '/{extension_id}/d' $(DESTDIR)/$(chromium_nm_dir)/linux_entra_sso.json
uninstall:
rm -rf $(DESTDIR)/$(libexecdir)/linux-entra-sso
rm -f $(DESTDIR)/$(firefox_nm_dir)/linux_entra_sso.json
rm -f $(DESTDIR)/$(chrome_nm_dir)/linux_entra_sso.json
rm -f $(DESTDIR)/$(chromium_nm_dir)/linux_entra_sso.json
rm -f $(DESTDIR)/$(chrome_ext_dir)/$(CHROME_EXT_ID_SIGNED).json
local-uninstall-firefox:
rm -f ~/.mozilla/native-messaging-hosts/linux_entra_sso.json ~/.mozilla/linux-entra-sso.py
local-uninstall-chrome:
rm -f ~/.config/google-chrome/NativeMessagingHosts/linux_entra_sso.json ~/.config/google-chrome/linux-entra-sso.py
rm -f ~/.config/chromium/NativeMessagingHosts/linux_entra_sso.json
local-uninstall: local-uninstall-firefox local-uninstall-chrome
.PHONY: clean release local-install-firefox local-install-chrome local-install install local-uninstall-firefox local-uninstall-chrome local-uninstall uninstall deb deb_clean