Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@elbosso
Last active February 23, 2023 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbosso/1ce7c8cdd254109283a6fc670c4da06c to your computer and use it in GitHub Desktop.
Save elbosso/1ce7c8cdd254109283a6fc670c4da06c to your computer and use it in GitHub Desktop.
This script installs and configures a few applications and services - in particular it sets up gnu screen and conky in a way to provide a nice bottom line complete with tabs for the open windows and some information about system health
#!/bin/bash
######################################################################
# This script sets up gnu screen and conky in a way to provide a nice
# footer line complete with tabs for the open windows and some
# information about the systems health
# (https://elbosso.github.io/gnu_screen_sitzung_wenig_aufgepeppt.html#content)
#
# If run as sudo (or root) it tries to install gnu screen and conky
# (needed) and joe (my own preference) before writing a customized
# version of .screenrc and a customized version of a conky config.
#
# Additionally, if run as sudo or root it tries to install ntpd,
# backing up and rewriting the config, adding a NTP server. Which server
# this is can be customized via setting the environment variable NTP_SERVER.
# If this variable is not set, the default (192.168.10.2) is used.
# For example, the script could be called like this:
# sudo NTP_SERVER=mail.klausen.dk /bin/bash setupscreenconkx.sh
# After rewriting the configuration, ntpd is restarted.
#
# Furthermore, telegraf - the plugin-driven server agent for
# collecting & reporting metrics - is installed along with a basic
# configuration and restarted so that this configuration is active.
######################################################################
if [[ "$EUID" -eq 0 ]]
then
apt-get update && apt-get -y install joe screen conky ntp telegraf
if grep "server.*prefer" /etc/ntp.conf
then
# code if found
echo "not doing anything with /etc/ntp.conf"
else
# code if not found
echo "Writing NTP config backup to /etc/ntp_$(date -d "today" +"%Y%m%d%H%M")"
cp /etc/ntp.conf "/etc/ntp_$(date -d "today" +"%Y%m%d%H%M")"
sed -i "/^.*Specify one or more NTP servers.*/aserver ${NTP_SERVER:-192.168.10.2} prefer" /etc/ntp.conf
service ntp restart
fi
echo "Writing telegraf config backup to /etc/telegraf/telegraf_$(date -d "today" +"%Y%m%d%H%M")"
cp /etc/telegraf/telegraf.conf "/etc/telegraf/telegraf_$(date -d "today" +"%Y%m%d%H%M")"
telegraf --output-filter influxdb --input-filter net:cpu:mem:disk:diskio:system:processes:temp:sensors --aggregator-filter none --processor-filter none config >/etc/telegraf/telegraf.conf
sed -i 's/interval = "10s"/interval = "1m"/g' /etc/telegraf/telegraf.conf
sed -i 's/# database = "telegraf"/database = "monitoring"/g' /etc/telegraf/telegraf.conf
sed -i 's|# urls = \["http\://127.0.0.1\:8086"\]|urls = \["http\://192.168.10.2\:8086"\]|g' /etc/telegraf/telegraf.conf
service telegraf restart
fi
if [ -f "/home/${SUDO_USER:-$USER}/.screenrc" ]
then
echo "/home/${SUDO_USER:-$USER}/.screenrc already exists - not touching it!"
else
echo "writing /home/${SUDO_USER:-$USER}/.screenrc"
cat <<EOF >"/home/${SUDO_USER:-$USER}"/.screenrc
#idle 10 lockscreen
autodetach on # Autodetach session on hangup instead of terminating screen completely
startup_message off # Turn off the splash screen
hardstatus on
backtick 1 5 5 conky -c /home/${SUDO_USER:-$USER}/.conkyinscreen
#hardstatus alwayslastline "%{.kc}%-w%{.kw}%n*%t%{-}%+w%=%1\`"
caption always "%{=u Kc} %=%1\`"
hardstatus alwayslastline "%{= kc} %-Lw%{=b Kc} %n%f %t %{-}%+Lw %=%{= dd}"
#hardstatus alwayslastline "%{bw}[%H] [%?%-Lw%?%{wb}%n*%f %t%{bw}%?%+Lw%?]%=%{bw}"
EOF
if [[ "$EUID" -eq 0 ]]
then
chown "${SUDO_USER:-$USER}" "/home/${SUDO_USER:-$USER}"/.screenrc
fi
fi
if [ -f "/home/${SUDO_USER:-$USER}/.conkyinscreen" ]
then
echo "/home/${SUDO_USER:-$USER}/.conkyinscreen already exists - not touching it!"
else
echo "writing /home/${SUDO_USER:-$USER}/.conkyinscreen"
cat <<EOF >"/home/${SUDO_USER:-$USER}"/.conkyinscreen
out_to_x no
out_to_console yes
total_run_times 1
TEXT
| \$nodename_short |free (/home):\${fs_free /home}|\$loadavg|free mem:\$memeasyfree|\${time %H:%M}
EOF
if [[ "$EUID" -eq 0 ]]
then
chown "${SUDO_USER:-$USER}" "/home/${SUDO_USER:-$USER}"/.conkyinscreen
fi
fi
@elbosso
Copy link
Author

elbosso commented Feb 23, 2023

added some more telegraf inputs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment