|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +if type update-alternatives >/dev/null 2>&1; then |
| 4 | + # Remove previous link if it doesn't use update-alternatives |
| 5 | + if [ -L '/usr/bin/t3code' -a -e '/usr/bin/t3code' -a "`readlink '/usr/bin/t3code'`" != '/etc/alternatives/t3code' ]; then |
| 6 | + rm -f '/usr/bin/t3code' |
| 7 | + fi |
| 8 | + update-alternatives --install '/usr/bin/t3code' 't3code' '/opt/t3code/t3code' 100 || ln -sf '/opt/t3code/t3code' '/usr/bin/t3code' |
| 9 | +else |
| 10 | + ln -sf '/opt/t3code/t3code' '/usr/bin/t3code' |
| 11 | +fi |
| 12 | + |
| 13 | +# Check if user namespaces are supported by the kernel and working with a quick test: |
| 14 | +if ! { [[ -L /proc/self/ns/user ]] && unshare --user true; }; then |
| 15 | + # Use SUID chrome-sandbox only on systems without user namespaces: |
| 16 | + chmod 4755 '/opt/t3code/chrome-sandbox' || true |
| 17 | +else |
| 18 | + chmod 0755 '/opt/t3code/chrome-sandbox' || true |
| 19 | +fi |
| 20 | + |
| 21 | +if hash update-mime-database 2>/dev/null; then |
| 22 | + update-mime-database /usr/share/mime || true |
| 23 | +fi |
| 24 | + |
| 25 | +if hash update-desktop-database 2>/dev/null; then |
| 26 | + update-desktop-database /usr/share/applications || true |
| 27 | +fi |
| 28 | + |
| 29 | +# Install apparmor profile. (Ubuntu 24+) |
| 30 | +# First check if the version of AppArmor running on the device supports our profile. |
| 31 | +# This is in order to keep backwards compatibility with Ubuntu 22.04 which does not support abi/4.0. |
| 32 | +# In that case, we just skip installing the profile since the app runs fine without it on 22.04. |
| 33 | +# |
| 34 | +# Those apparmor_parser flags are akin to performing a dry run of loading a profile. |
| 35 | +# https://wiki.debian.org/AppArmor/HowToUse#Dumping_profiles |
| 36 | +# |
| 37 | +# Unfortunately, at the moment AppArmor doesn't have a good story for backwards compatibility. |
| 38 | +# https://askubuntu.com/questions/1517272/writing-a-backwards-compatible-apparmor-profile |
| 39 | +if apparmor_status --enabled > /dev/null 2>&1; then |
| 40 | + APPARMOR_PROFILE_SOURCE='/opt/t3code/resources/apparmor-profile' |
| 41 | + APPARMOR_PROFILE_TARGET='/etc/apparmor.d/t3code' |
| 42 | + if apparmor_parser --skip-kernel-load --debug "$APPARMOR_PROFILE_SOURCE" > /dev/null 2>&1; then |
| 43 | + cp -f "$APPARMOR_PROFILE_SOURCE" "$APPARMOR_PROFILE_TARGET" |
| 44 | + |
| 45 | + # Updating the current AppArmor profile is not possible and probably not meaningful in a chroot'ed environment. |
| 46 | + # Use cases are for example environments where images for clients are maintained. |
| 47 | + # There, AppArmor might correctly be installed, but live updating makes no sense. |
| 48 | + if ! { [ -x '/usr/bin/ischroot' ] && /usr/bin/ischroot; } && hash apparmor_parser 2>/dev/null; then |
| 49 | + # Extra flags taken from dh_apparmor: |
| 50 | + # > By using '-W -T' we ensure that any abstraction updates are also pulled in. |
| 51 | + # https://wiki.debian.org/AppArmor/Contribute/FirstTimeProfileImport |
| 52 | + apparmor_parser --replace --write-cache --skip-read-cache "$APPARMOR_PROFILE_TARGET" |
| 53 | + fi |
| 54 | + else |
| 55 | + echo "Skipping the installation of the AppArmor profile as this version of AppArmor does not seem to support the bundled profile" |
| 56 | + fi |
| 57 | +fi |
0 commit comments