Last active
July 20, 2019 02:51
-
-
Save lnoering/3814a4f0d788a6a03591bd7d264e456d to your computer and use it in GitHub Desktop.
Install some softwares on Fedora
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
#!/bin/bash | |
set -e | |
# Parameters: | |
# - the name of the software. | |
# - the path to the logs file. | |
check_command_result() { | |
if [ "$?" != 0 ]; then | |
echo "An error occurred during $1 installation. Please see $2 for more details." | |
fi | |
} | |
# Parameters: | |
# - the name of the package. | |
# - the path to the package. | |
rpm_file_dnf_install() { | |
echo "Installing $1..." | |
logs_filepath="$logs_dir/$1.log" | |
{ | |
dnf install -y $2 | |
} &> ${logs_filepath} || { | |
check_command_result $1 $logs_filepath | |
} | |
unset logs_filepath | |
} | |
# Parameters: | |
# - the name of the package. | |
simple_dnf_install() { | |
echo "Installing $1..." | |
logs_filepath="$logs_dir/$1.log" | |
{ | |
dnf install -y $1 | |
} &> ${logs_filepath} || { | |
check_command_result $1 $logs_filepath | |
} | |
unset logs_filepath | |
} | |
# Parameters: | |
# - the name of the software. | |
# - the name of the package. | |
simple_npm_install() { | |
echo "Installing $1..." | |
logs_filepath="$logs_dir/$1.log" | |
{ | |
hash npm; | |
if [ "$?" != 0 ]; then | |
echo "npm needs to be installed to install $2" | |
install_node | |
fi | |
su $SUDO_USER -c "npm install -g $2" | |
} &> ${logs_filepath} || { | |
check_command_result $1 $logs_filepath | |
} | |
unset logs_filepath | |
} | |
install_atom() { | |
rpm_file_dnf_install "atom" "https://atom-installer.github.com/v1.21.1/atom.x86_64.rpm" | |
} | |
install_chrome() { | |
rpm_file_dnf_install "chrome" "https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm" | |
} | |
install_docker() { | |
echo 'Installing Docker...' | |
logs_filepath="$logs_dir/docker.log" | |
{ | |
dnf -y install dnf-plugins-core && | |
dnf config-manager --add-repo -y https://download.docker.com/linux/fedora/docker-ce.repo && | |
dnf install -y docker-ce && | |
systemctl enable docker && | |
systemctl start docker && | |
usermod -aG docker $SUDO_USER | |
} &> ${logs_filepath} || { | |
check_command_result "Docker" $logs_filepath | |
} | |
unset logs_filepath | |
} | |
install_gimp() { | |
simple_dnf_install "gimp" | |
} | |
install_git() { | |
simple_dnf_install "git" | |
} | |
install_gradle() { | |
simple_dnf_install "gradle" | |
} | |
install_htop() { | |
simple_dnf_install "htop" | |
} | |
install_insomnia() { | |
echo 'Install Insomnia...' | |
logs_filepath="$logs_dir/insomnia.log" | |
filepath="/opt/insomnia.AppImage" | |
{ | |
curl -L https://builds.insomnia.rest/downloads/linux/latest > ${filepath} && | |
chown $SUDO_USER. $filepath && | |
chmod +x $filepath && | |
echo "alias insomnia=$filepath > /dev/null &" > /etc/profile.d/insomnia.sh | |
} &> ${logs_filepath} || { | |
check_command_result "Insomnia" $logs_filepath | |
} | |
unset logs_filepath | |
unset filepath | |
} | |
install_intellij() { | |
echo 'Install IntelliJ...' | |
logs_filepath="$logs_dir/intellij.log" | |
filepath="/opt/intellij.tar.gz" | |
{ | |
curl -L https://download.jetbrains.com/idea/ideaIU-2017.2.5.tar.gz > ${filepath} && | |
tar xf ${filepath} && | |
rm -f ${filepath} && | |
chown -R $SUDO_USER. /opt/$(ls /opt | grep idea) | |
} &> ${logs_filepath} || { | |
check_command_result "IntelliJ" $logs_filepath | |
} | |
unset logs_filepath | |
unset filepath | |
} | |
install_java() { | |
simple_dnf_install "java-1.8.0-openjdk-devel" | |
} | |
install_maven() { | |
simple_dnf_install "maven" | |
} | |
install_ng() { | |
simple_npm_install "ng" "@angular/cli" | |
} | |
install_node() { | |
echo 'Installing node...' | |
logs_filepath="$logs_dir/node.log" | |
{ | |
curl --location https://rpm.nodesource.com/setup_8.x | sudo bash - && | |
dnf install -y nodejs && | |
mkdir /home/$SUDO_USER/.npm && | |
chown -R $SUDO_USER. /home/$SUDO_USER/.npm && | |
su $SUDO_USER -c "npm config set prefix '~/.npm'" && | |
echo 'export PATH=~/.npm/bin:$PATH' > /etc/profile.d/npm.sh | |
} &> ${logs_filepath} || { | |
check_command_result "node" $logs_filepath | |
} | |
unset logs_filepath | |
} | |
install_ohmyzsh() { | |
echo 'Installing Oh My Zsh...' | |
logs_filepath="$logs_dir/ohmyzsh.log" | |
zsh_dir="/home/$SUDO_USER/.oh-my-zsh" | |
zshrc_filepath="/home/$SUDO_USER/.zshrc" | |
{ | |
dnf install -y git zsh && | |
git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git $zsh_dir && | |
chown -R $SUDO_USER. $zsh_dir && | |
cp $zsh_dir/templates/zshrc.zsh-template $zshrc_filepath && | |
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="agnoster"/' $zshrc_filepath && | |
sed -i 's/plugins=(git)/plugins=(apache2-macports command-not-found composer common-aliases dnf docker encode64 git git-extras gradle httpie history mvn ng node npm pip python sudo symfony2 systemd vagrant web-search yarn)/' $zshrc_filepath && | |
echo "DEFAULT_USER=$SUDO_USER" >> ${zshrc_filepath} | |
} &> ${logs_filepath} || { | |
check_command_result "Oh My Zsh" $logs_filepath | |
} | |
unset logs_filepath | |
unset zsh_dir | |
unset zshrc_filepath | |
} | |
install_terminator() { | |
simple_dnf_install "terminator" | |
} | |
install_vagrant() { | |
echo 'Installing vagrant...' | |
logs_filepath="$logs_dir/vagrant.log" | |
{ | |
dnf install -y vagrant http://download.virtualbox.org/virtualbox/5.2.0/VirtualBox-5.2-5.2.0_118431_fedora26-1.x86_64.rpm | |
} &> ${logs_filepath} || { | |
check_command_result "vagrant" $logs_filepath | |
} | |
unset logs_filepath | |
} | |
install_yarn() { | |
simple_npm_install "yarn" "yarn" | |
} | |
softwares=("atom" "chrome" "docker" "gimp" "git" "gradle" "htop" "insomnia" "intellij" "java" "maven" "ng" "node" "ohmyzsh" "terminator" "vagrant" "yarn") | |
# If --help is present, juste display help | |
if [[ "$@" == *"--help"* ]]; then | |
echo "Usage: $0 [--help|--list|--all|--<software_name>...]" | |
echo "Options:" | |
echo " --help: Display this message." | |
echo " --list: List all softwares." | |
echo " --all: Install all softwares." | |
echo " --<software_name>: Install the given software." | |
exit 0 | |
fi | |
# If --list is present, just display all softwares | |
if [[ "$@" == *"--list"* ]]; then | |
for software in "${softwares[@]}"; do | |
echo $software | |
done | |
exit 0 | |
fi | |
# If the user is not root, exit | |
if [ "$(id -u)" != "0" ]; then | |
echo 'You need to be root!' | |
exit 1 | |
fi | |
# Create logs directory | |
logs_dir="/var/log/setup" | |
mkdir -p $logs_dir | |
# If --all is present, install all softwares | |
if [[ "$@" == *"--all"* ]]; then | |
for software in "${softwares[@]}"; do | |
install_$software | |
done | |
exit 0 | |
fi | |
# For all options, install the associated software. | |
for option in $@; do | |
software=${option#--} | |
hash install_$software &> /dev/null | |
if [ "$?" != 0 ]; then | |
echo "Unknown software $software ignored." | |
else | |
install_$software | |
fi | |
unset software | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment