Skip to content

Instantly share code, notes, and snippets.

@steve-todorov
Created October 27, 2017 16:45
Show Gist options
  • Select an option

  • Save steve-todorov/955934fa361b58cff800cfdd3c259add to your computer and use it in GitHub Desktop.

Select an option

Save steve-todorov/955934fa361b58cff800cfdd3c259add to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
usage() {
cat <<EOF
Usage: $0 [options]
Options:
--install-repos Adds necessary repositories to zypper (kernel, 1dot75cm, nodejs, php, etc)
--install-nvidia-driver [VERSION] Installs nVidia drivers with the specified version i.e. 384.90. (Requires proper repositories from --install-repos!)
--install-apps Installs Google Chrome and Skype.
--install-pulseaudio Installs PulseAudio packages.
--help Show this message
EOF
}
ask() {
question=$1
read -r -p "$question [y/N] " response
case "$response" in
y)
echo true
;;
*)
echo false
;;
esac
}
repoExists() {
repoUrl=$1
echo `zypper lr -u | grep -F "$repoUrl" | wc -l`
}
addRepo() {
url=$1
alias=$2
askToInstall=$3
continueInstallation=1
printSkip=$4 || true
if [[ $askToInstall == "ask" ]]; then
continueInstallation=`ask "Install $alias ($url) repo?"`
fi
if [[ $continueInstallation -eq 1 && `repoExists $url` -eq 0 ]]; then
(set -x; zypper ar -f "$url" "$alias")
echo ""
elif [[ $continueInstallation -eq 1 ]]; then
if [[ $printSkip ]]; then
echo "Repository $url already exists! Skipping..."
fi
fi
}
installRepos() {
echo "Adding zypper repositories..."
addRepo "https://download.opensuse.org/repositories/Kernel:/stable/standard" "kernel:stable"
addRepo "https://download.opensuse.org/repositories/home:/1dot75cm:/branches:/X11:/Deepin/openSUSE_Tumbleweed" "deepin"
addRepo "https://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_Tumbleweed" "nodejs8" "ask"
addRepo "https://download.opensuse.org/repositories/devel:/languages:/php/openSUSE_Factory/" "php7" "ask"
addRepo "https://repo.skype.com/rpm/stable" "skype" "ask"
if `ask "Refresh repositories now?"`; then
zypper refresh
fi
}
installNvidiaDriver() {
if `ask "Installing nvidia requires some dependencies. Install them now?"`; then
echo "Installing kernel dependencies..."
kernelPackages=`zypper search -si kernel | cut -f 2 -d "|" | tail -n +6 | uniq | grep -v "patterns" | grep -v devel_kernel | xargs`
zypper in --force --repo kernel:stable $kernelPackages
echo ""
echo "Installing zypper patterns to be able to build nVidia drivers..."
zypper in -t pattern "devel_basis" "devel_C_C++" "devel_kernel" "devel_rpm_build"
echo ""
echo "New kernel has been installed. Please reboot and run this script again, skipping this step!"
echo ""
exit 0
fi
NVIDIA_RUN="/usr/src/NVIDIA-Linux-x86_64-$INSTALL_NVIDIA.run"
if [ ! -e $NVIDIA_RUN ]; then
echo "Downloading driver version $INSTALL_NVIDIA into $NVIDIA_RUN"
#https://uk.download.nvidia.com/XFree86/Linux-x86_64/384.90/NVIDIA-Linux-x86_64-384.90.run
(set -x; curl -j -L -o $NVIDIA_RUN https://uk.download.nvidia.com/XFree86/Linux-x86_64/$INSTALL_NVIDIA/NVIDIA-Linux-x86_64-$INSTALL_NVIDIA.run)
chmod 750 $NVIDIA_RUN
echo ""
else
echo "Driver has alredy been downloaded... skipping download."
fi
NOUVEAU=0
echo -n "Is nouveau module is currently being used? "
if [ `lsmod | grep -i nouveau | wc -l` -gt 0 ]; then
echo "yes - nvidia installation will fail!"
echo ""
echo "To fix nouveu module needs to be blacklisted in modprobe.d."
if `ask "Should we blacklist the nouveu module?"`; then
echo "blacklist nouveau" > /etc/modprobe.d/nvidia.conf
mkinitrd
echo ""
echo "Reboot and run this script again."
exit 0
else
echo "Sorry, nothing more to do here. Exiting."
exit 1
fi
else
echo "no - we can proceed"
fi
if [ `service --status-all | grep -i display-manager.service | grep -i running | wc -l` -gt 0 ]; then
echo ""
echo "Warning: You are currently running rcxdm!"
echo "Installing the driver will require you to stop Xorg/Wayland."
echo "You can do this by doing CTRL + ALT + F4; enter a valid user/pass; write rcxdm stop; run this script again!"
echo ""
exit 1
fi
echo "Installing nVidia driver $INSTALL_NVIDIA"
$NVIDIA_RUN
echo ""
echo "If the installation was successful - reboot and enjoy."
}
installApps() {
echo "Installing basic apps..."
echo " - Installing Google Chrome (if installation states boken packages - ignore)"
zypper in -y --no-force-resolution https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
echo ""
echo " - Installing Skype (if installation states boken packages - ignore)"
zypper in -y --no-force-resolution skypeforlinux
}
installGoogleChrome() {
echo "Installing Google Chrome"
echo " - Adding google signing key..."
rpm --import https://dl.google.com/linux/linux_signing_key.pub
}
installPulseAudio() {
echo "Installing PulseAudio packages..."
zypper in `zypper search pulseaudio | grep -v xfce | grep -v gdm | tail -n +6 | cut -f 2 -d "|" | xargs`
}
# Process arguments.
SHORT=h,
LONG=help,install-nvidia-driver:,install-repos,install-pulseaudio,install-apps
# -temporarily store output to be able to check for errors
# -activate advanced mode getopt quoting e.g. via “--options”
# -pass arguments only via -- "$@" to separate them correctly
PARSED=`getopt -n 'parse-options' --options $SHORT --longoptions $LONG --name "$0" -- "$@"`
if [[ $? -ne 0 ]]; then
# e.g. $? == 1
# then getopt has complained about wrong arguments to stdout
exit 2
fi
if [[ $# -eq 0 ]]; then
usage
exit 3
fi
# use eval with "$PARSED" to properly handle the quoting
eval set -- "$PARSED"
while true; do
case "$1" in
--install-nvidia-driver)
INSTALL_NVIDIA="$2"
shift 2
;;
--install-repos)
INSTALL_REPOS=1
shift
;;
--install-pulseaudio)
INSTALL_PULSEAUDIO=1
shift
;;
--install-apps)
INSTALL_APPS=1
shift
;;
-h|--help)
usage
exit 0;
;;
--)
shift
break
;;
*)
usage
exit 3
;;
esac
done
echo ""
if [[ $INSTALL_REPOS ]]; then
installRepos
fi
if [[ $INSTALL_PULSEAUDIO ]]; then
installPulseAudio
fi
if [[ $INSTALL_NVIDIA ]]; then
installNvidiaDriver
fi
if [[ $INSTALL_APPS ]]; then
installApps
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment