6cf4d9
#!/bin/sh
6cf4d9
6cf4d9
#set -vx
6cf4d9
6cf4d9
LCFILE=/etc/pki/ca-trust/ca-legacy.conf
6cf4d9
LLINK=/etc/pki/ca-trust/source/ca-bundle.legacy.crt
6cf4d9
LDEFAULT=/usr/share/pki/ca-trust-legacy/ca-bundle.legacy.default.crt
6cf4d9
LDISABLE=/usr/share/pki/ca-trust-legacy/ca-bundle.legacy.disable.crt
6cf4d9
6cf4d9
# An absent value, or any unexpected value, is treated as "default".
6cf4d9
is_disabled()
6cf4d9
{
6cf4d9
    grep -i "^legacy *= *disable *$" $LCFILE >/dev/null 2>&1
6cf4d9
}
6cf4d9
6cf4d9
do_check()
6cf4d9
{
6cf4d9
    is_disabled
6cf4d9
    if [ $? -eq 0 ]; then
6cf4d9
        echo "Legacy CAs are set to DISABLED in file $LCFILE (affects install/upgrade)"
6cf4d9
        LEXPECT=$LDISABLE
6cf4d9
    else
6cf4d9
        echo "Legacy CAs are set to DEFAULT in file $LCFILE (affects install/upgrade)"
6cf4d9
        LEXPECT=$LDEFAULT
6cf4d9
    fi
6cf4d9
    echo "Status of symbolic link $LLINK:"
6cf4d9
    readlink -v $LLINK
6cf4d9
}
6cf4d9
6cf4d9
do_install()
6cf4d9
{
6cf4d9
    is_disabled
6cf4d9
    if [ $? -eq 0 ]; then
6cf4d9
        # found, legacy is disabled
6cf4d9
        ln -sf $LDISABLE $LLINK
6cf4d9
    else
6cf4d9
        # expression not found, legacy is set to default
6cf4d9
        ln -sf $LDEFAULT $LLINK
6cf4d9
    fi
6cf4d9
}
6cf4d9
6cf4d9
do_default()
6cf4d9
{
6cf4d9
    sed -i 's/^legacy *=.*$/legacy=default/' $LCFILE
6cf4d9
    do_install
6cf4d9
    /usr/bin/update-ca-trust
6cf4d9
}
6cf4d9
6cf4d9
do_disable()
6cf4d9
{
6cf4d9
    sed -i 's/^legacy *=.*$/legacy=disable/' $LCFILE
6cf4d9
    do_install
6cf4d9
    /usr/bin/update-ca-trust
6cf4d9
}
6cf4d9
6cf4d9
do_help()
6cf4d9
{
6cf4d9
    echo "usage: $0 [check | default | disable | install]"
6cf4d9
}
6cf4d9
6cf4d9
if [[ $# -eq 0 ]]; then
6cf4d9
  # no parameters
6cf4d9
  do_help
6cf4d9
  exit $?
6cf4d9
fi
6cf4d9
6cf4d9
if [[ "$1" = "install" ]]; then
6cf4d9
  do_install
6cf4d9
  exit $?
6cf4d9
fi
6cf4d9
6cf4d9
if [[ "$1" = "default" ]]; then
6cf4d9
  do_default
6cf4d9
  exit $?
6cf4d9
fi
6cf4d9
if [[ "$1" = "disable" ]]; then
6cf4d9
  do_disable
6cf4d9
  exit $?
6cf4d9
fi
6cf4d9
6cf4d9
if [[ "$1" = "check" ]]; then
6cf4d9
  do_check
6cf4d9
  exit $?
6cf4d9
fi
6cf4d9
6cf4d9
echo "$0: Unsupported command $1"
6cf4d9
do_help