Skip to content
Snippets Groups Projects
Commit 0855d47f authored by Keegan Mullaney's avatar Keegan Mullaney
Browse files

conversion from Fedora to Ubuntu

also remove server options

 On branch master
 Your branch is up-to-date with 'origin/master'.

 Changes to be committed:
	modified:   LICENSE
	modified:   README.md
	new file:   includes/base.lib
	new file:   includes/git.lib
	new file:   includes/software.lib
	new file:   run.sh
	new file:   scripts/aliases.sh
	new file:   scripts/git_config.sh
	new file:   scripts/linux_update.sh
	new file:   scripts/ssh_key.sh
	new file:   scripts/terminal_config.sh
	new file:   sudoers.sh
	new file:   vars.sh
parent 9131c5ee
No related branches found
No related tags found
No related merge requests found
The MIT License (MIT)
Copyright (c) 2016 Keegan Mullaney
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SEE: http://kma.mit-license.org
# ubuntu-workstation-setup
Quickly configures a fresh install of Ubuntu 14.04 x64 for a workstation.
ubuntu-workstation-setup
========================
Quickly configures a fresh install of [Ubuntu 14.04 x64][ubuntu] for a workstation.
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## What it can do
- update Ubuntu and install useful programs
- configure [git][git] for pushing and pulling with [GitHub][gh]
- generate an [RSA key][sshkey] for remote [SSH sessions][ssh] if none exists (note: this is not a [GPG key][gpgkey])
- add some [shell aliases][sa]
- configure some terminal settings
## Usage
### Clone or download this project
- HTTPS: `git clone https://github.com/keegoid/config-ubuntu-workstation.git`
- SSH: `git clone git@github.com:keegoid/config-ubuntu-workstation.git`
### Set variables for run.sh script
Open **vars.sh** with your favorite text editor and **edit the input variables** at the top to reflect your information.
### Run run.sh
```bash
sudo chmod +x run.sh
sudo dos2unix -k run.sh
sudo ./run.sh
```
## SSH Keys
You can save a backup copy of your [SSH key pair][sshkey] that gets generated and output to the screen. I prefer saving it as a secure note in [LastPass][lp]. Copy the keys from the [Linux console][lc] with `ctrl+shift+c` before clearing the screen.
```bash
cat ~/.ssh/id_rsa.pub
cat ~/.ssh/id_rsa
clear
```
## License
SEE: http://keegoid.mit-license.org
[ubuntu]: http://www.ubuntu.com/global
[lc]: http://en.wikipedia.org/wiki/Linux_console
[lp]: https://lastpass.com/f?3202156
[ss]: http://en.wikipedia.org/wiki/Shell_script
[ssh]: http://en.wikipedia.org/wiki/Secure_Shell
[sshkey]: http://en.wikipedia.org/wiki/Ssh-keygen
[gpgkey]: http://en.wikipedia.org/wiki/GNU_Privacy_Guard
[sa]: http://en.wikipedia.org/wiki/Alias_%28command%29
[gh]: https://github.com/
[git]: https://git-scm.com/
[twitter]: https://twitter.com/intent/tweet?screen_name=keegoid&text=loving%20your%20CentOS%207.0%20deploy%20scripts%20for%20%40middlemanapp%20or%20%40WordPress%20with%20%40nginxorg%20https%3A%2F%2Fgithub.com%2Fkeegoid%2Flinux-deploy-scripts
#!/bin/bash
# --------------------------------------------
# A library of useful Linux functions
#
# Author : Keegan Mullaney
# Company: KM Authorized LLC
# Website: http://kmauthorized.com
#
# MIT: http://kma.mit-license.org
# --------------------------------------------
# set variables
declare -r TRUE=0
declare -r FALSE=1
# purpose: converts a string to lower case
# arguments:
# $1 -> string to convert to lower case
function to_lower()
{
local str="$@"
local output
output=$(tr '[A-Z]' '[a-z]'<<<"${str}")
echo $output
}
# purpose: to display an error message and die
# arguments:
# $1 -> message
# $2 -> exit status (optional)
function die()
{
local m=$1 # message
local e=${2-1} # default exit status 1
printf "$m"
exit $e
}
# purpose: return true if script is executed by the root user
# arguments: none
# return: true or die with message
function is_root()
{
# [ $(id -u) -eq 0 ] && return $TRUE || return $FALSE
[ "$EUID" -eq 0 ] && return $TRUE || return $FALSE
}
# purpose: return true $user exits in /etc/passwd
# arguments:
# $1 -> username to check in /etc/passwd
# return: true or false
function user_exists()
{
local u="$1"
# -q (quiet), -w (only match whole words, otherwise "user" would match "user1" and "user2")
if grep -qw "^${u}" /etc/passwd; then
echo "user $u exists in /etc/passwd"
return $TRUE
else
echo "user $u does not exists in /etc/passwd"
return $FALSE
fi
}
# purpose: trim shortest pattern from the left
# arguments:
# $1 -> variable
# $2 -> pattern
function trim_shortest_left_pattern()
{
echo -n "${1#*$2}"
# -n (don't create newline character)
}
# purpose: trim longest pattern from the left
# arguments:
# $1 -> variable
# $2 -> pattern
function trim_longest_left_pattern()
{
echo -n "${1##*$2}"
}
# purpose: trim shortest pattern from the right
# arguments:
# $1 -> variable
# $2 -> pattern
function trim_shortest_right_pattern()
{
echo -n "${1%$2*}"
}
# purpose: trim longest pattern from the right
# arguments:
# $1 -> variable
# $2 -> pattern
function trim_longest_right_pattern()
{
echo -n "${1%%$2*}"
}
# purpose: return name of script being run
# arguments:
# $1 -> message before
# $2 -> message after
function script_name()
{
# echo "$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
# can be accomplished with trim_longest_left_pattern instead
echo -n "$1" && trim_longest_left_pattern $0 / && echo "$2"
}
# purpose: wait for user to press enter
# arguments:
# $1 -> user message
function pause()
{
local msg="$1"
[ -z "${msg}" ] && msg="Press [Enter] key to continue..."
read -p "$msg"
}
# purpose: run a script from another script
# arguments:
# $1 -> name of script to be run
function run_script()
{
local script="$1"
local project_dir="$PWD"
# reset back to root poject directory to run scripts
cd "$project_dir/scripts"
echo "changing directory to $_"
# make sure dos2unix is installed
hash dos2unix 2>/dev/null || { echo >&2 "dos2unix will be installed."; apt-get -y install dos2unix; }
dos2unix -k ${script} && echo "carriage returns removed"
chmod +x ${script} && echo "execute permissions set"
chown $(logname):$(logname) ${script} && echo "owner set to $(logname)"
read -p "Press enter to run: ${script}"
. ./${script}
echo
echo " done with ${script}"
echo "*********************************************"
cd "$project_dir"
}
# purpose: set Repos directory location
# arguments:
# $1 -> non-root Linux username
# $2 -> use Dropbox?
function locate_repos()
{
local u="$1"
local db=$2
local repos
if [ "$db" = true ]; then
repos="/home/${u}/Dropbox/Repos"
# if dropbox directory is made, set ownership
if mkdir -p "/home/${u}/Dropbox"; then
chown $u:$u "/home/${u}/Dropbox"
fi
else
repos="/home/${u}/Repos"
fi
# if repos directory is made, set ownership
if mkdir -p "$repos"; then
chown $u:$u "$repos"
fi
echo -n $repos
}
# purpose: generate an RSA SSH keypair if none exists or copy from root
# arguments:
# $1 -> SSH directory
# $2 -> SSH key comment
# $3 -> use SSH?
# $4 -> non-root Linux username (optional)
function gen_ssh_keys()
{
local ssh_dir="$1"
local comment="$2"
local use_ssh=$3
local u="$4"
# echo "variable use_ssh = $use_ssh"
# pause
if [ "$use_ssh" = true ]; then
# move id_rsa to new user account or create new SSH keypair if none exists
echo
pause "Press enter to continue to SSH keys..."
echo
echo "Note: ${ssh_dir}/id_rsa is for public/private key pairs to establish"
echo "outgoing SSH connections to remote systems"
echo
# check if id_rsa already exists and skip if true
if [ -e "${ssh_dir}/id_rsa" ]; then
echo "${ssh_dir}/id_rsa already exists"
# if it doesn't exist, get it from root user
# elif [ -e "$HOME/.ssh/id_rsa" ] && [ -n "${u}" ]; then
# mkdir -pv "${ssh_dir}"
# cp -v $HOME/.ssh/id_rsa ${ssh_dir}
# cp -v $HOME/.ssh/id_rsa.pub ${ssh_dir}
# chmod -c 0600 "${ssh_dir}/id_rsa"
# chown -cR "${u}":"${u}" "${ssh_dir}"
# if no id_rsa, create a new keypair
else
# create a new ssh key with provided ssh key comment
echo "create new key: ${ssh_dir}/id_rsa"
pause "Press enter to generate a new SSH key"
ssh-keygen -b 4096 -t rsa -C "${comment}"
echo "SSH key generated"
# if [ -e "$HOME/.ssh/id_rsa" ] && [ -n "${ssh_dir}/id_rsa" ]; then
# mkdir -pv "${ssh_dir}"
# cp -v $HOME/.ssh/id_rsa "${ssh_dir}/id_rsa"
# cp -v $HOME/.ssh/id_rsa.pub "${ssh_dir}/id_rsa.pub"
# fi
chmod -c 0600 "${ssh_dir}/id_rsa"
chown -cR "${u}":"${u}" "${ssh_dir}"
echo
echo "*** NOTE ***"
echo "Copy the contents of id_rsa.pub (printed below) to the SSH keys section"
echo "of your GitHub account or authorized_keys section of your remote server."
echo "Highlight the text with your mouse and press ctrl+shift+c to copy."
echo
cat "${ssh_dir}/id_rsa.pub"
echo
read -p "Press enter to continue..."
fi
echo
echo "Have you copied id_rsa.pub (above) to the SSH keys section"
echo "of your GitHub account?"
select yn in "Yes" "No"; do
case $yn in
"Yes") break;;
"No") echo "Copy the contents of id_rsa.pub (printed below) to the SSH keys section"
echo "of your GitHub account."
echo "Highlight the text with your mouse and press ctrl+shift+c to copy."
echo
cat "${ssh_dir}/id_rsa.pub";;
*) echo "case not found, try again..."
continue;;
esac
break
done
fi
}
# purpose: set authorized SSH keys for incoming connections on remote host
# arguments:
# $1 -> SSH directory
# $2 -> non-root Linux username
function authorized_ssh_keys()
{
local ssh_dir="$1"
local u="$2"
local ssh_rsa
echo
echo "Note: ${ssh_dir}/authorized_keys are public keys to establish"
echo "incoming SSH connections to a server"
echo
if [ -e "${ssh_dir}/authorized_keys" ]; then
echo "${ssh_dir}/authorized_keys already exists for ${u}"
else
# passwd "${u}"
# echo
# echo "for su root command:"
# passwd root # for su root command
mkdir -pv "${ssh_dir}"
chmod -c 0700 "${ssh_dir}"
echo
echo "*** NOTE ***"
echo "Paste (using ctrl+shift+v) your public ssh-rsa key from your workstation"
echo "to SSH into this server."
read -e -p "Paste it here: " ssh_rsa
echo "${ssh_rsa}" > "${ssh_dir}/authorized_keys"
echo "public SSH key saved to ${ssh_dir}/authorized_keys"
chmod -c 0600 "${ssh_dir}/authorized_keys"
chown -cR "${u}":"${u}" "${ssh_dir}"
fi
}
# purpose: import public GPG key if it doesn't already exist in list of RPM keys
# although rpm --import won't import duplicate keys, this is a proof of concept
# arguments:
# $1 -> URL of the public key file
# return: false if URL is empty, else true
function get_public_key()
{
local url="$1"
local apt_keys="$HOME/apt_keys"
[ -z "${url}" ] && return $FALSE
pause "Press enter to download and import the GPG Key..."
mkdir -pv "$apt_keys"
cd "$apt_keys"
echo "changing directory to $_"
# download keyfile
wget -nc "$url"
local key_file=$(trim_longest_left_pattern "${url}" /)
# get key id
local key_id=$(echo $(gpg --throw-keyids < "$key_file") | cut --characters=11-18 | tr [A-Z] [a-z])
# import key if it doesn't exist
if ! apt-key list | grep "$key_id" > /dev/null 2>&1; then
echo "Installing GPG public key with ID $key_id from $key_file..."
apt-key add "$key_file"
fi
# change directory back to previous one
echo -n "changing directory back to " && cd -
return $TRUE
}
#!/bin/bash
# --------------------------------------------
# A library of useful git functions
#
# Author : Keegan Mullaney
# Company: KM Authorized LLC
# Website: http://kmauthorized.com
#
# MIT: http://kma.mit-license.org
# --------------------------------------------
# set variables
declare -r TRUE=0
declare -r FALSE=1
# purpose: to set global git defaults
# arguments:
# $1 -> code author's name
# $2 -> code author's email
# $3 -> editor to use for git
function configure_git()
{
local name="$1"
local email="$2"
local editor="$3"
local ignore="$HOME/.gitignore_global"
if git config --list | grep -q "${name}"; then
echo "git is already configured."
else
echo
read -p "Press enter to configure git..."
# specify a user
git config --global user.name "${name}"
git config --global user.email "${email}"
# select a text editor
git config --global core.editor "${editor}"
# set default push and pull behavior to the old method
git config --global push.default matching
git config --global pull.default matching
# create a global .gitignore file
echo "# global list of file types to ignore
# from https://gist.githubusercontent.com/octocat/9257657/raw/c91b435be351fcdff00f6f97f20824d0286b99ef/.gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db" > "${ignore}"
git config --global core.excludesfile "${ignore}"
echo "git was configured"
echo
read -p "Press enter to view the config..."
git config --list
fi
}
# purpose: clone repository after fork
# arguments:
# $1 -> GitHub username
# $2 -> name of upstream repository
# $3 -> location of Repos directory
# $4 -> use SSH protocal for git operations? (optional)
function clone_repo()
{
local github_user="$1"
local address="${github_user}/$2.git"
local repos_dir="$3"
local use_ssh=$4
[ -z "${use_ssh}" ] && use_ssh=false
if [ -d "${repos_dir}/${2}" ]; then
echo
echo "${2} directory already exists, skipping clone operation..."
else
echo
echo "*** NOTE ***"
echo "Make sure \"github.com/${address}\" exists."
read -p "Press enter to clone ${address} at GitHub..."
if [ "$use_ssh" = true ]; then
git clone "git@github.com:${address}"
else
git clone "https://github.com/${address}"
fi
fi
# change to newly cloned directory
cd "${2}"
echo "changing directory to $_"
}
# purpose: set remote origin, if not set yet
# arguments:
# $1 -> GitHub username
# $2 -> name of origin repository
# $3 -> set remote upstream or origin (true for upstream)
# $4 -> use SSH protocal for git operations? (optional)
# return: true or false
function set_remote_repo()
{
local github_user="$1"
local address="${github_user}/$2.git"
local set_upstream=$3
local use_ssh=$4
[ -z "${use_ssh}" ] && use_ssh=false
if [ "$set_upstream" = true ] && [ "${github_user}" = 'keegoid' ]; then
echo
echo "upstream doesn't exist for $github_user, skipping..."
return $FALSE
fi
if git config --list | grep -q "${address}"; then
echo
echo "remote repo already configured: ${address}"
else
echo
if [ "$set_upstream" = true ]; then
read -p "Press enter to assign upstream repository..."
if [ "$use_ssh" = true ]; then
git remote add upstream "git@github.com:${address}" && echo "remote upstream added: git@github.com:${address}"
else
git remote add upstream "https://github.com/${address}" && echo "remote upstream added: https://github.com/${address}"
fi
else
echo "*** NOTE ***"
echo "Make sure \"github.com/${address}\" exists."
echo "Either fork and rename it, or create a new repository in your GitHub."
read -p "Press enter to assign remote origin repository..."
if [ "$use_ssh" = true ]; then
git remote add origin "git@github.com:${address}" && echo "remote origin added: git@github.com:${address}"
else
git remote add origin "https://github.com/${address}" && echo "remote origin added: https://github.com/${address}"
fi
fi
fi
return $TRUE
}
# purpose: create a branch for custom changes so master can receive upstream updates
# upstream changes can then be merged with the branch interactively
# arguments:
# $1 -> branch name
function create_branch()
{
local branch_name="$1"
echo
read -p "Press enter to create a git branch for your site at ${branch_name}..."
git checkout -b "${branch_name}"
# some work and some commits happen
# some time passes
#git fetch upstream
#git rebase upstream/master or git rebase interactive upstream/master
echo
read -p "Press enter to push changes and set branch origin in config..."
git push -u origin "${branch_name}"
echo
read -p "Press enter to checkout the master branch again..."
git checkout master
# above could also be done with:
# git branch "${branch_name}"
# git push origin "${branch_name}"
# git branch -u "origin/${branch_name}" "${branch_name}"
echo
echo "*************************************************************************"
echo "* - use ${branch_name} branch to make your own site "
echo "* - use master branch to keep up with changes from the upstream repo "
echo "*************************************************************************"
}
# purpose: commit changes with git
# arguments: none
# return: true or false
#function git_status()
#{
# local commit=$FALSE
# print git status
# echo
# read -p "Press enter to view git status..."
# git status
# commit changes with git
# if git status | egrep -qw "Changes not staged for commit|Changes to be committed"; then
# echo
# echo "*** NOTE ***"
# read -p "Enter a commit message and press enter to commit changes: " msg
# git commit -am "$msg"
# commit=$TRUE
# else
# echo "skipping commit..."
# fi
# return $commit
#}
# purpose: add remote upstream repository, fetch and merge changes
# arguments: none
function merge_upstream()
{
# pull in changes not present in local repository, without modifying local files
echo
read -p "Press enter to fetch changes from upstream repository..."
git fetch upstream && echo "upstream fetch done"
# merge any changes fetched into local working files
echo
echo "*** NOTE ***"
echo "If merging changes, press \":wq enter\" to accept the merge message in vi."
read -p "Press enter to merge changes..."
git merge upstream/master
# or combine fetch and merge with:
#git pull upstream master
}
# purpose: commit and push changes with git
# arguments: none
#function commit_and_push()
#{
# local commit=$FALSE
# commit=$(git_status)
# echo "commit = $commit"
# push commits to your remote repository
# if $commit || git status | grep -qw "Your branch is ahead of"; then
# echo
# read -p "Press enter to push changes to your remote repository (GitHub)..."
# git push origin master
# else
# echo "nothing to push, skipping push..."
# fi
#}
#!/bin/bash
# --------------------------------------------
# A library of functions to set repository
# and software versions, download and
# install repositories and apps
#
# Author : Keegan Mullaney
# Company: KM Authorized LLC
# Website: http://kmauthorized.com
#
# MIT: http://kma.mit-license.org
# --------------------------------------------
# set variables
declare -r TRUE=0
declare -r FALSE=1
# names and versions of repositories/software
SN=( EPEL REMI NGINX OPENSSL ZLIB PCRE FRICKLE RUBY )
SV=( 7-5 7 1.9.9 1.0.2f 1.2.8 8.38 2.3 2.3.0 )
# URLs to check software versions for latest versions
# EPEL dl.fedoraproject.org/pub/epel/7/x86_64/e/
# REMI rpms.famillecollet.com/enterprise/
# NGINX nginx.org/download/
# OPENSSL www.openssl.org/source/
# ZLIB zlib.net/
# PCRE http://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
# FRICKLE https://github.com/FRiCKLE/ngx_cache_purge/
# RUBY www.ruby-lang.org/en/downloads/
# purpose: set software versions
# arguments:
# $1 -> software list (space-separated)
function set_software_versions()
{
local swl="$1"
local version
echo
for ((i=0; i<${#SN[@]}; i++)); do
if echo $swl | grep -qw "${SN[i]}"; then
read -ep "Enter software version for ${SN[i]}: " -i "${SV[i]}" version
SV[i]="$version"
fi
done
}
# version variable assignments (determined by array order)
EPEL_V="${SV[0]}"
REMI_V="${SV[1]}"
NGINX_V="${SV[2]}"
OPENSSL_V="${SV[3]}"
ZLIB_V="${SV[4]}"
PCRE_V="${SV[5]}"
FRICKLE_V="${SV[6]}"
RUBY_V="${SV[7]}"
# software download URLs
EPEL_URL="http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-${EPEL_V}.noarch.rpm"
REMI_URL="http://rpms.famillecollet.com/enterprise/remi-release-${REMI_V}.rpm"
NGINX_URL="http://nginx.org/download/nginx-${NGINX_V}.tar.gz"
OPENSSL_URL="http://www.openssl.org/source/openssl-${OPENSSL_V}.tar.gz"
ZLIB_URL="http://zlib.net/zlib-${ZLIB_V}.tar.gz"
PCRE_URL="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-${PCRE_V}.tar.gz"
FRICKLE_URL="https://github.com/FRiCKLE/ngx_cache_purge/archive/master.zip"
RUBY_URL="https://get.rvm.io"
WORDPRESS_URL="http://wordpress.org/latest.tar.gz"
# GPG public keys
EPEL_KEY="http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-"$(trim_longest_right_pattern "${EPEL_V}" -)
REMI_KEY='http://rpms.famillecollet.com/RPM-GPG-KEY-remi'
# purpose: download and extract software
# arguments:
# $1 -> list of URLs to software (space-separated)
function get_software()
{
local list="$1"
local name
echo
for url in ${list}; do
name="${url##*/}"
read -p "Press enter to download and extract: $name"
wget -nc $url
tar -xzf $name
done
}
# purpose: to install programs from a list
# arguments:
# $1 -> program list (space-separated)
# $2 -> enable-repo (optional)
function install_apt()
{
local names="$1"
local repo="$2"
# install applications in the list
for apt in $names; do
hash "$apt" 2>/dev/null; then
echo "$apt is already installed"
else
echo
read -p "Press enter to install $apt..."
[ -z "${repo}" ] && apt-get -y install "$apt" || { apt-add-repository "${repo}"; apt-get update; apt-get -y install "$apt"; }
fi
done
}
# purpose: to install npm packages from a list
# arguments:
# $1 -> npm list (space-separated)
# $2 -> install globally or into current directory (true for global, optional)
function install_npm()
{
local names="$1"
local global=$2
[ -z "${global}" ] && global=true
# install npm packages in the list
for app in $names; do
if npm ls -gs | grep -qw "$app"; then
echo "npm $app is already installed"
else
echo
read -p "Press enter to install $app..."
[ $global ] && npm install -g "$app" || npm install "$app"
fi
done
}
# purpose: to install ruby and rubygems
# arguments: none
function install_ruby()
{
echo
read -p "Press enter to install ruby and rubygems..."
if ruby -v | grep -q "ruby ${RUBY_V}"; then
echo "ruby is already installed"
else
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
curl -L "$RUBY_URL" | bash -s stable --ruby="${RUBY_V}"
fi
}
# purpose: to source the rvm command
# arguments: none
function source_rvm()
{
echo
read -p "Press enter to start using rvm..."
if grep -q "/usr/local/rvm/scripts/rvm" $HOME/.bashrc; then
echo "already added rvm to .bashrc"
else
echo "source /usr/local/rvm/scripts/rvm" >> $HOME/.bashrc
source /usr/local/rvm/scripts/rvm && echo "rvm sourced and added to .bashrc"
fi
}
# purpose: to install gems from a list
# arguments:
# $1 -> gem list (space-separated)
function install_gem()
{
local names="$1"
# install Ruby and RubyGems
if hash "rubypick" 2>/dev/null; then
echo "rubypick is already installed"
else
echo
read -p "Press enter to install Ruby and RubyGems with rubypick..."
install_apt "rubypick"
fi
# update gem package manager
echo
read -p "Press enter to update the gem package manager..."
gem update --system
# install gems in the list
for app in $names; do
if $(gem list "$app" -i); then
echo "gem $app is already installed"
else
echo
read -p "Press enter to install $app..."
gem install "$app"
fi
done
}
# purpose: to install pips from a list
# arguments:
# $1 -> pip list (space-separated)
function install_pip()
{
local names="$1"
# install Ruby and RubyGems
if hash "pip" 2>/dev/null; then
echo "pip is already installed"
else
echo
read -p "Press enter to install pip..."
install_apt "pip"
fi
# upgrade pip
echo
read -p "Press enter to upgrade pip..."
pip install pip --upgrade
# install pips in the list
for app in $names; do
if [ -n "$(pip list | grep $app)" ]; then
echo "pip $app is already installed"
else
echo
read -p "Press enter to install $app..."
pip install "$app"
fi
done
}
run.sh 0 → 100755
#!/bin/bash
echo "# --------------------------------------------"
echo "# Quickly configures a fresh install of "
echo "# Ubuntu 14.04 x64 for a workstation. "
echo "# "
echo "# Author : Keegan Mullaney "
echo "# Company: KM Authorized LLC "
echo "# Website: http://kmauthorized.com "
echo "# "
echo "# MIT: http://kma.mit-license.org "
echo "# --------------------------------------------"
source vars.sh
# check to make sure script is being run as root
is_root && echo "root user detected, proceeding..." || die "\033[40m\033[1;31mERROR: root check FAILED (you must be root to use this script). Quitting...\033[0m\n"
# source function libraries
for lib in $LIBS; do
[ -d "$LIB_DIR" ] && { source "$LIB_DIR/$lib" > /dev/null 2>&1 && echo "sourced: $LIB_DIR/$lib" || echo "can't find: $LIB_DIR/$lib"; }
done
# make sure curl is installed
hash curl 2>/dev/null || { echo >&2 "curl will be installed."; apt-get -y install curl; }
# create Linux non-root user
echo
pause "Press enter to create user \"$USER_NAME\" if it doesn't exist..."
/usr/sbin/adduser $USER_NAME
# check if user exists
if ! user_exists $USER_NAME; then
die "\033[40m\033[1;31mERROR: $USER_NAME does not exist. Quitting...\033[0m\nQuitting..."
fi
# local repository location
#echo
#REPOS=$(locate_repos $USER_NAME $DROPBOX)
#echo "repository location: $REPOS"
# install software and update system
function updates_go()
{
echo "# -------------------------------"
echo "# SECTION 1: INSTALLS & UPDATES "
echo "# -------------------------------"
# install and update software
run_script linux_update.sh
pause
}
# git
function git_go()
{
echo "# -------------------------------"
echo "# SECTION 2: GIT CONFIG "
echo "# -------------------------------"
# setup git
run_script git_config.sh
pause
}
# ssh
function ssh_go()
{
echo "# -------------------------------"
echo "# SECTION 3: SSH KEY "
echo "# -------------------------------"
# setup git
run_script ssh_key.sh
pause
}
# aliases
function aliases_go()
{
echo "# -------------------------------"
echo "# SECTION 4: ALIASES "
echo "# -------------------------------"
# add useful aliases
run_script aliases.sh
pause
}
# config
function terminal_go()
{
echo "# -------------------------------"
echo "# SECTION 5: TERMINAL CONFIG "
echo "# -------------------------------"
# setup the terminal
run_script terminal_config.sh
pause
}
# display the menu
display_menu()
{
clear
echo "~~~~~~~~~~~~~~~~~~~~~~~"
echo " M A I N - M E N U "
echo "~~~~~~~~~~~~~~~~~~~~~~~"
echo "1. INSTALLS & UPDATES"
echo "2. GIT CONFIG"
echo "3. SSH KEY"
echo "4. ALIASES"
echo "5. TERMINAL CONFIG"
echo "6. EXIT"
}
# user selection
select_options()
{
local choice
read -p "Enter choice [1 - 6]: " choice
case $choice in
1) updates_go;;
2) git_go;;
3) ssh_go;;
4) aliases_go;;
5) terminal_go;;
6) exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 2
esac
}
# ----------------------------------------------
# trap CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
#trap '' SIGINT SIGQUIT SIGTSTP
# -----------------------------------
# main loop (infinite)
# ------------------------------------
while true; do
display_menu
select_options
done
# set ownership
echo
#chown -cR $USER_NAME:$USER_NAME "$REPOS"
chown -cR $USER_NAME:$USER_NAME "$WORKING_DIR"
echo
echo "# --------------------------------------------------------------------"
echo "# Execute sudo ./sudoers.sh to increase the sudo timeout. "
echo "# --------------------------------------------------------------------"
echo
echo "Thanks for using the ubuntu-workstation-setup script."
#!/bin/bash
echo "# --------------------------------------------"
echo "# Add some useful shell aliases. "
echo "# "
echo "# Author : Keegan Mullaney "
echo "# Company: KM Authorized LLC "
echo "# Website: http://kmauthorized.com "
echo "# "
echo "# MIT: http://kma.mit-license.org "
echo "# --------------------------------------------"
# check if user exists
pause "Press enter to check if user $USER_NAME exists"
if user_exists $USER_NAME; then
# append aliases to .bashrc if not done already
pause "Press enter to add useful aliases for $USER_NAME..."
if grep -q "alias wget" /home/$USER_NAME/.bashrc; then
echo "already added aliases for $USER_NAME..."
else
# alias useful shell commands
cat << 'EOF' >> /home/$USER_NAME/.bashrc
# add color
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
# make directories and parents
alias mkdir='mkdir -pv'
# list open ports
alias ports='netstat -tulanp'
# shortcut for firewall-cmd in CentOS 7
alias fctl='firewall-cmd'
# shortcut for systemctl in CentOS 7
alias sctl='systemctl'
# display headers
alias header='curl -I'
# display headers that support compression
alias headerc='curl -I --compress'
# delete protection
alias rm='rm -I --preserve-root'
# confirm operation
alias mv='mv -i'
alias cp='cp -i'
alias ln='ln -i'
# become root
alias su='/bin/su'
# reboot and shutdown
alias reboot='sudo /sbin/reboot'
alias shutdown='sudo /sbin/shutdown'
# list memory info
alias meminfo='free -m -l -t'
# nginx test
alias nginxtest='sudo /usr/local/nginx/sbin/nginx -t'
# OS version
alias osversion='cat /etc/*release*'
# resume downloads
alias wget='wget -c'
# print aliases
alias aliases="cat /home/$USER_NAME/.bashrc"
EOF
echo "/home/$USER_NAME/.bashrc was updated"
else
echo "error: $USER_NAME does not exist, skipping .bashrc file"
fi
echo
script_name " done with "
echo "*********************************************"
#!/bin/bash
echo "# --------------------------------------------"
echo "# Configure git for $USER_NAME. "
echo "# "
echo "# Author : Keegan Mullaney "
echo "# Company: KM Authorized LLC "
echo "# Website: http://kmauthorized.com "
echo "# "
echo "# MIT: http://kma.mit-license.org "
echo "# --------------------------------------------"
# configure git
configure_git "$REAL_NAME" "$EMAIL_ADDRESS" "$GIT_EDITOR"
echo
script_name " done with "
echo "*********************************************"
#!/bin/bash
echo "# --------------------------------------------"
echo "# Install and update programs. "
echo "# "
echo "# Author : Keegan Mullaney "
echo "# Company: KM Authorized LLC "
echo "# Website: http://kmauthorized.com "
echo "# "
echo "# MIT: http://kma.mit-license.org "
echo "# --------------------------------------------"
# update programs maintained by the package manager
pause "Press enter to update Linux..."
apt-get -y install upgrade
# install programs with apt-get
install_apt "$APT_PROGRAMS"
# install gems
install_gem "$GEM_PROGRAMS"
# install pips
install_pip "$PIP_PROGRAMS"
# install npms
install_npm "$NPM_PROGRAMS" true
# install keybase
pause "Press enter to run the keybase installer..."
keybase-installer
pause "Press enter to test the keybase command..."
keybase version
if $DROPBOX; then
echo
echo "To install Dropbox, please do so manually at: "
echo "https://www.dropbox.com/install?os=lnx"
fi
echo
script_name " done with "
echo "*********************************************"
#!/bin/bash
echo "# --------------------------------------------"
echo "# Generate an SSH key pair. "
echo "# "
echo "# Author : Keegan Mullaney "
echo "# Company: KM Authorized LLC "
echo "# Website: http://kmauthorized.com "
echo "# "
echo "# MIT: http://kma.mit-license.org "
echo "# --------------------------------------------"
# generate an RSA SSH keypair if none exists
gen_ssh_keys "/home/$USER_NAME/.ssh" "$SSH_KEY_COMMENT" $SSH $USER_NAME
echo
script_name " done with "
echo "*********************************************"
#!/bin/bash
echo "# --------------------------------------------"
echo "# Configure some terminal settings. "
echo "# "
echo "# Author : Keegan Mullaney "
echo "# Company: KM Authorized LLC "
echo "# Website: http://kmauthorized.com "
echo "# "
echo "# MIT: http://kma.mit-license.org "
echo "# --------------------------------------------"
# color terminal prompts
if grep -q "#force_color_prompt=yes" /home/$USER_NAME/.bashrc; then
echo "adding color to terminal prompts"
sed -i.bak -e "s/#force_color_prompt=yes/force_color_prompt=yes/"
else
echo "already set color prompts for $USER_NAME..."
fi
# terminal history lookup
pause "Press enter to add terminal history lookup for $USER_NAME..."
if grep -q "backward-char" /home/$USER_NAME/.inputrc; then
echo "already added terminal history lookup for $USER_NAME..."
else
# terminal input config file
cat << 'EOF' >> /home/$USER_NAME/.inputrc
# shell command history lookup by matching string
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
EOF
echo "/home/$USER_NAME/.inputrc was created with:"
cat "/home/$USER_NAME/.inputrc"
# proxy for terminal traffic
PROXY=false
echo
echo "Do you wish to use a proxy for terminal operations?"
select yn in "Yes" "No"; do
case $yn in
"Yes") PROXY=true;;
"No") break;;
*) echo "case not found, try again..."
continue;;
esac
break
done
if [ "$PROXY" = true ]; then
# set proxy address and port in .bashrc
if grep -q "http_proxy" /home/$USER_NAME/.bashrc; then
echo "already set proxy for $USER_NAME..."
else
# check if trying to use lantern proxy without lantern installed
if [ -n "$(hash lantern)" ] && [ "$PROXY_ADDRESS" = '127.0.0.1:8787' ]; then
echo "error: Lantern is not installed, skipping proxy..."
echo "download Lantern from getlantern.org and run this script again"
else
echo "setting http_proxy var"
echo "http_proxy=http://\'$PROXY_ADDRESS\'" >> /home/$USER_NAME/.bashrc
fi
fi
else
echo
echo "skipping proxy..."
fi
echo
script_name " done with "
echo "*********************************************"
#!/bin/bash
# configure sudoers file
# chmod +x sudoers.sh
# run with sudo ./sudoers.sh
if [ -z "$1" ]; then
echo "Starting up visudo with this script as first parameter"
export EDITOR=$0 && /usr/sbin/visudo
else
egrep -qi "timestamp_timeout=120" $1
if [ $? -eq 0 ]; then
echo "sudoers already updated"
else
echo "setting sudo timeout to 120 minutes"
sed -i.bak -e "s/mail_badpass/mail_badpass, timestamp_timeout=120/" $1
fi
fi
vars.sh 0 → 100755
#!/bin/bash
echo "# --------------------------------------------"
echo "# Set global variables for run.sh script. "
echo "# "
echo "# Author : Keegan Mullaney "
echo "# Company: KM Authorized LLC "
echo "# Website: http://kmauthorized.com "
echo "# "
echo "# MIT: http://kma.mit-license.org "
echo "# --------------------------------------------"
# --------------------------------------------------
# EDIT THESE VARIABLES WITH YOUR INFO
USER_NAME='kmullaney' # your Linux user
REAL_NAME='Keegan Mullaney'
EMAIL_ADDRESS='keegan@kmauthorized.com'
SSH_KEY_COMMENT='coding key'
GITHUB_USER='keegoid' # your GitHub username
GIT_EDITOR='nano'
PROXY_ADDRESS='127.0.0.1:8787' # default uses Lantern, make sure it is installed first
# programs to install
WORKSTATION_PROGRAMS='deluge git gnupg2 gufw lynx nautilus-open-terminal npm pip python-gpgme xclip vagrant virtualbox virtualbox-guest-additions-iso vlc'
# gems to install
GEM_PROGRAMS='gist'
# pips to install
PIP_PROGRAMS='jrnl[encrypted]'
# npms to install
NPM_PROGRAMS='doctoc keybase-installer'
# what to allow from the Internet
SERVICES=''
TCP_PORTS=''
UDP_PORTS=''
# whitelisted IPs
TRUSTED_IPV4_HOSTS=""
TRUSTED_IPV6_HOSTS=""
# --------------------------------------------------
# for screen error messages
RED='\033[0;41;30m'
STD='\033[0;0;39m'
# library files
LIBS='base.lib software.lib git.lib'
LIBS_DIR='includes'
# save current directory
WORKING_DIR="$PWD"
# use Dropbox for Repos directory?
#DROPBOX=false
#echo
#echo "Are you using Dropbox for your repositories?"
#select yn in "Yes" "No"; do
# case $yn in
# "Yes") DROPBOX=true;;
# "No") break;;
# *) echo "case not found..."
# continue;;
# esac
# break
#done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment