-
-
Save rjoydip-zz/cfa5186a24f4126036ad1293161a0507 to your computer and use it in GitHub Desktop.
Ubuntu post installation script that setup a development environment using dialogs
This file contains hidden or 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
#!/usr/bin/bash | |
failure() { | |
printf "\n%s\n" "" | |
exit 2 | |
} | |
#*********************************** | |
# CREATE TEMPORARY FOLDER | |
#*********************************** | |
init_temp_dir() { | |
cd ~ || exit | |
POST_INSTALL_TMP="./post_install_tmp" | |
if [ $POST_INSTALL_TMP ]; then | |
echo "Erasing existing post_install_tmp dir..." | |
rm -rf ./post_install_tmp | |
fi | |
mkdir ./post_install_tmp | |
cd post_install_tmp || exit | |
} | |
#******************************* | |
# GET SECURITY UPDATES | |
#******************************* | |
update_packages() { | |
sudo apt-get update -y | |
sudo apt-get upgrade -y | |
} | |
#****************************************** | |
# ESSENTIAL (NON-DEVELOPPER) TOOLS | |
#****************************************** | |
install_mandatories() { | |
# [synaptic]: User-friendly package manager | |
$APTGETCMD -y install synaptic firefox wget ssh samba \ && | |
build-essential checkinstall libreadline-gplv2-dev \ && | |
libncursesw5-dev libssl-dev libsqlite3-dev tk-dev \ && | |
libgdbm-dev libc6-dev libbz2-dev libffi-dev -y | |
} | |
#********************************** | |
# SOURCE CONTROL MANAGERS | |
#********************************** | |
install_scm() { | |
for i in "${SCM_PKG[@]}"; do | |
case $i in | |
"subversion") | |
$APTGETCMD -y install subversion;; | |
"cvs") | |
$APTGETCMD -y install cvs;; | |
"mercurial") | |
$APTGETCMD -y install mercurial;; | |
"git") | |
$APTGETCMD -y install git git-gui gitk;; | |
esac | |
done | |
} | |
#******************** | |
# DATABASES | |
#******************** | |
install_dbms() { | |
for i in "${DBMS_PKG[@]}"; do | |
case $i in | |
"mysql") | |
$APTGETCMD -y install mysql-server mysql-client mysql-admin;; | |
"postgresql") | |
$APTGETCMD -y install postgresql postgresql-client pgadmin3;; | |
"sqlite3") | |
$APTGETCMD -y install sqlite3;; | |
esac | |
done | |
#On a developer workstation, db servers should be started only when needed (Optional) | |
#update-rc.d -f mysql remove | |
#update-rc.d -f mysql-ndb remove | |
#update-rc.d -f mysql-ndb-mgm remove | |
#update-rc.d -f postgresql-8.2 remove | |
} | |
#**************** | |
# C/C++ | |
#**************** | |
install_cppenv() { | |
$APTGETCMD -y install \ && | |
autoconf automake build-essential libtool linux-source linux-headers-"$(uname -r)" \ && | |
distcc ccache distccmon-gnome valgrind libxmlrpc++-dev libwxgtk2.8-0 libwxgtk2.8-dev \ && | |
libwxgtk2.8-dbg wx2.8-doc wx2.8-examples wx2.8-i18n wx-common openmpi-bin \ && | |
openmpi-common openmpi-dbg openmpi-dev openmpi-libs0 swig | |
$APTGETCMD -y libboost.*-dev libboost-doc libboost.*1.34.1 | |
} | |
#**************** | |
# golang | |
#**************** | |
install_golang() { | |
VERSION="1.14" | |
[ -z "$GOROOT" ] && GOROOT="$HOME/.go" | |
[ -z "$GOPATH" ] && GOPATH="$HOME/go" | |
OS="$(uname -s)" | |
ARCH="$(uname -m)" | |
case $OS in | |
"Linux") | |
case $ARCH in | |
"x86_64") | |
ARCH=amd64 | |
;; | |
"aarch64") | |
ARCH=arm64 | |
;; | |
"armv6") | |
ARCH=armv6l | |
;; | |
"armv8") | |
ARCH=arm64 | |
;; | |
.*386.*) | |
ARCH=386 | |
;; | |
esac | |
PLATFORM="linux-$ARCH" | |
;; | |
"Darwin") | |
PLATFORM="darwin-amd64" | |
;; | |
esac | |
print_help() { | |
echo "Usage: bash goinstall.sh OPTIONS" | |
echo -e "\nOPTIONS:" | |
echo -e " --remove\tRemove currently installed version" | |
echo -e " --version\tSpecify a version number to install" | |
} | |
if [ -n "$($SHELL -c "echo $ZSH_VERSION")" ]; then | |
shell_profile="zshrc" | |
elif [ -n "$($SHELL -c "echo $BASH_VERSION")" ]; then | |
shell_profile="bashrc" | |
fi | |
if [ "$1" == "--remove" ]; then | |
rm -rf "$GOROOT" | |
if [ "$OS" == "Darwin" ]; then | |
sed -i "" "/# GoLang/d" "$HOME/.${shell_profile}" | |
sed -i "" "/export GOROOT/d" "$HOME/.${shell_profile}" | |
sed -i "" "/$GOROOT\/bin/d" "$HOME/.${shell_profile}" | |
sed -i "" "/export GOPATH/d" "$HOME/.${shell_profile}" | |
sed -i "" "/$GOPATH\/bin/d" "$HOME/.${shell_profile}" | |
else | |
sed -i "/# GoLang/d" "$HOME/.${shell_profile}" | |
sed -i "/export GOROOT/d" "$HOME/.${shell_profile}" | |
sed -i "/$GOROOT\/bin/d" "$HOME/.${shell_profile}" | |
sed -i "/export GOPATH/d" "$HOME/.${shell_profile}" | |
sed -i "/$GOPATH\/bin/d" "$HOME/.${shell_profile}" | |
fi | |
echo "Go removed." | |
exit 0 | |
elif [ "$1" == "--help" ]; then | |
print_help | |
exit 0 | |
elif [ "$1" == "--version" ]; then | |
if [ -z "$2" ]; then # Check if --version has a second positional parameter | |
echo "Please provide a version number for: $1" | |
else | |
VERSION=$2 | |
fi | |
elif [ -n "$1" ]; then | |
echo "Unrecognized option: $1" | |
exit 1 | |
fi | |
if [ -d "$GOROOT" ]; then | |
echo "The Go install directory ($GOROOT) already exists. Exiting." | |
exit 1 | |
fi | |
PACKAGE_NAME="go$VERSION.$PLATFORM.tar.gz" | |
TEMP_DIRECTORY=$(mktemp -d) | |
echo "Downloading $PACKAGE_NAME ..." | |
if hash wget 2>/dev/null; then | |
wget https://storage.googleapis.com/golang/"$PACKAGE_NAME" -O "$TEMP_DIRECTORY/go.tar.gz" | |
else | |
curl -o "$TEMP_DIRECTORY/go.tar.gz" https://storage.googleapis.com/golang/"$PACKAGE_NAME" | |
fi | |
if ! $? | |
then | |
echo "Download failed! Exiting." | |
exit 1 | |
fi | |
echo "Extracting File..." | |
mkdir -p "$GOROOT" | |
tar -C "$GOROOT" --strip-components=1 -xzf "$TEMP_DIRECTORY/go.tar.gz" | |
touch "$HOME/.${shell_profile}" | |
{ | |
echo "# GoLang" | |
echo "export GOROOT=${GOROOT}" | |
echo "export PATH=$GOROOT/bin:$PATH" | |
echo "export GOPATH=$GOPATH" | |
echo "export PATH=$GOPATH/bin:$PATH" | |
} >> "$HOME/.${shell_profile}" | |
mkdir -p "$GOPATH"/{src,pkg,bin} | |
echo -e "\nGo $VERSION was installed into $GOROOT.\nMake sure to relogin into your shell or run:" | |
echo -e "\n\tsource $HOME/.${shell_profile}\n\nto update your environment variables." | |
echo "Tip: Opening a new terminal window usually just works. :)" | |
rm -f "$TEMP_DIRECTORY/go.tar.gz" | |
} | |
#***************** | |
# python | |
#***************** | |
install_python() { | |
VERSION="2.7.15" | |
mkdir python_installation && cd python_installation || exit | |
wget https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tgz | |
tar xzvf Python-$VERSION.tgz | |
rm -f Python-$VERSION.tgz | |
cd Python-$VERSION || exit | |
./configure --enable-optimizations | |
make -j 4 | |
make altinstall | |
cd ../.. | |
rm -rf python_installation | |
python$VERSION -m pip install -U pip | |
echo alias pip2="python$VERSION -m pip" >> ~/.bashrc | |
} | |
#************************** | |
# node through nvm | |
#************************** | |
install_node() { | |
VERSION="0.35.3" | |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$VERSION/install.sh | bash | |
if [ -d "$HOME/.nvm" ]; then | |
# export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" | |
export NVM_DIR="$HOME/.nvm" | |
# This loads nvm | |
[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" | |
# This loads nvm bash_completion | |
[ -s "$NVM_DIR/bash_completion" ] && \\. "$NVM_DIR/bash_completion" | |
fi | |
source ~/.bashrc | |
command -v nvm | |
} | |
#******************* | |
# rust | |
#******************* | |
install_rust() { | |
curl https://sh.rustup.rs -sSf | bash | |
source ~/.profile | |
source ~/.cargo/env | |
rustc --version | |
} | |
#******************* | |
# vscode | |
#******************* | |
install_vscode() { | |
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg \ && | |
install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/ \ && | |
sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list' \ && | |
apt-get install -y apt-transport-https code # or code-insiders | |
} | |
#********************* | |
# MATH TOOLS | |
#********************* | |
install_mathtools() { | |
for i in "${MATHTOOLS_PKG[@]}"; do | |
case $i in | |
"scilab") | |
$APTGETCMD -y install scilab;; | |
"octave") | |
$APTGETCMD -y install octave;; | |
"gnuplot") | |
$APTGETCMD -y install gnuplot;; | |
esac | |
done | |
} | |
#******************************** | |
# MISC DEVELOPMENT TOOLS | |
#******************************** | |
install_misctools() { | |
#Prepare Konsole Desktop icon | |
cat >> ~/post_install_tmp/Konsole.desktop << "EOF" | |
[Desktop Entry] | |
Encoding=UTF-8 | |
Exec='konsole' | |
GenericName=Konsole | |
Name=Konsole | |
StartupNotify=true | |
Terminal=false | |
Type=Application | |
X-KDE-SubstituteUID=true | |
EOF | |
for i in "${MISCTOOLS_PKG[@]}"; do | |
case $i in | |
"umbrello") | |
$APTGETCMD -y install umbrello;; | |
"geany") | |
$APTGETCMD -y install geany;; | |
"scons") | |
$APTGETCMD -y install scons;; | |
"konsole") | |
$APTGETCMD -y install konsole | |
mv ~/post_install_tmp/Konsole.desktop ~/Desktop/;; | |
"xclip") | |
$APTGETCMD -y install xclip;; | |
esac | |
done | |
} | |
#******************************* | |
# CLEAN TEMPORARY FOLDER | |
#******************************* | |
cleanup() { | |
rm -rf ~/post_install_tmp | |
if [ -a ~/.bash_profile ]; then | |
source ~/.bash_profile | |
fi | |
} | |
#********************** | |
# DISPLAY HELP | |
#********************** | |
show_usage() { | |
echo "Usage: $APPNAME [options]" | |
echo " $APPNAME [-l LOCAL_DEPOT]" | |
echo "" | |
echo "$APPNAME is a shell script that setup a development environment" | |
echo "for Ubuntu and its derivatives (Kubuntu, Xubuntu, etc.) By default," | |
echo "it uses a GUI dialog, specify the -n option to force console dialogs." | |
echo "" | |
echo "Options:" | |
echo " -h This help text" | |
echo " -q Quiet mode - Less verbose than normal mode" | |
echo " -s No-act. Perform ordering simulation" | |
echo " -v Show version numbers" | |
echo " -l Install using local packages only. Depot location is provided as an argument" | |
} | |
#***************************************************************************** | |
# SET SOME DEFAULT APT-GET OPTIONS ACCORDING TO COMMANDLINE SWITCHES | |
#***************************************************************************** | |
init_aptget_options() { | |
SIM_OPT= | |
QUIET_OPT= | |
if [ "$SIM_MODE" = y ] | |
then | |
SIM_OPT="-s" | |
fi | |
if [ "$QUIET_MODE" = y ] | |
then | |
QUIET_OPT="-q" | |
fi | |
if ! [ "$(id -u)" = 0 ]; then | |
echo "The script need to be run as root." >&2 | |
exit 1 | |
fi | |
APTGETCMD=apt-get $QUIET_OPT $SIM_OPT | |
} | |
show_version() { | |
echo "$VERSION" | |
} | |
show_welcome_msg() { | |
printf "\n%s\n" "$APPNAME is a shell script that setup a development environment \ | |
for Ubuntu and its derivatives (Kubuntu, Xubuntu, etc.) In the next windows, \ | |
you will have to choose the applications you want installed in your environment." "" | |
} | |
get_packages() { | |
#Get SCM list | |
SCM_PKG="echo git" # subversion cvs mercurial git | |
#Get DBMS List | |
DBMS_PKG="echo mysql postgresql sqlite3" # mysql postgresql sqlite3 | |
#Get Math tools choices | |
MATHTOOLS_PKG="echo scilab octave gnuplot" # scilab octave gnuplot | |
#Get Miscallenous tools choices | |
MISCTOOLS_PKG="" # umbrello geany scons konsole xclip | |
case $? in | |
0) | |
CPPENV_PKG="cpp";; | |
1) | |
CPPENV_PKG="";; | |
esac | |
} | |
#*********************** | |
# MAIN PROGRAM | |
#*********************** | |
#*** Initialization *** | |
#Set application name & version | |
APPNAME=$(basename "$0") | |
VERSION="Version: 0.9_2008-09-20" | |
APTGETCMD= | |
#Set Default option values | |
QUIET_MODE=n | |
SIM_MODE=n | |
#Parse command line options (if any) | |
while getopts bhl:nqsv OPTIONS | |
do | |
case "$OPTIONS" in | |
h) show_usage | |
exit 0;; | |
l) echo "Option -$OPTIONS is not implemented yet.";; | |
q) QUIET_MODE=y;; | |
s) SIM_MODE=y;; | |
v) show_version;; | |
*) echo "Unknown option. Please use -h option to display command usage." | |
exit 1;; | |
esac | |
done | |
init_temp_dir | |
init_aptget_options | |
#Show welcome screen | |
show_welcome_msg | |
#Collect user choice of packages to install | |
SCM_PKG= | |
DBMS_PKG= | |
CPPENV_PKG= | |
MATHTOOLS_PKG= | |
MISCTOOLS_PKG= | |
get_packages | |
#debug | |
#for scm in $SCM_PKG; do echo $scm; done | |
#for dbms in $DBMS_PKG; do echo $dbms; done | |
#for cppenv in $CPPENV_PKG; do echo $cppenv; done | |
#for mathtools in $MATHTOOLS_PKG; do echo $mathtools; done | |
#for misctools in $MISCTOOLS_PKG; do echo $misctools; done | |
case $? in | |
0) | |
echo "Proceed with the installation.";; | |
1) | |
echo "Installation aborted." | |
exit 0;; | |
esac | |
#Proceed with mandatory installation procedures | |
update_packages | |
install_mandatories | |
#Process user choices | |
install_scm | |
install_dbms | |
if [ "$CPPENV_PKG" = "cpp" ]; then | |
install_cppenv; | |
fi | |
install_mathtools | |
install_misctools | |
cleanup | |
echo "Installation completed." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment