Initial commit.
This commit is contained in:
commit
53693b9b7b
8 changed files with 1030 additions and 0 deletions
60
libraries/update/docker.sh
Normal file
60
libraries/update/docker.sh
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/bin/bash
|
||||
# ____ _ ____
|
||||
# | _ \ ___ _ __ ___ ___ | |_ ___ ___| _ \ _ _ _ __
|
||||
# | |_) / _ \ '_ ` _ \ / _ \| __/ _ \/ __| |_) | | | | '_ \
|
||||
# | _ < __/ | | | | | (_) | || __/\__ \ _ <| |_| | | | |
|
||||
# |_| \_\___|_| |_| |_|\___/ \__\___||___/_| \_\\__,_|_| |_|
|
||||
#
|
||||
# Run several scripts on remote servers automatically.
|
||||
# Copyright (C) 2022 Ad5001
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
# This library contains docker related utilities
|
||||
|
||||
# Updates a docker container to a newer version of the image by tag,
|
||||
# and relaunches the container with a specified script.
|
||||
# Signature: (<string container_name>, <string container_tag>, <string run_script>) -> void
|
||||
update_docker() {
|
||||
container_name=$1
|
||||
container_tag=$2
|
||||
run_script=$3
|
||||
|
||||
info "Seaching for updates for $container_name..."
|
||||
run_as_root "docker pull $container_tag"
|
||||
|
||||
eq=$(run_as_root "docker ps" | awk -F ' {2,}' '$7 == "'$container_name'" { print $2 }')
|
||||
if [ -z "$eq" ]; then
|
||||
# No published ports, so we check field 6.
|
||||
eq=$(run_as_root "docker ps" | awk -F ' {2,}' '$6 == "'$container_name'" { print $2 }')
|
||||
fi
|
||||
# If the image doesn't have the awaited tag, then
|
||||
if [[ $eq != "$container_tag" ]]; then
|
||||
# On relance le conteneur.
|
||||
info "Restarting container $container_name..."
|
||||
run_as_root "bash $run_script"
|
||||
# On supprime l'ancienne image pour libérer de l'espace.
|
||||
success "$container_name restarted!"
|
||||
info "Deleting old image version of $container_name..."
|
||||
sudo -p "" -i -S bash -c "docker rmi $eq"
|
||||
if [ $? -eq 0 ]; then
|
||||
success "Old image of $container_name deleted!"
|
||||
else
|
||||
error "Old image of $container_name could not be removed."
|
||||
fi
|
||||
else
|
||||
success "$container_name up to date!"
|
||||
fi
|
||||
echo ""
|
||||
}
|
45
libraries/update/redhat.sh
Normal file
45
libraries/update/redhat.sh
Normal file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
# ____ _ ____
|
||||
# | _ \ ___ _ __ ___ ___ | |_ ___ ___| _ \ _ _ _ __
|
||||
# | |_) / _ \ '_ ` _ \ / _ \| __/ _ \/ __| |_) | | | | '_ \
|
||||
# | _ < __/ | | | | | (_) | || __/\__ \ _ <| |_| | | | |
|
||||
# |_| \_\___|_| |_| |_|\___/ \__\___||___/_| \_\\__,_|_| |_|
|
||||
#
|
||||
# Run several scripts on remote servers automatically.
|
||||
# Copyright (C) 2022 Ad5001
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
# This library contains information for redhat based systems (fedora, centos, redhat).
|
||||
|
||||
|
||||
# Updates a redhat system when the user isn't root (runs with sudo)
|
||||
# Signature: () -> void
|
||||
update_non_root() {
|
||||
info "Checking for updates..."
|
||||
run_as_root "yum check-update"
|
||||
info "Updating..."
|
||||
run_as_root "yum update -y"
|
||||
success "Updated!"
|
||||
}
|
||||
|
||||
# Updates a redhat system when the user is root (runs without sudo)
|
||||
# Signature: () -> void
|
||||
update_as_root() {
|
||||
info "Checking for updates..."
|
||||
yum check-update
|
||||
info "Updating..."
|
||||
yum update -y
|
||||
success "Updated!"
|
||||
}
|
57
libraries/update/ubuntu.sh
Normal file
57
libraries/update/ubuntu.sh
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/bin/bash
|
||||
# ____ _ ____
|
||||
# | _ \ ___ _ __ ___ ___ | |_ ___ ___| _ \ _ _ _ __
|
||||
# | |_) / _ \ '_ ` _ \ / _ \| __/ _ \/ __| |_) | | | | '_ \
|
||||
# | _ < __/ | | | | | (_) | || __/\__ \ _ <| |_| | | | |
|
||||
# |_| \_\___|_| |_| |_|\___/ \__\___||___/_| \_\\__,_|_| |_|
|
||||
#
|
||||
# Run several scripts on remote servers automatically.
|
||||
# Copyright (C) 2022 Ad5001
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
# This library contains information for debian & ubuntu based systems.
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
|
||||
# Updates a debian system when the user isn't root (runs with sudo)
|
||||
# Signature: () -> void
|
||||
update_non_root() {
|
||||
info "Checking for updates..."
|
||||
run_as_root "apt-get update"
|
||||
count=$(apt list --upgradeable | wc -l) # Count, with 1 additional line
|
||||
if [[ $count -ne 1 ]]; then
|
||||
info "Updating $(expr $count - 1) packets..."
|
||||
run_as_root "apt-get dist-upgrade -y"
|
||||
success "System has been updated!"
|
||||
else
|
||||
success "System up to date."
|
||||
fi
|
||||
}
|
||||
|
||||
# Updates a redhat system when the user is root (runs without sudo)
|
||||
# Signature: () -> void
|
||||
update_as_root() {
|
||||
info "Checking for updates..."
|
||||
apt-get update
|
||||
count=$(apt list --upgradeable | wc -l) # Count, with 1 additional line
|
||||
if [[ $count -ne 1 ]]; then
|
||||
info "Updating $(expr $count - 1) packets..."
|
||||
apt-get dist-upgrade -y
|
||||
success "System has been updated!"
|
||||
else
|
||||
success "System up to date."
|
||||
fi
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue