#!/bin/bash
atom_required_plugins_file="atom-required-plugins"
atom_required_plugins_repo="https://gist.github.com/d76c5fdb074e6c22054a854b0197948b.git"
atom_tmp_dir="/tmp/atom"
atom_deb_package_path="${atom_tmp_dir}/atom-install.deb"
atom_required_plugins_dest_dir="${atom_tmp_dir}/required-packages"
function validate_user_permissions {
if [ "$EUID" -ne 0 ]
then echo "To install/upgrade atom you need to be root or admin user"
exit 1
fi
}
function install_atom {
mkdir -p ${atom_tmp_dir}
wget -O ${atom_deb_package_path} -c https://atom.io/download/deb
dpkg -i ${atom_deb_package_path}
rm -rfv ${atom_tmp_dir}
}
function remove_required_plugins_dest_dir {
rm -rf ${atom_required_plugins_dest_dir}
}
function install_atom_plugins {
if [ ! -z $(which git) ]; then
if [ -d ${atom_required_plugins_dest_dir} ] ; then
remove_required_plugins_dest_dir
fi
git clone --quiet ${atom_required_plugins_repo} ${atom_required_plugins_dest_dir}
# installing goimports dependencie
go get -v golang.org/x/tools/cmd/goimports
for plugin in $( cat "${atom_required_plugins_dest_dir}/${atom_required_plugins_file}" ) ; do
apm install ${plugin}
done
remove_required_plugins_dest_dir
else
echo "Please install git before use this script"
fi
}
function main {
if [ "${1}" == "--install-atom=true" ] || [ "${2}" == "--install-atom=true" ] ; then
validate_user_permissions
install_atom
fi
if [ "${1}" == "--install-atom-plugins=true" ] || [ "${2}" == "--install-atom-plugins=true" ] ; then
install_atom_plugins
fi
if [ -z "${1}" ] && [ -z ${2} ] ; then
echo "Usage:"
echo ""
echo "bash ${0} --install-atom=true --install-atom-plugins=true"
fi
}
main "${@}"
exit 0