"Fossies" - the Fresh Open Source Software Archive

Member "LinOTP-release-2.10.5.2/linotpd/src/debian/config" (13 May 2019, 10234 Bytes) of package /linux/misc/LinOTP-release-2.10.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash -e
    2 . /usr/share/debconf/confmodule
    3 
    4 #if [ -f /usr/share/dbconfig-common/dpkg/config.mysql ]; then
    5 #    . /usr/share/dbconfig-common/dpkg/config.mysql
    6 #    dbc_go linotp "$@"
    7 #fi
    8 
    9 msg="LinOTP2: "
   10 
   11 echo_prio() {
   12     t=$(date +"%Y/%m/%d - %T")
   13     echo >&2 "$t $1 [linotp config] $2"
   14 }
   15 echo_info() {
   16     echo_prio INFO "$1"
   17 }
   18 echo_warn() {
   19     echo_prio WARNING "$1"
   20 }
   21 echo_log() {
   22     echo >&2 "${msg}$1"
   23 }
   24 
   25 # Just like other maintainer scripts, config scripts must be idempotent. The
   26 # config script is passed 2 parameters. The first is either "configure" or
   27 # "reconfigure". The latter occurs only if a package is being reconfigured by
   28 # dpkg-reconfig. The second parameter is the last version of the package that
   29 # was configured.
   30 #
   31 # http://www.fifi.org/doc/debconf-doc/tutorial.html
   32 
   33 # Like the postinst, the config script is passed two parameters when it is run.
   34 # The first tells what action is being performed, and the second is the version
   35 # of the package that is currently installed. So, like in a postinst, you can
   36 # use dpkg --compare-versions on $2 to make some behavior happen only on
   37 # upgrade from a particular version of a package, and things like that.
   38 #
   39 # man debconf-devel
   40 
   41 
   42 # I have observed following behaviour:
   43 #
   44 #   During first installation or after installing following 'apt-get purge'
   45 #   this script is invoked twice, both times with following output:
   46 #     INFO [linotp config] Installing new package?: true
   47 #     INFO [linotp config] Re-installing package?: false
   48 #     INFO [linotp config] Reconfiguring package?: false
   49 #     INFO [linotp config] Currently installed version: 
   50 #     INFO [linotp config] New version: 2.8~0dev0+g09d8dab-1~trusty
   51 #     INFO [linotp config] Version equal: 
   52 #     INFO [linotp config] Version upgrade: 
   53 #     INFO [linotp config] Version downgrade: 
   54 #
   55 #
   56 #  During installation following 'apt-get remove' this script is invoked twice
   57 #  with following output:
   58 #     INFO [linotp config] Installing new package?: true
   59 #     INFO [linotp config] Re-installing package?: false
   60 #     INFO [linotp config] Reconfiguring package?: false
   61 #     INFO [linotp config] Currently installed version: 
   62 #     INFO [linotp config] New version: 2.8~0dev0+g09d8dab-1~trusty
   63 #     INFO [linotp config] Version equal: 
   64 #     INFO [linotp config] Version upgrade: 
   65 #     INFO [linotp config] Version downgrade: 
   66 #
   67 #     INFO [linotp config] Installing new package?: false
   68 #     INFO [linotp config] Re-installing package?: true
   69 #     INFO [linotp config] Reconfiguring package?: false
   70 #     INFO [linotp config] Currently installed version: 2.8~0dev0+g09d8dab-1~trusty
   71 #     INFO [linotp config] New version: 2.8~0dev0+g09d8dab-1~trusty
   72 #     INFO [linotp config] Version equal: true
   73 #     INFO [linotp config] Version upgrade: 
   74 #     INFO [linotp config] Version downgrade: 
   75 #
   76 #
   77 #  During 'dpkg-reconfigure' this script is invoked once with following output:
   78 #     INFO [linotp config] Installing new package?: false
   79 #     INFO [linotp config] Re-installing package?: false
   80 #     INFO [linotp config] Reconfiguring package?: true
   81 #     INFO [linotp config] Currently installed version: 2.8~0dev0+g09d8dab-1~trusty
   82 #     INFO [linotp config] New version: 2.8~0dev0+g09d8dab-1~trusty
   83 #     INFO [linotp config] Version equal: true
   84 #     INFO [linotp config] Version upgrade: 
   85 #     INFO [linotp config] Version downgrade: 
   86 #
   87 #
   88 #  During package upgrade (dpkg -i) this script is invoked once with following output:
   89 #     INFO [linotp config] Installing new package?: false
   90 #     INFO [linotp config] Re-installing package?: true
   91 #     INFO [linotp config] Reconfiguring package?: false
   92 #     INFO [linotp config] Currently installed version: 2.8~0dev0+g09d8dab-1~trusty
   93 #     INFO [linotp config] New version: 2.9-1~trusty
   94 #     INFO [linotp config] Version equal: 
   95 #     INFO [linotp config] Version upgrade: true
   96 #     INFO [linotp config] Version downgrade: 
   97 #
   98 #
   99 #  During package downgrade (dpkg -i) this script is invoked once with following output:
  100 #     INFO [linotp config] Installing new package?: false
  101 #     INFO [linotp config] Re-installing package?: true
  102 #     INFO [linotp config] Reconfiguring package?: false
  103 #     INFO [linotp config] Currently installed version: 2.8~0dev0+g09d8dab-1~trusty
  104 #     INFO [linotp config] New version: 2.7.1-1~trusty
  105 #     INFO [linotp config] Version equal: 
  106 #     INFO [linotp config] Version upgrade:
  107 #     INFO [linotp config] Version downgrade: true
  108 
  109 
  110 MYSQLSERVER=/usr/sbin/mysqld
  111 MYSQLCLIENT=/usr/bin/mysql
  112 DBFILE_FS=/etc/linotp2/token.db
  113 
  114 
  115 # this function checks, if we are on a univention corparate server
  116 function check_ucs() {
  117     which ucr
  118     UNIVENTION_UCR=$?
  119     test -d /etc/univention
  120     UNIVENTION_ETC=$?
  121     return $UNIVENTION_UCR || $UNIVENTION_ETC
  122 }
  123 
  124 function check_mysql_tables() {
  125     #mysql --host=localhost --user=linotp2 --password=linotppw --database=linotp2 --execute='show tables;'
  126     #echo "Starting to check DB" >> /var/log/messages
  127     # Test database connction
  128     if [ -z "`mysql --host=$DBHOST --user=$DBUSER --password=$DBPASSWORD --database=$DBNAME --execute='quit' 2>&1`" ]; then
  129         DB_OK=1
  130         TABLES=`mysql --host=$DBHOST --user=$DBUSER --password=$DBPASSWORD --database=$DBNAME --execute='show tables;'`
  131         if [ -n "`echo $TABLES | grep "Config Token"`" ]; then
  132             TABLES_OK=1
  133         else
  134             TABLES_OK=0
  135         fi
  136     else
  137         DB_OK=0
  138         TABLES_OK=0
  139     fi
  140     #echo "DB: $DB_OK, TABLES: $TABLES_OK" >> /var/log/messages
  141 }
  142 
  143 NEW_VERSION='@@@DEB_VERSION@@@'
  144 
  145 INSTALL_ACTION=install
  146 if [ -n "$2" ]; then
  147     INSTALLED_VERSION="$2"
  148     if dpkg --compare-versions "${NEW_VERSION}" eq "${INSTALLED_VERSION}"; then
  149     INSTALL_ACTION=reinstall
  150     elif dpkg --compare-versions "${NEW_VERSION}" gt "${INSTALLED_VERSION}"; then
  151     INSTALL_ACTION=upgrade
  152     else
  153     INSTALL_ACTION=downgrade
  154     fi
  155 fi
  156 
  157 
  158 if [ "$1" = "reconfigure" ]; then
  159     INSTALL_MODE=reconfigure
  160 elif [ "$1" = "configure" ]; then
  161     if [ -n "${INSTALLED_VERSION}" ]; then
  162     INSTALL_MODE=reinstall
  163     else
  164     INSTALL_MODE=install
  165     fi
  166 fi
  167 
  168 print_timestamp() {
  169     date +"%Y/%m/%d - %T"
  170 }
  171 
  172 # Always print to stderr, otherwise debconf can get confused
  173 echo_info "Installation mode: $INSTALL_MODE"
  174 echo_info "Installed version: ${INSTALLED_VERSION:-(none)}"
  175 echo_info "New version: $NEW_VERSION"
  176 echo_info "Installation action: $INSTALL_ACTION"
  177 
  178 # In case of univention corparate server we do not use debconf!
  179 if [ !  $(check_ucs) ]; then
  180     db_input high linotp/apache/activate || true
  181     db_go
  182     db_get linotp/apache/activate
  183     APACHE=$RET
  184 
  185     if [ "$APACHE" = "true" ]; then
  186         db_input high linotp/apache/admin_password || true
  187         db_go
  188 
  189         db_input high linotp/apache/ssl_create || true
  190         db_go
  191 
  192         db_input high linotp/tokendb/dbtype_apache2 || true
  193         db_go
  194         db_get linotp/tokendb/dbtype_apache2
  195         TOKENDB=$RET
  196     else
  197         # If not choosen apache, you can also choose SQLlite
  198         db_input high linotp/tokendb/dbtype || true
  199         db_go
  200         db_get linotp/tokendb/dbtype
  201         TOKENDB=$RET
  202     fi
  203 
  204     if [ "$TOKENDB" = "MySQL" ] || [ "$TOKENDB" = "PostgreSQL" ]; then
  205         db_beginblock
  206         db_go
  207 
  208         db_input high linotp/tokendb/dbhost || true
  209         db_go
  210         db_get linotp/tokendb/dbhost
  211         DBHOST=$RET
  212 
  213         db_input high linotp/tokendb/dbname || true
  214         db_go
  215         db_get linotp/tokendb/dbname
  216         DBNAME=$RET
  217 
  218         db_input high linotp/tokendb/dbuser || true
  219         db_go
  220         db_get linotp/tokendb/dbuser
  221         DBUSER=$RET
  222 
  223         db_input high linotp/tokendb/password || true
  224         db_go
  225         db_get linotp/tokendb/password
  226         DBPASSWORD=$RET
  227 
  228         db_endblock
  229         db_go
  230     fi
  231 
  232 
  233 #
  234 # Do the postgres configuration.
  235 # In fact we only tell, that we do nothing.
  236 #
  237     if [ "$TOKENDB" == "PostgreSQL" ]; then
  238         db_input high linotp/postgres/no_configuration
  239         db_go
  240     fi
  241 #
  242 # Ask if we should create the sqlite file
  243 #
  244     if [ "$TOKENDB" == "SQLite" ]; then
  245         if [ -f $DBFILE_FS ]; then
  246             db_input high linotp/sqlite/ask_createdb
  247             db_go
  248         else
  249             db_set linotp/sqlite/ask_createdb true
  250         fi
  251     fi
  252 #
  253 # Check all effects for mysql: Does the DB exist? Do the table exist?
  254 #
  255     if [ "$TOKENDB" = "MySQL" ]; then
  256         if [ "$INSTALL_MODE" = "reinstall" ] && [ "$INSTALL_ACTION" = "upgrade" ]
  257         then
  258             # In version 2.6 of LinOTP ask_createdb was RESET in the
  259             # postinst. This meant the question appeared again,
  260             # because the 'seen' flag had been reset too. The RESET was
  261             # changed to a SET in LinOTP 2.7.1 .
  262             # If we detect an upgrade from a version between 2.6 and
  263             # 2.7.1 we force the 'seen' flag of the question to true,
  264             # preventing the latter from being displayed to the user.
  265             # In other versions (or when running dpkg-reconfigure)
  266             # we don't want to interfere with the regular debian
  267             # behaviour.
  268             # See also issues #12298 and #12718
  269             set +e
  270             dpkg --compare-versions ${INSTALLED_VERSION} ge 2.6
  271             result_ge=$?
  272             dpkg --compare-versions ${INSTALLED_VERSION} lt 2.7.1
  273             result_lt=$?
  274             set -e
  275             if [ $result_ge = 0 ] && [ $result_lt = 0 ]
  276             then
  277                 # Version is >= than 2.6 and < than 2.7.1
  278                 db_fset linotp/mysql/ask_createdb seen true
  279             fi
  280         fi
  281         if [ -x $MYSQLCLIENT ]; then
  282             # check, if the database already exists
  283             check_mysql_tables
  284             if [ "$DB_OK" = "1" ]; then
  285                 if [ "$TABLES_OK" = "1" ]; then
  286                     # Database and Tables already exist. Good!
  287                     db_input high linotp/mysql/tables_exist || true
  288                     db_go
  289                 else
  290                     # Ask, if we should create the tables
  291                     db_input high linotp/mysql/ask_createtables || true
  292                     db_go
  293                 fi
  294             else
  295                 if [ "$DBHOST" = "localhost" ]; then
  296                     if [ -x $MYSQLSERVER ]; then
  297                         # server is installed locally
  298                         db_input high linotp/mysql/ask_createdb || true
  299                         db_go
  300                         db_get linotp/mysql/ask_createdb
  301                         MYSQL_CREATE_DB=$RET
  302                     fi
  303                     # ELSE: localhost choosen, but no mysql installed on localhost.
  304                 else # SQL DB not on localhost
  305                     # client and server are installed locally
  306                     db_input high linotp/mysql/ask_createdb || true
  307                     db_go
  308                     db_get linotp/mysql/ask_createdb
  309                     MYSQL_CREATE_DB=$RET
  310                 fi
  311                 if [ "$MYSQL_CREATE_DB" = "true" ]; then
  312                     db_set linotp/mysql/ask_createtables true
  313                     # Ask for the administrative credentials
  314                     if [ ! -f /etc/lseappliance/mysql_root ]; then
  315                         db_input high linotp/mysql/ask_rootpw || true
  316                         db_go
  317                     fi
  318                 fi
  319             fi # end of DB_OK
  320         fi # end of mysqlclient
  321     fi  # end of $TOKENDB
  322 fi  # end of NOT UCS