Skip to content

Instantly share code, notes, and snippets.

@p4p1
Last active Jul 6, 2020
Embed
What would you like to do?
📁📁📁📁
#!/bin/bash
# problem.sh
# Created on: Wed 27 May 2020 07:08:31 PM CEST
# Creator: Leo Smith (aka p4p1)
# Creator website: https://p4p1.github.io/
# ____ __ ____ __
# ( _ \ /. |( _ \/ )
# )___/(_ _))___/ )(
# (__) (_)(__) (__)
#
# Description:
# simple script to get help <3
#
# Install:
# chmod +x ./problem.sh && sudo cp -r ./problem.sh /usr/local/bin/
#
# Dependencies:
# sudo apt install dialog tree ssh git curl
#
# Usage:
# Students:
# ./problem.sh
# ./problem.sh -b # Show a banner
# ./problem.sh -i # Install this software
# Teachers:
# To add new questions just follow those simple instructions, 1: add a
# question to the question variable. 2: create the function. 3: add an entry
# to the switch case at the bottom of the script
# Ignore this line
DIALOG_RC="use_shadow = ON\nuse_colors = ON\nscreen_color = (RED,BLACK,ON)\nshadow_color = (BLACK,BLACK,ON)\ndialog_color = (BLACK,WHITE,OFF)\ntitle_color = (RED,WHITE,ON)\nborder_color = (WHITE,WHITE,ON)\nbutton_active_color = (RED,BLACK,ON)\nbutton_inactive_color = dialog_color\nbutton_key_active_color = button_active_color\nbutton_key_inactive_color = (BLACK,WHITE,OFF)\nbutton_label_active_color = (RED, BLACK, ON)\nbutton_label_inactive_color = (BLACK,WHITE,ON)\ninputbox_color = dialog_color\ninputbox_border_color = dialog_color\nsearchbox_color = dialog_color\nsearchbox_title_color = title_color\nsearchbox_border_color = border_color\nposition_indicator_color = title_color\nmenubox_color = dialog_color\nmenubox_border_color = border_color\nitem_color = dialog_color\nitem_selected_color = button_active_color\ntag_color = title_color\ntag_selected_color = button_label_active_color\ntag_key_color = button_key_inactive_color\ntag_key_selected_color = (RED,BLACK,ON)\ncheck_color = dialog_color\ncheck_selected_color = button_active_color\nuarrow_color = (GREEN,WHITE,ON)\ndarrow_color = uarrow_color\nitemhelp_color = (WHITE,BLACK,OFF)\nform_active_text_color = button_active_color\nform_text_color = (WHITE,CYAN,ON)\nform_item_readonly_color = (CYAN,WHITE,ON)\ngauge_color = title_color\nborder2_color = dialog_color\ninputbox_border2_color = dialog_color\nsearchbox_border2_color = dialog_color\nmenubox_border2_color = dialog_color\n"
# Important variables
WIDTH=80
HEIGHT=30
#INSTALL_DIR=/opt/problem # no use for now
dependencies=(dialog tree ssh git curl)
blih_url="https://raw.githubusercontent.com/Epitech/dump/master/blih.py"
devgo_pack=(
ssh git curl php nodejs npm build-essentials vim emacs libbz2-dev tig tmux \
tilix apache2 \
)
# TODO: Add new questions here with the same format
question=(
"1" "Install blih and ssh" \
"2" "Intall school software suite" \
"3" "Install apache configuration" \
"4" "Help" \
"5" "NOP"\
)
function usage() {
echo -e "Description:"
echo -e "\tNew to linux? no worries, this tool helps you correct a few bugs"
echo -e "\there and there to help you have a stable working environement."
echo -e "\tFor more information open up the file and read the source code."
echo -e "Usage:"
echo -e "\t$0\t"
echo -e "\t$0 -b\t\t# Show a banner"
echo -e "\t$0 -i\t\t# Install this software"
echo -e "Made by p4p1"
}
# TODO: Add function here with the same syntax
function install_blih_shh() {
ret="Bad token"
# Installing blih
if ! hash blih &> /dev/null; then
curl $blih_url --output /tmp/blih
chmod +x /tmp/blih
sudo mv /tmp/blih ${PATH[0]%%:*}/blih
fi
if [ ! -d $HOME/.ssh ]; then
echo -n "Press [Enter] 3 times to set the path to default and password to"
echo " (null)"
sshkey-gen
fi
echo -n "Please enter your @epitech.eu email: "
read email
echo -n "You are uploading your ssh public file to the server, press <C-c> "
echo "to exit"
while [[ ! -z "$ret" ]]; do
ret=$(blih -u $email sshkey upload ~/.ssh/id_rsa.pub)
echo $ret
ret=$(echo $ret | grep "Bad token")
done
ssh git@git.epitech.eu
echo "All done, press [Enter]"
read tmp
}
function install_software_suite() {
# Installing software
echo -e "\e[96;5;4mInstalling packages ...\e[m"
for item in ${devgo_pack[@]}; do
echo -n "Checking $item -> "
if hash $item &> /dev/null; then
echo -e "\e[1;34m:)\e[m"
else
echo -e "\e[1;31m:(\e[m"
sudo apt install -y $item
fi
done
echo
why_is_blih_not_working
}
function install_apache_conf() {
# function to install apache configuration
WEB_SERVER_ROOT=/var/www/html
WEB_SERVER_CONF=/etc/apache2
APACHE_CONF="<VirtualHost *:80>\n\tServerName web-and-go.fr\n\tServerAlias www.web-and-go.fr\n\tServerAdmin contact@web-and-go.fr\n\tDocumentRoot $WEB_SERVER_ROOT\n\tErrorLog ${APACHE_LOG_DIR}/web-and-go.log\n\tCustomLog ${APACHE_LOG_DIR}/web-and-go.log combined\n</VirtualHost>"
sudo echo -e $APACHE_CONF > $WEB_SERVER_CONF/site-available/web-and-go.conf
sudo a2ensite dev-and-go
sudo systemctl reload apache2
}
# function for the banner can be shown with -b
function banner() {
echo -e "\e[35m ______ _______ __ _______ _______\e[m"
echo -e "\e[35m ( __ \ ( ____ \|\ /| /__\ ( ____ \( ___ )\e[m"
echo -e "\e[35m | ( \ )| ( \/| ) ( |( \/ ) | ( \/| ( ) |\e[m"
echo -e "\e[35m | | ) || (__ | | | | \ / | | | | | |\e[m"
echo -e "\e[35m | | | || __) ( ( ) ) / \/\| | ____ | | | |\e[m"
echo -e "\e[35m | | ) || ( \ \_/ / / /\ /| | \_ )| | | |\e[m"
echo -e "\e[35m | (__/ )| (____/\ \ / ( \/ \| (___) || (___) |\e[m"
echo -e "\e[35m (______/ (_______/ \_/ \___/\/(_______)(_______)\e[m"
echo
echo "Press [Enter] to continue:"
read tmp
}
# function to install software list
function installer() {
echo -e "\e[96;5;4mInstalling packages ...\e[m"
sudo apt update
for item in $@; do
echo -n "Checking $item -> "
if hash $item &> /dev/null; then
echo -e "\e[1;34m:)\e[m"
else
echo -e "\e[1;31m:(\e[m"
sudo apt install -y $item
fi
done
echo
}
echo -e $DIALOG_RC > $HOME/.dialogrc
# Command parser
while getopts "bi" o; do
case "${o}" in
b)
banner
;;
i)
installer ${dependencies[*]}
#sudo mkdir -p $INSTALL_DIR
sudo cp -r $0 ${PATH[0]%%:*}/$0
echo -e "Copied \e[1;31m$0\e[m to: \e[1;34m${PATH[0]%%:*}/$0\e[m"
exit
;;
*)
usage
exit 84
;;
esac
done
shift $((OPTIND-1))
# Initial setup
echo -en "\e[96;5;4mChecking dependencies \e[m"
for item in ${dependencies[*]}; do
if hash $item; then
echo -n "."
else
installer ${dependencies[*]}
fi
done
echo # echo for a new line
# Main while loop
while true; do
exec 3>&1
selection=$(dialog --backtitle "$0" \
--clear \
--title "What is your problem?" \
--cancel-label "Exit" \
--menu "Please select:" \
$HEIGHT $WIDTH 20 \
"${question[@]}" \
2>&1 1>&3)
exit_state=$?
exec 3>&-
[ $exit_state -ne "0" ] && break
# TODO: Add here new entries for question functions
case $selection in
0 )
clear
break
;;
1)
install_blih_shh
;;
2)
install_software_suite
;;
3)
install_apache_conf
;;
4)
usage
echo "Press [Enter] to continue:"
read tmp
;;
5)
;;
esac
done
echo "All done :)"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment