added sconfig.sh draft
This commit is contained in:
parent
a19131d99c
commit
264f841ba3
161
sconfig.sh
Executable file
161
sconfig.sh
Executable file
@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
## name: sconfig.sh
|
||||
## author: david@socialnerds.org
|
||||
## version: 0.1
|
||||
##
|
||||
## decription: This is a script to help you configure
|
||||
## various aspects of a linux server.
|
||||
##
|
||||
## features: manage user accounts and their keys
|
||||
## update operating system packages
|
||||
## install admin tools
|
||||
## harden sshd
|
||||
## enable ufw
|
||||
## setup docker
|
||||
## setup nginx & acme.sh
|
||||
## setup duplicity
|
||||
## setup snmpd
|
||||
##
|
||||
## usage: sconfig
|
||||
##
|
||||
## changelog: 2020-06-22 first draft of a working menu
|
||||
## 2020-06-21 started development of v0.1
|
||||
|
||||
#TODO: merge content of prep_ubuntu_server.sh in here
|
||||
|
||||
# **** start of script ****
|
||||
|
||||
|
||||
## functions
|
||||
|
||||
### check for superuser privileges
|
||||
amiroot() { if [ $(whoami) != "root" ]; then return 1; fi }
|
||||
|
||||
### header and footer output
|
||||
header() {
|
||||
clear
|
||||
local cols=$(tput cols); local char="="
|
||||
local i=0; while [ $i != $((cols)) ]; do local chars="$chars$char"; i=$((i+1)); done
|
||||
echo $chars; echo "Server configuration"; echo -e "$chars\n"
|
||||
}
|
||||
|
||||
footer() {
|
||||
local lines=$(tput lines)
|
||||
local i=5; while [ $i != $((lines-$1)) ]; do echo ""; i=$((i+1)); done
|
||||
local option=""; read -n 1 -p "Enter number to select an option: " option
|
||||
if [[ $option =~ ^[1-9]+$ ]]; then return $option; fi
|
||||
}
|
||||
|
||||
menu() {
|
||||
header
|
||||
local lines=$(tput lines)
|
||||
for i in $(seq 1 $#); do
|
||||
echo "$i) ${!i}"
|
||||
done
|
||||
footer $i
|
||||
}
|
||||
|
||||
### ask for confirmation
|
||||
confirm() {
|
||||
header
|
||||
echo "Are you sure?"
|
||||
echo "1) Yes"
|
||||
echo "2) No"
|
||||
footer 3
|
||||
if [ $? -eq 1 ]; then return 0; else return 1; fi
|
||||
}
|
||||
|
||||
### main menu
|
||||
mainmenu() {
|
||||
header
|
||||
echo "1) Install operating system updates"
|
||||
echo
|
||||
echo "3) Start a shell session"
|
||||
echo "4) Restart server"
|
||||
echo "5) Shutdown server"
|
||||
echo "6) Logout"
|
||||
echo
|
||||
footer 7
|
||||
case $? in
|
||||
1)
|
||||
header
|
||||
echo 1; sleep 1
|
||||
;;
|
||||
2)
|
||||
header
|
||||
echo 2; sleep 1
|
||||
;;
|
||||
3)
|
||||
header
|
||||
echo "Executing $SHELL"; sleep 1; clear
|
||||
$SHELL
|
||||
;;
|
||||
4)
|
||||
if confirm; then
|
||||
header
|
||||
echo "Rebooting server"; sleep 1
|
||||
#sudo shutdown -r -t now
|
||||
fi
|
||||
;;
|
||||
5)
|
||||
if confirm; then
|
||||
header
|
||||
echo "Shutting down server"; sleep 1
|
||||
#sudo shutdown -h -t now
|
||||
fi
|
||||
;;
|
||||
6)
|
||||
header
|
||||
echo "Logging out"; sleep 1
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
header
|
||||
echo "Unknown option"; sleep 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
update() {
|
||||
systems="ubuntu arch solus raspbian antergos"
|
||||
issue="$(cat /etc/issue)"
|
||||
for item in $systems; do
|
||||
echo $issue | grep -i $item >> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
system=$item
|
||||
fi
|
||||
done
|
||||
|
||||
case $system in
|
||||
ubuntu|debian|raspbian)
|
||||
echo "Updating Ubuntu/Debian.."
|
||||
sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y
|
||||
;;
|
||||
arch|antergos)
|
||||
echo "Updating Arch Linux.."
|
||||
sudo pacman -Syu
|
||||
;;
|
||||
?)
|
||||
echo "error: unknown system."
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "error: something went wrong."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
## start loop
|
||||
menu "Install system upgrades" \
|
||||
"Reboot server" \
|
||||
"Shutdown server" \
|
||||
"Logout"
|
||||
|
||||
#while true; do mainmenu; done
|
||||
|
||||
exit 0
|
||||
# **** end of script ****
|
Loading…
Reference in New Issue
Block a user