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

bug fixes for linux_update.sh

 On branch master

 Changes to be committed:
	modified:   README.md
	modified:   includes/base.lib
	modified:   includes/software.lib
	modified:   run.sh
	modified:   scripts/linux_update.sh
        modified:   scripts/ssh_key.sh
	modified:   scripts/terminal_config.sh
	modified:   vars.sh
parent 3557727b
No related branches found
No related tags found
No related merge requests found
ubuntu-workstation-setup
========================
ubuntu-quick-config
===================
 
Quickly configures a fresh install of [Ubuntu 14.04 x64][ubuntu] for a workstation.
Quickly configures a fresh install of [Ubuntu 14.04 x64][ubuntu].
 
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Loading
Loading
@@ -11,30 +11,35 @@ Quickly configures a fresh install of [Ubuntu 14.04 x64][ubuntu] for a workstati
## What it can do
 
- update [Ubuntu][ubuntu] and install useful programs
- configure [git][git] for pushing and pulling with [GitHub][gh]
- configure [git][git] global settings
- generate an [RSA key][sshkey] for remote [SSH sessions][ssh] (this is not a [GPG key][gpgkey])
- add some [shell aliases][sa]
- configure some [terminal][lc] settings
- add useful [shell aliases][sa]
- make the [terminal][lc] easier to read and use
 
## Usage
 
### Clone or download this project
 
- HTTPS: `git clone https://github.com/keegoid/ubuntu-workstation-setup.git`
- SSH: `git clone git@github.com:keegoid/ubuntu-workstation-setup.git`
- HTTPS: `git clone https://github.com/keegoid/ubuntu-quick-config.git`
- SSH: `git clone git@github.com:keegoid/ubuntu-quick-config.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
### Run it
Run the main program with `./run.sh`
If it doesn't work, you might need to do this:
 
```bash
sudo chmod +x run.sh
sudo dos2unix -k run.sh
sudo ./run.sh
chmod +x run.sh
dos2unix -k run.sh
```
 
Also run `./sudoers.sh` if you want to increase the sudo timeout which is set to 15 minutes by default.
## 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.
Loading
Loading
Loading
Loading
@@ -130,11 +130,11 @@ function run_script()
local project_dir="$PWD"
# reset back to root poject directory to run scripts
cd "$project_dir/scripts"
echo "changing directory to $_"
# echo "changing directory to $_"
# make sure dos2unix is installed
[ -z "$(apt-cache policy dos2unix | grep '(none)')" ] || { echo >&2 "dos2unix will be installed."; sudo apt-get -y install dos2unix; }
dos2unix -k ${script} && echo "carriage returns removed"
chmod +x ${script} && echo "execute permissions set"
dpkg-query -W dos2unix >/dev/null 2>&1 || { echo >&2 "dos2unix will be installed."; sudo apt-get -y install dos2unix; }
dos2unix -k -q ${script}
chmod +x ${script}
# sudo chown $(logname):$(logname) ${script} && echo "owner set to $(logname)"
read -p "Press enter to run: ${script}"
. ./${script}
Loading
Loading
@@ -191,8 +191,6 @@ function gen_ssh_keys()
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
Loading
Loading
Loading
Loading
@@ -97,7 +97,7 @@ function install_apt()
local repo="$2"
# install applications in the list
for apt in $names; do
if [ -z "$(apt-cache policy $apt | grep '(none)')" ]; then
if dpkg-query -W "$apt" >/dev/null 2>&1; then
echo "$apt is already installed"
else
echo
Loading
Loading
@@ -118,14 +118,16 @@ function install_npm()
[ -z "${global}" ] && global=true
# make sure npm is installed
install_apt "npm"
# 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"
echo "$app is already installed"
else
echo
read -p "Press enter to install $app..."
[ $global ] && npm install -g "$app" || npm install "$app"
[ $global ] && sudo npm install -g "$app" || sudo npm install "$app"
fi
done
}
Loading
Loading
@@ -164,22 +166,12 @@ function source_rvm()
function install_gem()
{
local names="$1"
# install Ruby and RubyGems
if [ -z "$(apt-cache policy rubypick | grep '(none)')" ]; 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
# make sure ruby and rubygems are installed
install_apt "ruby rubygems"
# install gems in the list
for app in $names; do
if $(gem list "$app" -i); then
echo "gem $app is already installed"
echo "$app is already installed"
else
echo
read -p "Press enter to install $app..."
Loading
Loading
@@ -194,27 +186,27 @@ function install_gem()
function install_pip()
{
local names="$1"
# install Ruby and RubyGems
if [ -z "$(apt-cache policy pip | grep '(none)')" ]; 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
# make sure python-pip and python-gpgme are installed
install_apt "python-pip python-gpgme"
# install pips in the list
for app in $names; do
if [ -n "$(pip list | grep $app)" ]; then
echo "pip $app is already installed"
app=$(trim_longest_right_pattern "$app" "[")
if pip list | grep "$app" >/dev/null 2>&1; then
echo "$app is already installed"
else
echo
read -p "Press enter to install $app..."
pip install "$app"
sudo pip install "$app"
fi
done
}
 
# purpose: to install keybase
function install_keybase()
{
# change to Downloads directory to download file and then back to original directory
cd /tmp
curl -O https://dist.keybase.io/linux/deb/keybase-latest-amd64.deb && sudo dpkg -i keybase-latest-amd64.deb
cd -
}
#!/bin/bash
echo "# --------------------------------------------"
echo "# Quickly configures a fresh install of "
echo "# Ubuntu 14.04 x64 for a workstation. "
echo "# Ubuntu 14.04 x64. "
echo "# "
echo "# Author : Keegan Mullaney "
echo "# Website: http://keegoid.com "
Loading
Loading
@@ -97,7 +97,7 @@ function finish_up()
echo "# Lastly: execute sudo ./sudoers.sh to increase the sudo timeout. "
echo "# --------------------------------------------------------------------"
echo
echo "Thanks for using the ubuntu-workstation-setup script."
echo "Thanks for using this ubuntu-quick-config script."
echo
}
 
Loading
Loading
Loading
Loading
@@ -10,14 +10,21 @@ echo "# http://keegoid.mit-license.org "
echo "# --------------------------------------------"
 
# update programs maintained by the package manager
pause "Press enter to update Linux..."
sudo apt-get -y install upgrade
#pause "Press enter to update Ubuntu sources..."
#sudo apt-get -y update
pause "Press enter to upgrade programs..."
sudo apt-get -y upgrade
 
# install programs with apt-get
install_apt "$APT_PROGRAMS"
install_apt "$WORKSTATION_PROGRAMS"
# install programs with apt-get
if [ "$IS_SERVER" = true ]; then
install_apt "$SERVER_PROGRAMS"
fi
 
# install gems
install_gem "$GEM_PROGRAMS"
#install_gem "$GEM_PROGRAMS"
 
# install pips
install_pip "$PIP_PROGRAMS"
Loading
Loading
@@ -26,9 +33,8 @@ install_pip "$PIP_PROGRAMS"
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..."
pause "Press enter to install keybase..."
install_keybase
keybase version
 
#if $DROPBOX; then
Loading
Loading
Loading
Loading
@@ -15,6 +15,60 @@ if [ "$(user_exists $USER_NAME)" = false ]; then
sudo /usr/sbin/adduser $USER_NAME
fi
 
# generate an RSA SSH keypair if none exists
gen_ssh_keys "/home/$USER_NAME/.ssh" "$SSH_KEY_COMMENT" true $USER_NAME
if [ "$IS_SERVER" = true ]; then
# make a copy of the original sshd config file
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.original
# protect it from writing
sudo chmod a-w /etc/ssh/sshd_config.original
# client allive interval
CLIENT_ALIVE=60
SSH_PORT=22
read -ep "Enter the client alive interval in seconds to prevent SSH from dropping out: " -i "60" CLIENT_ALIVE
read -ep "Enter the ssh port number to use on the server: " -i "22" SSH_PORT
# edit /etc/ssh/sshd_config
echo
pause "Press enter to configure sshd service..."
sudo sed -i.bak -e "{
s|#Port 22|Port $SSH_PORT|
s|#ClientAliveInterval 0|ClientAliveInterval $CLIENT_ALIVE|
}" /etc/ssh/sshd_config
echo
echo -e "SSH port set to $SSH_PORT\nclient alive interval set to $CLIENT_ALIVE"
# add public SSH key for new ssh user
SSH_DIRECTORY="/home/$USER_NAME/.ssh"
# generate SSH keypair
# gen_ssh_keys $SSH_DIRECTORY "$SSH_COMMENT" true $USER_NAME
# add authorized key for ssh user
authorized_ssh_keys $SSH_DIRECTORY $USER_NAME
# use ufw to limit login attempts too
echo
pause "Press enter to configure ufw to limit ssh connection attempts..."
sudo ufw limit ssh
# disable root user access and limit login attempts
echo
pause "Press enter to configure sshd security settings..."
sudo sed -i -e "s|#PermitRootLogin yes|PermitRootLogin no|" \
-e "s|PasswordAuthentication yes|PasswordAuthentication no|" \
-e "s|#MaxStartups 10:30:60|MaxStartups 2:30:10|" \
-e "s|#Banner /etc/issue.net|Banner /etc/issue.net|" /etc/ssh/sshd_config
if grep -q "AllowUsers $USER_NAME" /etc/ssh/sshd_config; then
echo "AllowUsers is already configured"
else
sudo printf "\nAllowUsers $USER_NAME" >> /etc/ssh/sshd_config && echo -e "\nroot login disallowed"
fi
echo
pause "Press enter to restart the ssh service..."
sudo service ssh restart
else
# generate an RSA SSH keypair if none exists
gen_ssh_keys "/home/$USER_NAME/.ssh" "$SSH_KEY_COMMENT" true $USER_NAME
fi
 
Loading
Loading
@@ -25,7 +25,7 @@ fi
 
# terminal history lookup
pause "Press enter to add terminal history lookup for $USER_NAME..."
[ -e /home/$USER_NAME/.inputrc ] || cat "" > /home/$USER_NAME/.inputrc
[ -e /home/$USER_NAME/.inputrc ] || printf "" > /home/$USER_NAME/.inputrc
if grep -q "backward-char" /home/$USER_NAME/.inputrc; then
echo "already added terminal history lookup for $USER_NAME..."
else
Loading
Loading
@@ -43,35 +43,39 @@ fi
 
# 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
#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
if grep -q "http_proxy" /etc/environment; then
echo "already set proxy for $USER_NAME..."
else
# check if trying to use lantern proxy without lantern installed
if [ -n "$(apt-cache policy lantern | grep '(none)')" ] && [ "$PROXY_ADDRESS" = '127.0.0.1:8787' ]; then
if ! dpkg-query -W lantern >/dev/null 2>&1 && [ "$PROXY_ADDRESS" = 'http://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 to: http://$PROXY_ADDRESS"
echo "setting http_proxy var to: $PROXY_ADDRESS"
echo "" >> /home/$USER_NAME/.bashrc
echo "# proxy for terminal (set by $USER_NAME)" >> /home/$USER_NAME/.bashrc
echo "http_proxy=\"http://$PROXY_ADDRESS\"" >> /home/$USER_NAME/.bashrc
echo "http_proxy=$PROXY_ADDRESS" >> /home/$USER_NAME/.bashrc
echo "http_proxy=$PROXY_ADDRESS" | sudo tee --append /etc/environment > /dev/null
echo "Acquire::http::proxy $PROXY_ADDRESS;" | sudo tee /etc/apt/apt.conf > /dev/null
echo "" | sudo tee /etc/apt/apt.conf > /dev/null
fi
fi
else
echo
echo "skipping proxy..."
# echo
# echo "skipping proxy..."
fi
 
Loading
Loading
@@ -17,11 +17,13 @@ EMAIL_ADDRESS='keegan@kmauthorized.com'
SSH_KEY_COMMENT='coding key'
GITHUB_USER='keegoid' # your GitHub username
GIT_EDITOR='vi'
PROXY_ADDRESS='127.0.0.1:8787' # default uses Lantern, make sure it is installed first
APT_PROGRAMS='deluge git gnupg2 gufw lynx nautilus-open-terminal npm pip python-gpgme xclip vagrant virtualbox virtualbox-guest-additions-iso vlc' # apts to install
GEM_PROGRAMS='gist' # gems to install
PIP_PROGRAMS='jrnl[encrypted]' # pips to install
NPM_PROGRAMS='doctoc keybase-installer' # npms to install
#PROXY_ADDRESS='http://127.0.0.1:8787' # default uses Lantern
# programs to be installed
WORKSTATION_PROGRAMS='deluge gist git gnupg2 gufw lynx nautilus-open-terminal xclip vagrant vim virtualbox virtualbox-guest-additions-iso vlc'
SERVER_PROGRAMS='openssh-server'
#GEM_PROGRAMS='gist'
PIP_PROGRAMS='jrnl[encrypted]'
NPM_PROGRAMS='doctoc'
# --------------------------------------------
 
# for screen error messages
Loading
Loading
@@ -35,6 +37,20 @@ LIBS_DIR='includes'
# save current directory
WORKING_DIR="$PWD"
 
# config for server
IS_SERVER=false
echo
echo "Is this a server?"
select yn in "Yes" "No"; do
case $yn in
"Yes") IS_SERVER=true;;
"No") break;;
*) echo "case not found, try again..."
continue;;
esac
break
done
# use Dropbox for Repos directory?
#DROPBOX=false
#echo
Loading
Loading
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