Skip to content

Instantly share code, notes, and snippets.

@nockstarr
Created September 1, 2019 21:01
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 nockstarr/3767769c75297a3b85a17767a02525f8 to your computer and use it in GitHub Desktop.
Save nockstarr/3767769c75297a3b85a17767a02525f8 to your computer and use it in GitHub Desktop.
jejejejeje
#!/bin/bash
##########
## https://linuxhint.com/bash_loop_list_strings/
## https://linuxize.com/post/bash-functions/
##########
### This install script assumes it executed in project directory ###
set -e
DRY_RUN=
# base_apt_pkg will be installed by all
base_apt_pkg=("git" "curl" "tmux" "htop")
# Server packages
server_base_apt_pkg=("")
optional_server_apt_pkg=("cifs-utils")
# Client packages
client_base_apt_pkg=("gnome-tweak-tool" "dconf-tools" "wireshark" "openvpn" "network-manager-openvpn" "network-manager-openvpn-gnome" \
"neofetch")
optional_client_apt_pkg=("flat-remix" "flat-remix-gtk" "nodejs" "npm")
client_snap_pkg=("discord" "spotify" "telegram-desktop" "pycharm-professional --classic"
"webstorm --classic" "code --classic" "vlc")
if [[ "$(id -u)" = "0" ]]; then
echo -e "This script should not be run by sudo!\nSudo is invoked when needed"
exit 1
fi
if [[ "$1" == "--dry-run" ]]
then
echo -n "DRY-RUN mode.."
DRY_RUN=true
fi
echo "Dry-run: $DRY_RUN"
# Update and Upgrade
if [[ -z "$DRY_RUN" ]]; then sudo apt update && sudo apt upgrade; fi
function client_install(){
echo "[#] Performing Client Installation.."
local to_install=""
to_install+="${base_apt_pkg[@]} "
to_install+="${client_base_apt_pkg[@]} "
if [[ -n "$optional_client_apt_pkg" ]]
then
local body_text="Select optional APT pkg to install"
local res=$(select_menu body_text optional_client_apt_pkg)
if [[ -n $res ]]
then
for sel in $res
do
# Could use a case statement for special stuff like rclone and flat-remix
# and default opt could be appending to selected_opt_pkg..
# Dvs could have a special routine for stuff out side of apt/snap
to_install+="${optional_client_apt_pkg[sel-1]} "
done
if [[ "$to_install" == *"flat-remix"* ]]
then
echo "[#] Adding flat-remix repo"
if [[ -z "$DRY_RUN" ]]; then sudo add-apt-repository ppa:daniruiz/flat-remix; fi
fi
fi # if $res ends
fi
echo "[#] Installing APT packages"
echo "install -y ${to_install}"
if [[ -z "$DRY_RUN" ]]
then
sudo apt install -y ${to_install}
fi
echo ""
echo "[#] Installing Snap packages"
if [[ -z "$DRY_RUN" ]]; then sudo snap refresh; fi
for s in "${client_snap_pkg[@]}"
do
echo "install $s"
if [[ -z "$DRY_RUN" ]]; then sudo snap install $s; fi
done
echo ""
echo "[#] Configuring stuff.."
if [[ -z "$DRY_RUN" ]]
then
configure_tmux
configure_nano
move_dot_files
fi
echo "[*] Done Configuring"
echo ""
echo "[*] Client installation Done"
}
function server_install(){
echo "[#] Performing Server Installation.."
local to_install=""
to_install+="${base_apt_pkg[@]} "
to_install+="${server_base_apt_pkg[@]} "
if [[ -n "$optional_server_apt_pkg" ]]
then
local body_text="Select optional APT pkg to install"
local res=$(select_menu body_text optional_server_apt_pkg)
if [[ -n $res ]]
then
for sel in $res
do
to_install+="${optional_server_apt_pkg[sel-1]} "
done
fi
fi
echo "install -y ${to_install}"
if [[ -z "$DRY_RUN" ]]
then
sudo apt install -y $to_install
fi
echo "[#] Configuring stuff.."
if [[ -z "$DRY_RUN" ]]
then
configure_tmux
configure_nano
#move_dot_files
fi
# Dot files not needed yet.. Might need a client or server versioned bashrc dotfile..
# move_dot_files
echo "[*] Done Configuring"
echo ""
echo "[*] Server installation Done"
}
function select_menu() {
# $1 = select body text
# $2 = select array
local -n body=$1
local -n arr=$2
local COUNTER=1
local CHECKLIST="" # variable where we will keep the list entries for checklist dialog
# for i in ${arr[@]}; do
for i in "${arr[@]}"; do
CHECKLIST="$CHECKLIST $COUNTER $i off "
let COUNTER=COUNTER+1
done
#echo $CHECKLIST
local SELECT_RES=$(whiptail --title "Check what you need" --separate-output --checklist "$body" 0 0 $COUNTER $CHECKLIST 3>&1 1>&2 2>&3)
local exitstatus=$?
if [[ $exitstatus = 0 ]]; then
echo $SELECT_RES
else
echo "You chose Cancel."
exit 1
fi
}
function configure_tmux(){
echo "[-] Configuring Tmux.."
if [[ -d "$HOME/.tmux" ]]
then
mv $HOME/.tmux $HOME/.tmux_backup
fi
git clone https://github.com/gpakosz/.tmux.git $HOME/.tmux
ln -s -f $HOME/.tmux/.tmux.conf $HOME/.tmux.conf
cp $HOME/.tmux/.tmux.conf.local $HOME
echo "[#] Tmux Done"
}
function configure_nano() {
echo "[-] Configuring Nano.."
# Get improved syntax highlighting
if [[ -d "/usr/share/nano-syntax-highlighting/" ]]
then
sudo rm -rf /usr/share/nano-syntax-highlighting
fi
sudo git clone https://github.com/scopatz/nanorc.git /usr/share/nano-syntax-highlighting/
# Use config file
sudo cp config_files/nanorc /etc/nanorc
echo "[#] Nano DONE"
}
function move_dot_files(){
echo "[-] Configuring DotFiles.."
cp $HOME/.bashrc $HOME/.bashrc_default_bck
cp -a dotfiles/. $HOME
echo "[#] DoteFiles Done"
}
function test_select(){
#select_menu body_text apt_pkg_arr
body_text="Select APT pkg to install"
res=$(select_menu body_text base_apt_pkg)
echo $res
if [[ -z $res ]]
then
echo "No selections made.."
exit 1
fi
apt_install_cmd=""
for sel in $res; do
#echo $sel
#echo "${apt_pkg_arr[sel]}"
apt_install_cmd+="${base_apt_pkg[sel-1]} "
#echo ""
done
echo $apt_install_cmd
if [[ $apt_install_cmd == *"flat-remix"* ]]
then
echo "flat-remix in apt_install_cmd"
fi
}
SELECT_PLATFORM=$(whiptail --title "Select platform" --radiolist \
"Select installation platform" 0 0 2 \
"Client" "Ubuntu laptop/desktop - Includes apt/snap and user configs " OFF \
"Server" "Ubuntu server - Includes apt and user configs " OFF 3>&1 1>&2 2>&3)
#exitstatus=$?
case $SELECT_PLATFORM in
Client)
client_install
;;
Server)
server_install
;;
*)
echo "No platform selected.. Exiting.."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment