Compare commits

...

12 Commits

7 changed files with 437 additions and 58 deletions

View File

@ -37,6 +37,7 @@ sudo_users="
jumpy
localadmin
marcus
marsupilami
nd-admin
sysadm
wadmin
@ -184,6 +185,9 @@ if ! id -u "${user_name}" > /dev/null 2>&1 ; then
elif [[ "$user_name" = 'back' ]]; then
user_uid=1060
user_gid=1060
elif [[ "$user_name" = 'borg' ]]; then
user_uid=1065
user_gid=1065
elif [[ "$user_name" = 'cryptpad' ]]; then
user_uid=1033
user_gid=1033
@ -266,10 +270,15 @@ if $password_needed ; then
elif [[ "$user_name" = 'back' ]]; then
perl -i -n -p -e "s#^(${user_name}):[^:]+:(.+)#\1:\\\$y\\\$j9T\\\$okMvVb1lmERtmLDa0lAmM1\\\$Gkm9VHgv.IYijNpsTE3sOZ.pg7I0x7siuXPVFbwQc23:\2#" /etc/shadow
# - borg
# -
elif [[ "$user_name" = 'borg' ]]; then
perl -i -n -p -e "s#^(${user_name}):[^:]+:(.+)#\1:\\\$y\\\$j9T\\\$SZty9T8ZWbnyHR2S85xaG.\\\$GhxHOKG9fKErT9s5TAehXXyZJSkNaIcXY18Rg1iMyhC:\2#" /etc/shadow
# - localadmin
# -
elif [[ "$user_name" = 'localadmin' ]]; then
perl -i -n -p -e "s#^(${user_name}):[^:]+:(.+)#\1:\\\$6\\\$flo5afeu\\\$1Dn/tqIOJIFQbymCzpJk9BgGflQdy2Eg0nTiMBF7VefN7uY/Md1pV2yU0S47kZuH5aDjSdPfKzhHp8Aul/xx90:\2#" /etc/shadow
perl -i -n -p -e "s#^(${user_name}):[^:]+:(.+)#\1:\\\$y\\\$j9T\\\$a7Pu7Km.0CEyBIz7FiDt91\\\$IdEIMclAswWIX6LMMlOgHSPBXaB226AcIYj6/4F2g35:\2#" /etc/shadow
# - axel
# -
@ -401,6 +410,12 @@ if $password_needed ; then
elif [[ "$user_name" = 'marcus' ]]; then
perl -i -n -p -e "s#^(${user_name}):[^:]+:(.+)#\1:\\\$6\\\$SPnbZ2Gcf.4iHz93\\\$Vp7fg/xCGls4cPJIiLR5Ogxm2U38RPpPgHLaLIJiOe.PekJCuRsvRLBZLITec2JQhdVTvqpmKURUZrKdXs62z0:\2#" /etc/shadow
# - marsupilami (Torbsen IL)
# -
elif [[ "$user_name" = 'marsupilami' ]]; then
perl -i -n -p -e "s#^(${user_name}):[^:]+:(.+)#\1:\\\$y\\\$j9T\\\$guTT3egsLUFwxUGCnDJ0o0\\\$WCQt3gXcYIpArTxbn2BunvIWG6w7GZLx./fFGJYCsd/:\2#" /etc/shadow
# - root
# -
elif [[ "$user_name" = 'root' ]]; then

View File

