install.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. # GNU AGPLv3
  3. # Interactive install script for wminizer
  4. # Function to prompt the user for input with a default value
  5. prompt_user() {
  6. local prompt=$1
  7. local default=$2
  8. read -p "$prompt [$default]: " input
  9. echo "${input:-$default}"
  10. }
  11. # Function to display help message
  12. display_help() {
  13. echo "Usage: $0 [OPTIONS]"
  14. echo "Options:"
  15. echo " -a, --ask Ask before proceeding with a list of actions."
  16. echo " -p, --preview Print a list of actions without performing them."
  17. echo " -i, --interactive Run in interactive mode."
  18. echo " -h, --help Display this help message."
  19. }
  20. # Function to display the list of actions
  21. display_actions() {
  22. echo "The following actions will be performed:"
  23. echo "1. Install scripts to $INSTALL_DIR"
  24. echo "2. Install manpage to $MAN_DIR"
  25. if [[ "$CONFIGURE_XINITRC" == "y" ]]; then
  26. echo "3. Configure .xinitrc to start wminizer"
  27. else
  28. echo "3. Skip .xinitrc configuration"
  29. fi
  30. }
  31. # Default values
  32. DEFAULT_INSTALL_DIR="$HOME/bin"
  33. DEFAULT_MAN_DIR="$HOME/.local/share/man/man1"
  34. CONFIGURE_XINITRC="y"
  35. # Parse command-line options
  36. INTERACTIVE=false
  37. ASK=false
  38. PREVIEW=false
  39. while [[ $# -gt 0 ]]; do
  40. case $1 in
  41. -a|--ask)
  42. ASK=true
  43. shift
  44. ;;
  45. -p|--preview)
  46. PREVIEW=true
  47. shift
  48. ;;
  49. -i|--interactive)
  50. INTERACTIVE=true
  51. shift
  52. ;;
  53. -h|--help)
  54. display_help
  55. exit 0
  56. ;;
  57. *)
  58. echo "Unknown option: $1"
  59. display_help
  60. exit 1
  61. ;;
  62. esac
  63. done
  64. # Determine the mode of operation
  65. if [[ "$INTERACTIVE" == true ]]; then
  66. INSTALL_DIR=$(prompt_user "Enter the installation directory" "$DEFAULT_INSTALL_DIR")
  67. MAN_DIR=$(prompt_user "Enter the manpage installation directory" "$DEFAULT_MAN_DIR")
  68. CONFIGURE_XINITRC=$(prompt_user "Do you want to configure .xinitrc to start wminizer? (y/n)" "$CONFIGURE_XINITRC")
  69. elif [[ "$ASK" == true ]]; then
  70. display_actions
  71. read -p "Do you want to proceed? (y/n): " proceed
  72. if [[ "$proceed" != "y" ]]; then
  73. echo "Installation aborted."
  74. exit 0
  75. fi
  76. elif [[ "$PREVIEW" == true ]]; then
  77. display_actions
  78. exit 0
  79. else
  80. INSTALL_DIR="$DEFAULT_INSTALL_DIR"
  81. MAN_DIR="$DEFAULT_MAN_DIR"
  82. fi
  83. # Define the source directory (assuming the script is run from the project root)
  84. SRC_DIR="$(pwd)"
  85. # List of scripts to install
  86. SCRIPTS=("wmrotate1" "wmrotate2" "wminizer")
  87. # Function to copy a script to the install directory and make it executable
  88. install_script() {
  89. local script=$1
  90. echo "Installing $script..."
  91. cp "$SRC_DIR/$script" "$INSTALL_DIR/$script"
  92. chmod +x "$INSTALL_DIR/$script"
  93. echo "$script installed successfully."
  94. }
  95. # Install each script
  96. for script in "${SCRIPTS[@]}"; do
  97. install_script "$script"
  98. done
  99. # Install the manpage
  100. MANPAGE="wminizer.1"
  101. echo "Installing manpage $MANPAGE..."
  102. cp "$SRC_DIR/$MANPAGE" "$MAN_DIR/$MANPAGE"
  103. gzip "$MAN_DIR/$MANPAGE"
  104. echo "Manpage installed successfully."
  105. # Configure .xinitrc
  106. if [[ "$CONFIGURE_XINITRC" == "y" ]]; then
  107. # Create a timestamped backup of the current .xinitrc if it exists
  108. XINITRC="$HOME/.xinitrc"
  109. if [ -f "$XINITRC" ]; then
  110. BACKUP="$XINITRC.$(date +%Y%m%d%H%M%S).bak"
  111. echo "Backing up existing .xinitrc to $BACKUP..."
  112. cp "$XINITRC" "$BACKUP"
  113. fi
  114. # Append the wminizer command to the .xinitrc file
  115. echo "exec wminizer" >> "$XINITRC"
  116. echo ".xinitrc updated to start wminizer."
  117. else
  118. echo ".xinitrc configuration skipped."
  119. fi
  120. echo "Installation complete. You can now start your X session with wminizer."