2021-12-29 13:38:28 +00:00
|
|
|
#
|
|
|
|
# DockerBashOOP - Implementation of BashOOP for Docker.
|
|
|
|
# Copyright (C) 2021 Ad5001 <mail@ad5001.eu>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
# This class contains various utils required for Docker.
|
|
|
|
|
|
|
|
# Returns the base command for docker, with it's executable and sudo if necessary.
|
2022-01-01 15:41:23 +00:00
|
|
|
# Signature: () -> string
|
2021-12-29 13:38:28 +00:00
|
|
|
Utils.DockerCommand() {
|
|
|
|
if [ $(Docker.RequiresSudo) == true ]; then echo -n "sudo "; fi
|
|
|
|
echo "$(Docker.Executable)"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Checks if the user has permission to use docker.
|
2022-01-01 15:41:23 +00:00
|
|
|
# Signature: () -> bool
|
2021-12-29 13:38:28 +00:00
|
|
|
Utils.hasPermission() {
|
|
|
|
$(Utils.DockerCommand) ps 2>&1 | grep -q "permission denied"
|
|
|
|
# Check status of last command. If permission denied is found, then we do not have permission to use docker.
|
|
|
|
if [ $? ]; then echo false; else echo true; fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|