aboutsummaryrefslogtreecommitdiff
path: root/root.sh
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2024-06-27 14:58:04 +0200
committersrdusr <trevorgray@srdusr.com>2024-06-27 14:58:04 +0200
commit96d7a3c44d2c78db616b5c5e97bfdbc8f206e3a4 (patch)
tree32692dbed08f299286978fa5a22211604b8286b2 /root.sh
parentf5eaa44d854d0844efa874912f0cdf8cc5907e24 (diff)
downloaddotfiles-96d7a3c44d2c78db616b5c5e97bfdbc8f206e3a4.tar.gz
dotfiles-96d7a3c44d2c78db616b5c5e97bfdbc8f206e3a4.zip
Add root.sh
Diffstat (limited to 'root.sh')
-rwxr-xr-xroot.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/root.sh b/root.sh
new file mode 100755
index 0000000..7706bce
--- /dev/null
+++ b/root.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+# Define the source base directory
+BASE_DIR="$HOME/extras"
+
+# Check if the script is running with superuser privileges
+if [ "$EUID" -ne 0 ]; then
+ echo "Please run as root or with sudo"
+ exit 1
+fi
+
+# Function to backup existing files
+backup_existing() {
+ local dest=$1
+ if [ -e "$dest" ]; then
+ echo "Backing up $dest"
+ mv "$dest" "$dest.bak"
+ fi
+}
+
+# Function to copy directories, backup, and change permissions
+copy_and_set_permissions() {
+ local src=$1
+ local dest=$2
+
+ if [ -d "$src" ]; then
+ echo "Processing directory $src"
+
+ for file in "$src"/*; {
+ dest_file="$dest/$(basename "$file")"
+
+ backup_existing "$dest_file"
+
+ echo "Copying $file to $dest"
+ cp -rp "$file" "$dest"
+
+ echo "Setting permissions for $dest_file"
+ chown root:root "$dest_file"
+ chmod 644 "$dest_file"
+ }
+ else
+ echo "Source directory $src does not exist."
+ fi
+}
+
+# Iterate over all directories in the extras directory
+for dir in "$BASE_DIR"/*; do
+ if [ -d "$dir" ]; then
+ dest_dir="/${dir##*/}"
+ copy_and_set_permissions "$dir" "$dest_dir"
+ fi
+done
+
+echo "Files copied and permissions set successfully."