#!/bin/bash
# Copyright (c) 2021 Dropbox, Inc.
# File: remctl-apt-full-upgrade
# Author: Bill MacAllister
# Description: Perform apt package upgrades

function display_usage {
    echo "Usage: remctl-apt-full-upgrade [update|help|manual]"
}

##############################################################################
# Main routine
##############################################################################

# Strip off a remctl sub-command of 'full-upgrade' from the command line.
if [ "$1" == "full-upgrade" ]
then
    shift
fi

case $1 in
    update)
        apt update
        export DEBIAN_FRONTEND=noninteractive
        apt full-upgrade -y \
            -o Dpkg::Options::=--force-confdef \
            -o Dpkg::Options::=--force-confold \
            --fix-missing
        ;;
    help)
        display_usage
        ;;
    manual)
        man remctl-apt-full-upgrade
        ;;
    *)
        display_usage
        ;;
esac

exit

DOCS=<<__END_OF_DOCS__

=head1 NAME

remctl-apt-full-upgrade - wrapper for apt full-upgrade

=head1 SYNOPSIS

remctl-apt-full-upgrade

=head1 DESCRIPTION

This script runs the commands 'apt update' followed by 'apt
full-upgrade'.  The script runs the full-upgrade step with apt and
dpkg switches that attempt to make the full-upgrade run without
requiring any user input.

=head1 ACTIONS

=over 4

=item update

Invoke 'apt update' followed by 'apt full-upgrade'.

=item help

Display script usage.  This is the default action if not other action
is given on the command line.

=item manul

Display the man page for this script.

=back

=head1 AUTHOR

Bill MacAllister <whm@dropbox.com>

=head1 COPYRIGHT

Copyright (C) 2021 Dropbox Inc.

This code is free software; you can redistribute it and/or modify it
under the same terms as Perl. For more details, see the full text of the
at https://opensource.org/licenses/Artistic-2.0.

This program is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.

=cut

__END_OF_DOCS__
