Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Commit

Permalink
Fix setup script to (by default) run without superuser permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
dmhacker committed Dec 28, 2019
1 parent c13d790 commit 11a9999
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/bash

echo "This script was created to simplify the setup process for Surface devices running Arch Linux."
echo "This script will prepare Surface devices for installation of a patched Arch Linux kernel."
echo "Answer 'y' to any options you wish to install. By default, options are unselected."
echo

cache_folder=.cache_setup
cache_folder=.cache
patches_repository=git://github.com/qzed/linux-surface.git
patches_src_folder=linux-surface
firmware_src_folder="$cache_folder/$patches_src_folder/firmware"
Expand All @@ -12,24 +13,24 @@ libwacom_src_folder=libwacom-surface

############################### SETUP ###############################

# This cache is temporary (fixes issues with superuser permissions)
echo "Creating temporary cache ..."
echo "Updating cache ..."
mkdir -p $cache_folder
cd $cache_folder

# Fetch repositories from GitHub
# Fetch patches repository
if [ -d $patches_src_folder ]; then
cd $patches_src_folder && git pull && cd ..
else
git clone $patches_repository $patches_src_folder
fi

# Fetch libwacom repository
if [ -d $libwacom_src_folder ]; then
cd $libwacom_src_folder && git pull && cd ..
else
git clone $libwacom_repository $libwacom_src_folder
fi

# Exit the cache folder
cd ..

############################### INSTALLATION ###############################
Expand All @@ -39,13 +40,11 @@ echo
read -r -p "1. Copy config files from qzed's kernel to root? [y/N] "
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Unpacking files to / ..."
cp -r $cache_folder/$patches_src_folder/root/etc/* /etc
mkdir -p /lib/systemd/system-sleep
cp $cache_folder/$patches_src_folder/root/lib/systemd/system-sleep/sleep /lib/systemd/system-sleep

sudo cp -r $cache_folder/$patches_src_folder/root/etc/* /etc
sudo mkdir -p /lib/systemd/system-sleep
sudo cp $cache_folder/$patches_src_folder/root/lib/systemd/system-sleep/sleep /lib/systemd/system-sleep
echo "Making /lib/systemd/system-sleep/sleep executable ..."
chmod a+x /lib/systemd/system-sleep/sleep

sudo chmod a+x /lib/systemd/system-sleep/sleep
echo "Done copying config files."
fi

Expand All @@ -55,20 +54,21 @@ echo "!!! WARNING !!! The following option will reset the MODULES option in your
echo "!!! WARNING !!! A backup of /etc/mkinitcpio.conf will be saved to /etc/mkinitcpio.conf.old if you proceed."
read -r -p "2. Rebuild kernel with modules from /etc/initramfs-tools/modules? [y/N] "
if [[ $REPLY =~ ^[Yy]$ ]]; then
cp /etc/mkinitcpio.conf /etc/mkinitcpio.conf.backup
sudo cp /etc/mkinitcpio.conf /etc/mkinitcpio.conf.backup
modules=$(echo "MODULES=($(grep -v '^#' $cache_folder/$patches_src_folder/root/etc/initramfs-tools/modules))" | tr "\n" " " | sed 's/ *$//g')
sed -i "/^MODULES=(.*)/c\\$modules" /etc/mkinitcpio.conf
sudo sed -i "/^MODULES=(.*)/c\\$modules" /etc/mkinitcpio.conf
echo "$modules will be added to /etc/mkinitcpio.conf."
mkinitcpio
sudo mkinitcpio
echo "Done fixing mkinitcpio.conf."
fi

# Prompt for replacement of suspend with hibernate
echo
read -r -p "3. Replace suspend with hibernate? [y/N] "
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Symlinking suspend target/service to hibernate target/service ..."
ln -sf /lib/systemd/system/hibernate.target /etc/systemd/system/suspend.target
ln -sf /lib/systemd/system/systemd-hibernate.service /etc/systemd/system/systemd-suspend.service
sudo ln -sf /lib/systemd/system/hibernate.target /etc/systemd/system/suspend.target
sudo ln -sf /lib/systemd/system/systemd-hibernate.service /etc/systemd/system/systemd-suspend.service
echo "Done replacing suspend with hibernate."
fi

Expand All @@ -77,8 +77,8 @@ echo
read -r -p "4. Install all firmware to /lib/firmware? [y/N] "
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Copying files to /lib/firmware ..."
mkdir -p /lib/firmware
cp -rv $firmware_src_folder/* /lib/firmware
sudo mkdir -p /lib/firmware
sudo cp -rv $firmware_src_folder/* /lib/firmware
echo "Done installing firmware."
fi

Expand All @@ -95,12 +95,5 @@ fi

############################### CLEANUP ###############################

# Remove the cache folder to handle permission issues
# echo ""
# echo "Removing temporary cache ..."
# rm -rf $cache_folder

# Yay! All done.
echo
echo "Setup process finished!"
echo "Install your patched kernel and then reboot."
echo "Setup process finished. Install your patched kernel and then reboot."

0 comments on commit 11a9999

Please sign in to comment.