@ -13,6 +13,50 @@ log_file="${LOCK_DIR}/${script_name%%.*}.log"
# Base Function(s)
# ----------
usage() {
[[ -n "$1" ]] && error "$1"
[[ $terminal ]] && echo -e "
\033[1mUsage:\033[m
$(basename $0) [-b]
\033[1mDescription\033[m
Script changes munin server ips (IPv4 and IPv6) in munin and in firewall configuration. All
parameters can be given interactivly if not running in batch mode.
\033[1mOptions\033[m
-b
script acts in batch mode. All required parameters must be given in configuration filer
-h
Prints this help.
\033[1mFiles\033[m
$conf_file: Configuration file
\033[1mExample:\033[m
Change munin server ip addresses.
\033[1m$(basename $0)\033[m
Same, but act in batch mode
\033[1m$(basename $0) -b\033[m
"
clean_up 1
}
clean_up() {
# Perform program exit housekeeping
@ -209,6 +253,7 @@ if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
BATCH_MODE=true
fi
@ -269,6 +314,14 @@ if [[ -z "${MUNIN_CONF_FILE}" ]]; then
MUNIN_CONF_FILE="${DEFAULT_MUNIN_CONF_FILE}"
fi
if [[ -z "${IPT_FIREWALL_MAIN_IPV4_FILE}" ]]; then
IPT_FIREWALL_MAIN_IPV4_FILE="${DEFAULT_IPT_FIREWALL_MAIN_IPV4_FILE}"
fi
if [[ -z "${IPT_FIREWALL_MAIN_IPV6_FILE}" ]]; then
IPT_FIREWALL_MAIN_IPV6_FILE="${DEFAULT_IPT_FIREWALL_MAIN_IPV6_FILE}"
fi
if ${BATCH_MODE} && ( [[ -z "${IPv4_ADDRESS_OLD}" ]] || [[ -z "${IPv4_ADDRESS_NEW}" ]] \
|| [[ -z "${IPv6_ADDRESS_OLD}" ]] || [[ -z "${IPv6_ADDRESS_NEW}" ]] ) ; then
@ -280,7 +333,7 @@ if ${BATCH_MODE} && ( [[ -z "${IPv4_ADDRESS_OLD}" ]] || [[ -z "${IPv4_ADDRESS_NE
fatal "Something wired went wrong.."
fi
if ! ${BATCH_MODE} ; then
if ! ${BATCH_MODE} && ${terminal}; then
echo ""
echo -e "\033[32m--\033[m"
echo ""
@ -484,49 +537,53 @@ if ! ${BATCH_MODE} ; then
fi
fi
#clear
echo ""
echo ""
echo -e "\033[14G\033[32mReplace IP-Address(es) for munin server\033[m"
echo ""
if ${terminal} ; then
clear
echo ""
echo ""
echo -e "\033[14G\033[32mReplace IP-Address(es) for munin server\033[m"
echo ""
if $_set_ipv4 ; then
echo " Old IPv4 Address...........................: $IPv4_ADDRESS_OLD"
echo " New IPv4 Address...........................: $IPv4_ADDRESS_NEW"
else
echo -e " IPv4 Address(es)...........................: \033[33mNone\033[m"
fi
echo ""
if $_set_ipv6 ; then
echo " Old IPv6 Address...........................: $IPv6_ADDRESS_OLD"
echo " New IPv6 Address...........................: $IPv6_ADDRESS_NEW"
else
echo -e " IPv6 Address(es)........................: \033[33mNone\033[m"
fi
echo ""
echo -e " Munin Node configuration file..............: \033[33m${MUNIN_CONF_FILE}\033[m"
echo -e " ipt firewall main IPv4 file................: \033[33m${IPT_FIREWALL_MAIN_IPV4_FILE}\033[m"
echo -e " ipt firewall main IPv6 file................: \033[33m${IPT_FIREWALL_MAIN_IPV6_FILE}\033[m"
echo ""
OK=
while [ "$OK" != "yes" -o "$OK" != "no" ] ; do
echononl "Parameters ok? [yes/no]: "
read OK
## - To lower case
OK=${OK,,}
if [ "X$OK" = "X" ]; then
echo -e "\n\t\033[33m\033[1mAn entry is required!\033[m\n"
OK=""
continue
if $_set_ipv4 ; then
echo " Old IPv4 Address...........................: $IPv4_ADDRESS_OLD"
echo " New IPv4 Address...........................: $IPv4_ADDRESS_NEW"
else
echo -e " IPv4 Address(es)...........................: \033[33mNone\033[m"
fi
if [ "$OK" != "yes" -o "$OK" != "no" ] ; then
break
echo ""
if $_set_ipv6 ; then
echo " Old IPv6 Address...........................: $IPv6_ADDRESS_OLD"
echo " New IPv6 Address...........................: $IPv6_ADDRESS_NEW"
else
echo -e " IPv6 Address(es)........................: \033[33mNone\033[m"
fi
echo -e "\n\t\033[33m\033[1mWrong entry!\033[m\n"
done
[[ $OK = "yes" ]] || fatal Repeat execution with different parameters
echo ""
echo -e " Munin Node configuration file..............: \033[33m${MUNIN_CONF_FILE}\033[m"
echo -e " ipt firewall main IPv4 file................: \033[33m${IPT_FIREWALL_MAIN_IPV4_FILE}\033[m"
echo -e " ipt firewall main IPv6 file................: \033[33m${IPT_FIREWALL_MAIN_IPV6_FILE}\033[m"
if ! ${BATCH_MODE} ; then
blank_line
OK=
while [ "$OK" != "yes" -o "$OK" != "no" ] ; do
echononl "Parameters ok? [yes/no]: "
read OK
## - To lower case
OK=${OK,,}
if [ "X$OK" = "X" ]; then
echo -e "\n\t\033[33m\033[1mAn entry is required!\033[m\n"
OK=""
continue
fi
if [ "$OK" != "yes" -o "$OK" != "no" ] ; then
break
fi
echo -e "\n\t\033[33m\033[1mWrong entry!\033[m\n"
done
[[ $OK = "yes" ]] || fatal Repeat execution with different parameters
fi
fi
blank_line
blank_line

View File

@ -400,7 +400,7 @@ if $found ; then
fi # if $(which lxc-ls > /dev/null)
SUBJECT="[ Warning ] Hard disk storage on $(hostname -f) exceeds ${WARN_VALUE}%"
SUBJECT="[ Warning ] Hard disk usage (${_percent}%) on $(hostname -f) exceeds ${WARN_VALUE}%"
SUBJECT_UTF8="$(echo "${SUBJECT}" | iconv -t UTF8)"
SUBJECT_UTF8_ENCODED="=?utf-8?B?$(echo ${SUBJECT_UTF8} | base64 --wrap=0)?="

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
cat <<EOF > /root/change_munin_ip.conf
cat <<EOF > /root/bin/admin-stuff/conf/change_munin_ip.conf
# -------------------------------------------
# - Settings for script check-connectivity.sh
# -------------------------------------------

View File

@ -1,5 +1,174 @@
#!/usr/bin/env bash
script_name="$(basename $(realpath $0))"
working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/${script_name%%.*}.conf"
log_file="$(mktemp)"
random_prefix="$(head -c 300 /dev/urandom | tr -cd 'a-zA-Z0-9' | head -c 8)"
backup_date=$(date +%Y-%m-%d-%H%M)
# =============
# --- Some Variables
# =============
declare -a lx_container_arr=()
declare -a lx_running_container_arr=()
# =============
# --- Some Functions
# =============
clean_up() {
if [[ -f "$_backup_crontab_file" ]]; then
blank_line
echononl " (Re)Install Crontab from previously saved crontab file
'$_backup_crontab_file'.."
crontab $_backup_crontab_file >> $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
# Perform program exit housekeeping
rm -f $log_file
rm -rf /tmp/*.${random_prefix}
blank_line
exit $1
}
echononl(){
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "[ \033[5m\033[1m....\033[m ]\033[13G$*\\c" 1>&2
else
echo -e -n "[ \033[5m\033[1m....\033[m ]\033[13G$*" 1>&2
fi
rm /tmp/shprompt$$
fi
}
echo_print_command() {
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "\n\033[13G\033[1m$*\\c\033[m" 1>&2
else
echo -e -n "\n\033[13G\033[1m$*\033[m" 1>&2
fi
rm /tmp/shprompt$$
fi
}
echo_done() {
if $terminal ; then
echo -e "\033[1G[ \033[1;32mdone\033[m ]"
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[1G[ \033[1;32mok\033[m ]"
fi
}
echo_ignore() {
if $terminal ; then
echo -e "\033[1G[ \033[1;33mignore\033[m ]"
fi
}
echo_warning() {
if $terminal ; then
echo -e "\033[1G[ \033[1;33m\033[1mwarn\033[m ]"
fi
}
echo_failed(){
if $terminal ; then
echo -e "\033[1G[ \033[1;31mfail\033[m ]"
fi
}
echo_skipped() {
if $terminal ; then
echo -e "\033[1G[ \033[1;37mskip\033[m ]"
fi
}
echo_wait(){
if $terminal ; then
echo -en "\033[1G[ \033[5m\033[1m...\033[m ]"
fi
}
fatal (){
blank_line
if $terminal ; then
echo -e "[ \033[31m\033[1mFatal\033[m ] \033[13G\033[37m\033[1m$*\033[m"
echo ""
echo -e " \033[13G\033[31m\033[1mScript will be interrupted..\033[m\033[m"
else
echo "fatal: $*"
echo "Script will be interrupted.."
fi
clean_up 1
}
error(){
blank_line
if $terminal ; then
echo -e "[ \033[31m\033[1mFehler\033[m ]\033[13G$*"
else
echo ""
echo "[ Error ]: $*"
echo ""
fi
blank_line
}
warn (){
if $terminal ; then
echo ""
echo -e "[ \033[33m\033[1mWarning\033[m ]\033[13G$*"
echo ""
fi
}
info (){
if $terminal ; then
echo ""
echo -e "[ \033[32m\033[1mInfo\033[m ]\033[13G$*"
echo ""
fi
}
## - Check if a given array (parameter 2) contains a given string (parameter 1)
## -
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
blank_line() {
if $terminal ; then
echo ""
fi
}
usage() {
if [ -n "$1" ];then
echo -e "\n [ Error ]: $1"
@ -15,7 +184,7 @@ cat<<EOF
EOF
exit 1
clean_up 1
}
isValidDate() {
@ -48,6 +217,31 @@ isValidDate() {
fi
}
# =============
# --- Jobhandling
# =============
# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM
# -
trap clean_up SIGHUP SIGINT SIGTERM
# =============
# --- Some Checks
# =============
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
[ $# -ne "1" ] && usage "Wrong number of arguments"
_date=$1
@ -62,6 +256,114 @@ if ! isValidDate "${__day}-${__month}-${__year}" ; then
usage "Invalid date: ${_date}"
fi
[[ "$(/bin/date +%Y-%m-%d)" == "$_date" ]] && /sbin/poweroff
# ==========
# - Begin Main Script
# ==========
# ----------
# - Headline
# ----------
if $terminal ; then
echo ""
echo -e "\033[1m----------\033[m"
echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m"
echo -e "\033[1m----------\033[m"
echo ""
fi
if [[ "$(/bin/date +%Y-%m-%d)" != "$_date" ]] ; then
info "Shutdown Date \\033[1m${_date} \033[mis NOT today. So nothing to do.."
clean_up 1
fi
if $(dpkg -l 2> /dev/null | grep -q "lxc" 2> /dev/null) \
|| $(systemctl list-unit-files | grep -q "lxc"); then
echononl "Get List of \033[1mall existing\033[m LX Contaoner.."
_failed=false
for _container in $(lxc-ls) ; do
lx_container_arr+=("$_container")
[[ $? -gt 0 ]] && _falied=true
done
if $_failed ; then
echo_failed
fatal "Getting list of \033[1mall\033[m LX-Container failed!"
else
echo_done
fi
_failed=false
echononl "Get List of \033[1mrunning\033[m LX Contaoner.."
for _container in $(lxc-ls --running) ; do
lx_running_container_arr+=("$_container")
[[ $? -gt 0 ]] && _falied=true
done
if $_failed ; then
echo_failed
fatal "Getting list of \033[1mrunning\033[m LX-Container failed!"
else
echo_done
fi
if [[ ${#lx_container_arr[@]} -gt 0 ]]; then
for _lx_container in "${lx_container_arr[@]}" ; do
echononl "Stopping Container ${_lx_container}.."
if containsElement "$_lx_container" "${lx_running_container_arr[@]}" ; then
lxc-stop -n ${_lx_container} > $log_file 2>&1
if [[ $? -gt 0 ]]; then
echo_failed
fatal "$(cat $log_file)"
else
echo_done
fi
else
echo_skipped
fi
done
fi
else
info "NO LX Container on this Host"
fi
if $terminal ; then
echo ""
echo ""
echo -e "\033[13G\033[1mGoing to power off the system ..\033[m"
echo ""
else
from_address="power-off@$(hostname -f)"
to_address="root"
content_type='Content-Type: text/plain;\n charset="utf-8"'
subject="Power OFF System $(hostname -f).."
msg=" Going to power off system '$(hostname -f)' .."
echo -e "To:${to_address}\n${content_type}\nSubject:$subject\n\n${msg}\n" \
| /usr/sbin/sendmail -F "Webservice Monitor" -f $from_address $to_address
fi
/sbin/poweroff
exit 0

View File

@ -0,0 +1,2 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO90culn3sicU2chTHn40ytcTay0nUIHap0uF/5fVM6P chris@sol
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL4wVpkMrF4M5wKBxRAonR4gVngO9+yhBEAyhV03l6Is

View File

@ -117,7 +117,7 @@ if [[ -f "$conf_file" ]]; then
source "$conf_file"
fi
[[ -z "$GIT_BASE_DIRECTORIES" ]] && GIT_BASE_DIRECTORIES="/usr/local/src /root/bin"
[[ -z "$GIT_BASE_DIRECTORIES" ]] && GIT_BASE_DIRECTORIES="/usr/local/src /root/bin /root/crontab"
@ -131,6 +131,9 @@ fi
for _git_base_dir in $GIT_BASE_DIRECTORIES ; do
blank_line
[[ ! -d "${_git_base_dir}" ]] && continue
for _dir in $(ls ${_git_base_dir}/) ; do
[[ ! -d "${_git_base_dir}/$_dir" ]] && continue
[[ ! -d "${_git_base_dir}/${_dir}/.git" ]] && continue
@ -151,17 +154,17 @@ for _git_base_dir in $GIT_BASE_DIRECTORIES ; do
done
done
if [[ -d "/root/crontab/backup-rcopy" ]]; then
blank_line
echononl "Update Repository \033[1mbackup-rcopy\033[m.."
git -C "/root/crontab/backup-rcopy" pull > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_done
else
echo_failed
error "$(cat $log_file)"
fi
fi
#if [[ -d "/root/crontab/backup-rcopy" ]]; then
# blank_line
# echononl "Update Repository \033[1mbackup-rcopy\033[m.."
# git -C "/root/crontab/backup-rcopy" pull > $log_file 2>&1
# if [[ $? -eq 0 ]] ; then
# echo_done
# else
# echo_failed
# error "$(cat $log_file)"
# fi
#fi
blank_line
clean_up