Advertisement
Mark2020H

Install script for Powershell Debian Bookworm

Dec 17th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.55 KB | Source Code | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. ## insPowerShell.sh
  4. ## Written by MD Harrington  For Debian (Bookworm) 64 bit achitecture
  5. ## Tested on Debian 12 and  works like a charm
  6. ## To Run do af follows
  7. ## 1) Change to directory you dowloaded this to  type the following
  8. ## 2) chmod +x <name of file.sh>
  9. ## 3) ./<name of file.sh>
  10. ## All the rest is automatically done for you
  11.  
  12. # Colors for output
  13. RED="\e[31m"
  14. GREEN="\e[32m"
  15. YELLOW="\e[33m"
  16. BLUE="\e[34m"
  17. RESET="\e[0m"
  18.  
  19. # Function to display colored messages
  20. function print_message() {
  21.     local color=$1
  22.     local message=$2
  23.     echo -e "${color}${message}${RESET}"
  24. }
  25.  
  26. # Function to display the header
  27. function display_header() {
  28.     clear
  29.     print_message "$YELLOW" "========================================"
  30.     print_message "$YELLOW" " Script Written By MD Harrington"
  31.     print_message "$YELLOW" " London Kent DA6 8NP"
  32.     print_message "$YELLOW" " Please wait 2 seconds ..."
  33.     print_message "$YELLOW" "========================================"
  34.     sleep 2
  35. }
  36.  
  37. # Call the header function
  38. display_header
  39.  
  40. # 1) Check OS and version
  41. print_message "$BLUE" "Checking system compatibility..."
  42.  
  43. OS_NAME=$(lsb_release -is 2>/dev/null || echo "Unknown")
  44. OS_VERSION=$(lsb_release -cs 2>/dev/null || echo "Unknown")
  45. ARCH=$(uname -m)
  46.  
  47. if [[ "$OS_NAME" != "Debian" || "$OS_VERSION" != "bookworm" || "$ARCH" != "x86_64" ]]; then
  48.     print_message "$RED" "Script is written for Debian 12 (bookworm) 64-bit architecture."
  49.     print_message "$YELLOW" "Proceed at your own risk!"
  50.     exit 1
  51. fi
  52. print_message "$GREEN" "System check passed: Debian 12 (bookworm) 64-bit."
  53.  
  54. # 2) Update system and check for updates
  55. print_message "$BLUE" "Updating package lists and checking for upgrades..."
  56. sudo apt-get update && sudo apt-get upgrade -y
  57. print_message "$GREEN" "System update completed successfully."
  58.  
  59. # 3) Install wget if not already installed
  60. print_message "$BLUE" "Checking for wget..."
  61. if ! command -v wget &> /dev/null; then
  62.     print_message "$YELLOW" "wget not found. Installing wget..."
  63.     sudo apt-get install -y wget
  64.     print_message "$GREEN" "wget installed successfully."
  65. else
  66.     print_message "$GREEN" "wget is already installed."
  67. fi
  68.  
  69. # 4) Download the PowerShell .deb file
  70. DEB_URL="https://github.com/PowerShell/PowerShell/releases/download/v7.4.6/powershell_7.4.6-1.deb_amd64.deb"
  71. DEB_FILE="powershell_7.4.6-1.deb_amd64.deb"
  72.  
  73. print_message "$BLUE" "Downloading PowerShell .deb file..."
  74. wget "$DEB_URL" -O "$DEB_FILE"
  75.  
  76. if [[ ! -f "$DEB_FILE" ]]; then
  77.     print_message "$RED" "Download failed. Exiting script."
  78.     exit 1
  79. fi
  80. print_message "$GREEN" "PowerShell .deb file downloaded successfully."
  81.  
  82. # 5) Create 'installs' directory
  83. INSTALL_DIR="installs"
  84.  
  85. print_message "$BLUE" "Creating '$INSTALL_DIR' directory..."
  86. mkdir -p "$INSTALL_DIR"
  87.  
  88. if [[ ! -d "$INSTALL_DIR" ]]; then
  89.     print_message "$RED" "Failed to create directory '$INSTALL_DIR'. Exiting script."
  90.     exit 1
  91. fi
  92. print_message "$GREEN" "'$INSTALL_DIR' directory created successfully."
  93.  
  94. # Move the downloaded file into the installs directory
  95. print_message "$BLUE" "Moving PowerShell .deb file to '$INSTALL_DIR'..."
  96. mv "$DEB_FILE" "$INSTALL_DIR/"
  97.  
  98. if [[ ! -f "$INSTALL_DIR/$DEB_FILE" ]]; then
  99.     print_message "$RED" "Failed to move the .deb file. Exiting script."
  100.     exit 1
  101. fi
  102. print_message "$GREEN" "File moved successfully."
  103.  
  104. # 6) Install PowerShell package
  105. print_message "$BLUE" "Installing PowerShell package..."
  106. cd "$INSTALL_DIR" || exit
  107. sudo dpkg -i "$DEB_FILE"
  108.  
  109. # 7) Resolve missing dependencies
  110. print_message "$BLUE" "Resolving missing dependencies..."
  111. sudo apt-get install -f -y
  112.  
  113. print_message "$GREEN" "PowerShell installation completed successfully."
  114.  
  115. # 8) Delete the .deb file
  116. print_message "$BLUE" "Cleaning up: Deleting PowerShell .deb file..."
  117. rm "$DEB_FILE"
  118.  
  119. if [[ -f "$DEB_FILE" ]]; then
  120.     print_message "$RED" "Failed to delete the .deb file. Please delete it manually."
  121. else
  122.     print_message "$GREEN" "Cleanup successful."
  123. fi
  124.  
  125. # 9) Test PowerShell installation
  126. print_message "$BLUE" "Testing PowerShell installation..."
  127. pwsh --version
  128.  
  129. if [[ $? -eq 0 ]]; then
  130.     print_message "$GREEN" "PowerShell installed successfully!"
  131.     print_message "$YELLOW" "You can now run PowerShell by typing 'pwsh'."
  132. else
  133.     print_message "$RED" "PowerShell installation failed."
  134. fi
  135.  
  136.  
  137. ## Links as follows
  138. ## https://www.instagram.com/markukh2021/
  139. ## https://www.facebook.com/mark.harrington.14289/
  140. ## https://github.com/markh2024?tab=repositories
  141. ## https://pastebin.com/u/Mark2020H
  142. ## https://codeshare.io/9bxp67
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement