From c02bbb6f00fe0686c496f2181a8674c7e8d339d2 Mon Sep 17 00:00:00 2001 From: Thomas Mashos Date: Thu, 14 Mar 2019 15:29:11 -0700 Subject: [PATCH] Save answers in a setup.conf file so we don't need to prompt on every run --- .gitignore | 1 + setup.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..3dd096eda03b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +setup.conf \ No newline at end of file diff --git a/setup.sh b/setup.sh index 620f2a37b833..2a53480a3850 100644 --- a/setup.sh +++ b/setup.sh @@ -3,6 +3,19 @@ LX_BASE="" LX_VERSION="" +if [ -e setup.conf ]; then + echo "Saved configuration:" + cat ./setup.conf + echo "" + read -rp "Do you want to use this configuration? (type yes or no) " setupconfig;echo + if [ "$setupconfig" = "yes" ]; then + echo "Loading config from setup.conf" + . ./setup.conf + else + echo "Not loading setup.conf. Will prompt user." + fi +fi + if [ -r /etc/os-release ]; then . /etc/os-release if [ $ID = arch ]; then @@ -37,7 +50,9 @@ for dir in $(ls root/); do cp -Rb root/$dir/* /$dir/; done echo "Making /lib/systemd/system-sleep/sleep executable...\n" chmod a+x /lib/systemd/system-sleep/sleep -read -rp "Do you want to replace suspend with hibernate? (type yes or no) " usehibernate;echo +if [ -z "${usehibernate}" ]; then + read -rp "Do you want to replace suspend with hibernate? (type yes or no) " usehibernate;echo +fi if [ "$usehibernate" = "yes" ]; then if [ "$LX_BASE" = "ubuntu" ] && [ 1 -eq "$(echo "${LX_VERSION} >= 17.10" | bc)" ]; then @@ -51,7 +66,9 @@ else echo "Not touching Suspend\n" fi -read -rp "Do you want use the patched libwacom packages? (type yes or no) " uselibwacom;echo +if [ -z "${uselibwacom}" ]; then + read -rp "Do you want use the patched libwacom packages? (type yes or no) " uselibwacom;echo +fi if [ "$uselibwacom" = "yes" ]; then echo "Installing patched libwacom packages..." @@ -61,7 +78,9 @@ else echo "Not touching libwacom" fi -read -rp "Do you want to remove the example intel xorg config? (type yes or no) " removexorg;echo +if [ -z "${removexorg}" ]; then + read -rp "Do you want to remove the example intel xorg config? (type yes or no) " removexorg;echo +fi if [ "$removexorg" = "yes" ]; then echo "Removing the example intel xorg config..." @@ -70,7 +89,9 @@ else echo "Not touching example intel xorg config (/etc/X11/xorg.conf.d/20-intel_example.conf)" fi -read -rp "Do you want to remove the example pulse audio config files? (type yes or no) " removepulse;echo +if [ -z "${removepulse}" ]; then + read -rp "Do you want to remove the example pulse audio config files? (type yes or no) " removepulse;echo +fi if [ "$removepulse" = "yes" ]; then echo "Removing the example pulse audio config files..." @@ -210,7 +231,9 @@ echo "Installing mwlwifi firmware...\n" mkdir -p /lib/firmware/mwlwifi/ unzip -o firmware/mwlwifi_firmware.zip -d /lib/firmware/mwlwifi/ -read -rp "Do you want to set your clock to local time instead of UTC? This fixes issues when dual booting with Windows. (type yes or no) " uselocaltime;echo +if [ -z "${uselocaltime}" ]; then + read -rp "Do you want to set your clock to local time instead of UTC? This fixes issues when dual booting with Windows. (type yes or no) " uselocaltime;echo +fi if [ "$uselocaltime" = "yes" ]; then echo "Setting clock to local time...\n" @@ -221,21 +244,64 @@ else echo "Not setting clock" fi -read -rp "Do you want this script to download and install the latest kernel for you? (type yes or no) " autoinstallkernel;echo +if [ -z "${autoinstallkernel}" ]; then + read -rp "Do you want this script to download and install the latest kernel for you? (type yes or no) " autoinstallkernel;echo +fi if [ "$autoinstallkernel" = "yes" ]; then - echo "Downloading latest kernel...\n" - urls=$(curl --silent "https://api.github.com/repos/jakeday/linux-surface/releases/latest" | grep '"browser_download_url":' | sed -E 's/.*"([^"]+)".*/\1/') + json=$(curl --silent "https://api.github.com/repos/jakeday/linux-surface/releases/latest") + if [ -e /usr/bin/jq ] + then + echo "Checking if the latest kernel version is already installed.\n" + LATESTKERNELVERSION=$(echo $json | jq .tag_name | cut -d '-' -f1 | tr -d '"') + LATESTKERNELVERSIONINSTALLED=$(dpkg -l | grep linux-image-$LATESTKERNELVERSION) + if [ $? = "0" ]; then + read -rp "Latest kernel version is already installed. Do you want to redownload and reinstall the latest kernel? (type yes or no) " INSTALLKERNEL;echo + else + echo "Latest kernel version is not installed, will download.\n" + INSTALLKERNEL='yes' + fi + else + INSTALLKERNEL="yes" + fi + + if [ "$INSTALLKERNEL" = "yes" ]; then + echo "Downloading latest kernel...\n" - resp=$(wget -P tmp $urls) + urls=$(curl --silent "https://api.github.com/repos/jakeday/linux-surface/releases/latest" | grep '"browser_download_url":' | sed -E 's/.*"([^"]+)".*/\1/') - echo "Installing latest kernel...\n" + resp=$(wget -P tmp $urls) - dpkg -i tmp/*.deb - rm -rf tmp + echo "Installing latest kernel...\n" + + dpkg -i tmp/*.deb + rm -rf tmp + else + echo "Latest kernel already installed, Not redownloading\n" + fi else echo "Not downloading latest kernel" fi +if [ "$setupconfig" = "no" -o ! -e setup.conf ]; then + read -rp "Do you want to save your answers to setup.conf? (type yes or no) " saveconfig;echo + if [ "$saveconfig" = "yes" ]; then + echo "Saving answers to setup.conf\n" + #echo "copyroot=$copyroot" > setup.conf + #echo "sleepexecutable=$sleepexecutable" >> setup.conf + echo "usehibernate=$usehibernate" >> setup.conf + echo "uselibwacom=$uselibwacom" >> setup.conf + echo "removexorg=$removexorg" >> setup.conf + echo "removepulse=$removepulse" >> setup.conf + #echo "iptsfirmware=$iptsfirmware" >> setup.conf + #echo "marvellfirmware=$marvellfirmware" >> setup.conf + #echo "mwlwifi=$mwlwifi" >> setup.conf + echo "uselocaltime=$uselocaltime" >> setup.conf + echo "autoinstallkernel=$autoinstallkernel" >> setup.conf + else + echo "Not saving answers.\n" + fi +fi + echo "\nAll done! Please reboot."