Last active
April 5, 2020 16:23
-
-
Save jmatthewturner/c9e73ed0c7127696fda4eec967820679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# PLEASE NOTE: I started learning Bash scripting 4 weeks ago, so if this somehow | |
# breaks your system and opens a wormhole to the Gamma Quadrant, | |
# I'm sorry. | |
# | |
# This is a setup script for Debian-based computers. It is highly customized | |
# for my personal use; I made it public because I think it could be a good | |
# starting point for someone else. It will need to be customized for anyone | |
# else's use. | |
# | |
# It requires some user input to run, making it somewhat adaptible. With a user- | |
# supplied backup location, it will restore backups to the user's home directory | |
# without destroying any files that may have already been added. | |
# | |
# It will also install a selection of software that I personally use. This part | |
# is not driven by user interaction; to alter what gets installed, you'll need to | |
# update the constants within the script. | |
# | |
# It uses a modified version of Dave Miller's excellent ask.sh script, | |
# which can be found here: | |
# https://gist.github.com/davejamesmiller/1965569 | |
# | |
# To modify ask.sh, simply change line 23 to read | |
# echo -n -e "$1 [$prompt] " | |
# | |
# (Adding the -e flag enables support for escape sequences, which allows | |
# the colored text formatting.) | |
# | |
# It also uses my own colors.sh script, which defines a list of colors | |
# for text formatting: | |
# https://gist.github.com/jmatthewturner/2aeee120aa112fd51b000e13579c2654 | |
# | |
# To run, just make sure that setup.sh (this script), ask.sh and colors.sh | |
# are in the same directory. (Everything is done with absolute paths, so it doesn't | |
# matter where they are.) | |
# | |
# Written by jmatthewturner | |
# https://github.com/jmatthewturner | |
# https://www.youtube.com/jmatthewturner/ | |
# | |
# https://gist.github.com/jmatthewturner/???? | |
# | |
. ./ask.sh # https://gist.github.com/davejamesmiller/1965569 | |
. ./colors.sh # https://gist.github.com/jmatthewturner/2aeee120aa112fd51b000e13579c2654 | |
# Instructions | |
instructions() | |
{ | |
clear | |
echo -e "\nThis is a highly personalized script that installs a bunch of software that" | |
echo -e "I use, reinstates some backups and sets a few things up the way I want them." | |
echo -e "${LIGHTYELLOW}If you are not me, I highly recommend that you personalize this" | |
echo -e "script before running it.${RESET} More info in the comments." | |
echo -e "\nIt's split into two parts: 1) install a bunch of stuff, then 2) copy backups" | |
echo -e "to the local drive. This way you can spend 5 minutes babysitting it up front" | |
echo -e "and then walk away while the file copy executes.\n" | |
echo -e "You can install everything at once, or you can itemize." | |
echo -e "${LIGHTYELLOW}Software installed includes KDE Plasma, utilities," | |
echo -e "video codecs and drivers, Spotify, Virtualbox, Wire and Signal.\n${RESET}" | |
} | |
# Check if running with root priveleges. | |
# | |
check_sudo() | |
{ | |
if [[ $(id -u) -ne 0 ]] | |
then | |
echo -e "\n${LIGHTYELLOW}Please run this script with root priveleges.\n${RESET}" | |
exit 1 | |
fi | |
} | |
# Update everything. | |
# | |
apt_updates() | |
{ | |
apt update | |
apt upgrade -y | |
} | |
# Install KDE Plasma | |
# | |
kde_plasma() | |
{ | |
apt install -y kubuntu-desktop | |
} | |
# Install Basic Utilities | |
# | |
basic_utilities() | |
{ | |
UTILITIES="yakuake neofetch backintime-qt4 qbittorrent \ | |
browser-plugin-freshplayer-pepperflash xorriso \ | |
nmon powertop htop nmap memtester exfat-utils exfat-fuse \ | |
terminator darktable gtkhash gimp" | |
apt install -y ${UTILITIES} | |
} | |
# Install Video Stuff | |
# https://support.system76.com/articles/codecs/ | |
# This actually installs the recommended apps for 18.10 instead of 18.04. | |
# The only difference is swapping out gstreamer1.0-fluendo-mp3 for | |
# grstreamer1.0-plugins-good, which seems like a good idea. | |
# | |
# This list last updated 2019-09-08 | |
# | |
video_stuff() | |
{ | |
VIDEO="gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-plugins-good \ | |
libavcodec-extra gstreamer1.0-libav libdvd-pkg ffmpeg \ | |
chromium-codecs-ffmpeg-extra vlc mediainfo nvidia-cuda-toolkit" | |
apt install -y ${VIDEO} | |
dpkg-reconfigure libdvd-pkg | |
} | |
# Install Virtualbox: | |
# | |
virtualbox() | |
{ | |
echo -e "\n${LIGHTYELLOW}Installing Virtualbox...${RESET}" | |
apt install -y virtualbox virtualbox-ext-pack virtualbox-qt | |
user mod -a -G vboxusers ${SUDO_USER} | |
} | |
# Install Wire | |
# | |
wire() | |
{ | |
echo -e "\n${LIGHTYELLOW}Installing Wire...${RESET}" | |
apt-get install apt-transport-https | |
wget -q https://wire-app.wire.com/linux/releases.key -O- | apt-key add - | |
echo "deb [arch=amd64] https://wire-app.wire.com/linux/debian stable main" | \ | |
tee /etc/apt/sources.list.d/wire-desktop.list | |
apt update | |
apt install -y wire-desktop | |
} | |
# Install Signal | |
# | |
signal() | |
{ | |
echo -e "\n${LIGHTYELLOW}Installing Signal...${RESET}" | |
curl -s https://updates.signal.org/desktop/apt/keys.asc | apt-key add - | |
echo "deb [arch=amd64] https://updates.signal.org/desktop/apt xenial main" | \ | |
tee -a /etc/apt/sources.list.d/signal-xenial.list | |
apt update | |
apt install -y signal-desktop | |
} | |
# Install Spotify | |
# | |
spotify() | |
{ | |
echo -e "\n${LIGHTYELLOW}Installing Spotify...${RESET}" | |
curl -sS https://download.spotify.com/debian/pubkey.gpg | sudo apt-key add - | |
echo "deb http://repository.spotify.com stable non-free" | sudo tee /etc/apt/sources.list.d/spotify.list | |
apt update | |
apt install -y spotify-client | |
} | |
# Prep for DBP | |
dragon() | |
{ | |
echo -e "\n${LIGHTYELLOW}Creating mount point for Dragon of the Black Pool...${RESET}" | |
mkdir ~/Dragon_of_the_Black_Pool | |
} | |
# Copy backups of selected /etc files to new machine. | |
# Creates backups before it un-backs up the backups, Dawg. | |
# | |
copy_etc_files() | |
{ | |
ETC_FILES="hosts hostname" # Define files to be copied. | |
echo -e "\n${LIGHTYELLOW}Where is the most recent backup of /etc? \ | |
(Select [backup]/etc/):${RESET} " | |
read -e etc_dir | |
for i in ${ETC_FILES} | |
do | |
echo -e "${LIGHTYELLOW}Copying ${i} to /etc/${i}...${RESET}" | |
mv /etc/${i} /etc/${i}_original | |
cp "${etc_dir}/${i}" /etc/ | |
chown root "/etc/${i}" | |
chmod 644 "/etc/${i}" | |
done | |
} | |
# Rebuild the Home Directories Part 1: | |
# Define the list of destination directories and display them for the user's confirmation. | |
# Get the backup location from user. | |
# | |
rebuild1_establish_directories() | |
{ | |
# Define default home folders. | |
DEFAULT_HOME_FOLDERS=('Desktop' 'Documents' 'Downloads' 'Music'\ | |
'Pictures' 'Public' 'Templates' 'Videos') | |
# Define additional home folders. | |
ADDITIONAL_HOME_FOLDERS=('Scripts' 'VirtualBox VMs') | |
# Define directories to rebuild. | |
ALL_HOME_FOLDERS=("${DEFAULT_HOME_FOLDERS[@]}" "${ADDITIONAL_HOME_FOLDERS[@]}") | |
# Confirm these actions (just so I don't forget which directories I included here). | |
# | |
# First for loop lists the Default home folders: | |
echo -e "${LIGHTYELLOW}\nThis will rebuild the following directories:${RESET}" | |
for ((i = 0; i < ${#DEFAULT_HOME_FOLDERS[@]}; i++)) | |
do | |
echo -e "${DEFAULT_HOME_FOLDERS[$i]}" | |
done | |
echo -e "-------------" | |
# Second for loop lists user-added home folders: | |
for ((i = 0; i < ${#ADDITIONAL_HOME_FOLDERS[@]}; i++)) | |
do | |
echo -e "${ADDITIONAL_HOME_FOLDERS[$i]}" | |
done | |
# Retrieve the backup location. | |
echo -e "\n${LIGHTYELLOW}Where is the most recent backup of /home/jmatthewturner?${RESET}" | |
echo -e "(Select [backup]/jmatthewturner/)" | |
read -e home_backup | |
} | |
# Rebuild the Home Directories Part 2: | |
# Copy the files from established directories and perform some admin/cleanup. | |
# | |
rebuild2_copy_files() | |
{ | |
# Array for tracking backup directories that cannot be found. | |
declare -a missing_dirs | |
# Array for tracking backup directories that are successfully copied. | |
declare -a completed_dirs | |
# User-created home folders may not exist yet, so create them. | |
for ((i = 0; i < ${#ADDITIONAL_HOME_FOLDERS[@]}; i++)) | |
do | |
if [[ ! -e ~/${ADDITIONAL_HOME_FOLDERS[$i]} ]] | |
then | |
mkdir -v "$HOME/${ADDITIONAL_HOME_FOLDERS[$i]}" | |
fi | |
done | |
# Display a message for the user. | |
echo -e "\n${LIGHTYELLOW}Copying default Home folders...${RESET}" | |
echo -e "Note: this will throw an error if any of the directories" | |
echo -e "are empty, but it works." | |
# For each of the defined directories, copy all files from backups to local directory. | |
for ((i = 0; i < ${#ALL_HOME_FOLDERS[@]}; i++)) | |
do | |
if [[ ! -e ${home_backup}${ALL_HOME_FOLDERS[$i]} ]] | |
then | |
missing_dirs+=("${ALL_HOME_FOLDERS[$i]}") | |
else | |
cp -v -i -r "${home_backup}${ALL_HOME_FOLDERS[$i]}/"* \ | |
"${HOME}/${ALL_HOME_FOLDERS[$i]}/" | |
completed_dirs+=("${ALL_HOME_FOLDERS[$i]}") | |
fi | |
done | |
# As of 2019-08-16, this section with .bashrc and .profile has not been tested. | |
# It failed the last time I ran the script, and I think I fixed it. But you never know. | |
# | |
# Save fresh login scripts and install backed up scripts. | |
mv ${HOME}/.bashrc ${HOME}/.bashrc_original | |
mv ${HOME}/.profile ${HOME}/.profile_original | |
cp ${home_backup}/.bashrc ${home_backup}/.profile ${HOME} | |
# Copy files into the root home directory without recursion. | |
# This does not include hidden files. | |
echo -e "\n${LIGHTYELLOW}Copying loose files from home folder...${RESET}" | |
cp -v -i "${home_backup}"* "${HOME}/" | |
# Make sure file permissions are all in order. | |
chown -R ${SUDO_USER} ${HOME} | |
chmod -R 755 ${HOME} | |
chmod 755 ${HOME}/.bashrc ${HOME}/.profile | |
# Report completion status to user. | |
echo -e "\n${LIGHTYELLOW}The following directories were copied to ${HOME}/:${RESET}" | |
for ((i = 0; i < ${#completed_dirs[@]}; i++)) | |
do | |
echo -e ${home_backup}${completed_dirs[$i]} | |
done | |
echo -e "\n${LIGHTYELLOW}The following directories do not exist in ${home_backup}:${RESET}" | |
for ((i = 0; i < ${#missing_dirs[@]}; i++)) | |
do | |
echo -e ${home_backup}${missing_dirs[$i]} | |
done | |
echo -e "\n${LIGHTYELLOW}Check if there are any random folders you want to bring over.${RESET}" | |
} | |
# Rebuild the Home directories. | |
# This function copies files from backups into the new, local directores. It does NOT | |
# move/replace the directories themselves, just in case files have already been added to the | |
# local directories. Any files already on the new installation will be kept. | |
# | |
rebuild_home_dir() | |
{ | |
# Define key directories | |
rebuild1_establish_directories | |
# Confirm file copy | |
echo -e "\n${LIGHTYELLOW}Copying backups from:${RESET}" | |
echo -e "${home_backup}" | |
echo -e "${LIGHTYELLOW}to:${RESET}" | |
echo -e "${HOME}/" | |
if ask "\n${LIGHTYELLOW}Proceed?${RESET}" Y | |
then | |
# Copy the files | |
rebuild2_copy_files | |
else | |
echo -e "\n${LIGHTYELLOW}File copy skipped.${RESET}" | |
fi | |
} | |
# Recommend some next steps | |
# | |
next_steps() | |
{ | |
echo -e "\n${RED}All done.${RESET}" | |
echo -e "\n${LIGHTYELLOW}Some things to do RIGHT NOW:${RESET}" | |
echo -e " * Restart." | |
echo -e " * Set display to 2560x1440, scale to 1.5." | |
echo -e " * Install Firefox extensions: Enhancer for YouTube, 1Password X," | |
echo -e " FVD Speed Dial, Ublock Origin." | |
echo -e " * Log into 1Password using security key. Set timeout lock to 999." | |
echo -e " * Change Firefox setting to Restore Previous Session." | |
echo -e " * Turn on numlock in KDE Keyboard Settings." | |
echo -e "\n${LIGHTYELLOW}Some things to do next:${RESET}" | |
echo -e " * Configure Dolphin to launch in split mode with default view Details." | |
echo -e " * Install SpiderOak using the .deb from their website." | |
echo -e " https://spideroak.com/one/download/" | |
echo -e " * Install Dropbox using the .deb from their website." | |
echo -e " Installing with the GUI solves dependency issues." | |
echo -e " * Add The Printer Who Lived using the Add Printer dialog." | |
echo -e " * Add a Dolphin sidebar entry for WD MyCloud: smb://192.168.1.177." | |
echo -e " * Set up KDE Connect." | |
echo -e " * Import VMs into Virtualbox. (Create NEW machines, but select" | |
echo -e " Use Exisitng Hard Drive and choose the VDI.)" | |
echo -e " * Set up Yakuake according to settings: ...." | |
echo -e " * Disable KDE Wallet: kwalletmanager --> Settings --> Disable." | |
echo -e " * Install Express VPN: log into website, download installer," | |
echo -e " activate and enter one-time code." | |
echo -e " * Disks --> DBP --> Disable User Session Defaults --> ext4 --> set mount point." | |
echo -e " * After restarting and mounting DBP, run these:" | |
echo -e " sudo chown -Rc jmatthewturner ~/Dragon_of_the_Black_Pool" | |
echo -e " sudo chmod -Rc u_rwX,g+rwX,o-rwx ~/Dragon_of_the_Black_Pool" | |
echo -e " * Reconnect Back in Time to previous backups using config file." | |
echo -e " * Install DaVinci Resolve. The process to reconnect a database is:" | |
echo -e " 1) clck New Database" | |
echo -e " 2) under the Connect tab, choose the folder that contains Cache Clip" | |
echo -e " (usually DaVinci Resolve)" | |
echo -e " 3) Enter the new name you want the database to have, and click Add." | |
echo -e " * Get the Alt key working inside of Resolve:" | |
echo -e " Window Behavior --> Window Actions --> Alt+Left Button = nothing" | |
echo | |
echo -e "${LIGHTYELLOW}To see these Next Steps again, use:${RESET}" | |
echo -e '$ ./setup.sh next' | |
echo | |
} | |
############################################################# | |
######################## MAIN ROUTINE ####################### | |
############################################################# | |
# Special case to display next steps and exit. | |
# | |
if [[ $1 == "next" ]] | |
then | |
next_steps | |
exit 0 | |
fi | |
# Check for root priveleges | |
# | |
check_sudo | |
# Display basic instructions. | |
# | |
instructions | |
# Install software. | |
# | |
if ask ${LIGHTYELLOW}"Itemize software?${RESET}" Y | |
then | |
if ask "${LIGHTYELLOW}Run apt updates?${RESET}" N | |
then | |
apt_updates | |
fi | |
if ask "${LIGHTYELLOW}Install KDE Plasma?${RESET}" N | |
then | |
kde_plasma | |
fi | |
if ask "${LIGHTYELLOW}Install some basic utilities?${RESET}" N | |
then | |
basic_utilities | |
fi | |
if ask "${LIGHTYELLOW}Install a lot video codecs and NVIDIA drivers and other useful media software?${RESET}" N | |
then | |
video_stuff | |
fi | |
if ask "${LIGHTYELLOW}Install Virtualbox?${RESET}" N | |
then | |
virtualbox | |
fi | |
if ask "${LIGHTYELLOW}Install Wire?${RESET}" N | |
then | |
wire | |
fi | |
if ask "${LIGHTYELLOW}Install Signal?${RESET}" N | |
then | |
signal | |
fi | |
if ask "${LIGHTYELLOW}Install Spotify?${RESET}" N | |
then | |
spotify | |
fi | |
elif ask "${LIGHTYELLOW}\nInstall everything?${RESET}" N | |
then | |
apt_updates | |
kde_plasma | |
basic_utilities | |
video_stuff | |
virtualbox | |
wire | |
signal | |
spotify | |
else | |
echo -e "\nAll software skipped.\n" | |
fi | |
# Do just a little system configuration. | |
# | |
if ask "${LIGHTYELLOW}Create a mount point for Dragon of the Black Pool?${RESET}" N | |
then | |
dragon | |
fi | |
if ask "${LIGHTYELLOW}Replace selected /etc files with the backed up versions?${RESET}" N | |
then | |
copy_etc_files | |
fi | |
# Copy home directory from backups. | |
# | |
if ask "${LIGHTYELLOW}Rebuild the home directory?${RESET}" N | |
then | |
rebuild_home_dir | |
fi | |
# Display some next steps. | |
# | |
next_steps | |
# Exit successfully. | |
# | |
exit 0 | |
# | |
# Written by jmatthewturner | |
# https://github.com/jmatthewturner | |
# https://www.youtube.com/jmatthewturner/ | |
# | |
# https://gist.github.com/jmatthewturner/c9e73ed0c7127696fda4eec967820679 | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment