RitchieSolo

Idea For Xanmod4Slackware.sh

Jul 26th, 2026
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.84 KB | None | 0 0
  1. #!/bin/bash
  2. # Xanmod4Slack - Universal XanMod Kernel Builder and Package Manager
  3. # Compatible with: Slackware, Debian, Devuan, and derivatives
  4. # Supports: systemd, OpenRC, runit, dinit, shepherd, sysvinit
  5. # Supports: GRUB2, GRUB Legacy, LILO, ELILO, SYSLINUX, systemd-boot, EFISTUB
  6. # Version: 2.0.3
  7.  
  8. # --- Color definitions for terminal output ---
  9. RED='\033[0;31m'
  10. GREEN='\033[0;32m'
  11. YELLOW='\033[0;33m'
  12. BLUE='\033[0;34m'
  13. NC='\033[0m' # No Color
  14.  
  15. # --- Configuration ---
  16. VERSION="2.0.3"
  17. CONFIG_DIR="${HOME}/.config/xanmod4slack"
  18. CONFIG_FILE="${CONFIG_DIR}/xanmod4slack.conf"
  19. LOG_DIR="${HOME}/.local/log/xanmod4slack"
  20. LOG_FILE="${LOG_DIR}/xanmod4slack.log"
  21. WORK_DIR="${HOME}/src/xanmod"
  22. XANMOD_REPO="https://github.com/xanmod/linux.git"
  23. XANMOD_BRANCH="master"
  24. NOTIFICATION_SENT_FILE="${CONFIG_DIR}/last_notification"
  25.  
  26. # --- Default Configuration Values ---
  27. DEFAULT_UPDATE_FREQ="weekly"
  28. DEFAULT_INTERFACE="auto"
  29. DEFAULT_KEEP_OLD="3"
  30. DEFAULT_AUTO_UPDATE="false"
  31. DEFAULT_AUTO_CLEANUP="false"
  32. DEFAULT_SILENT_NOTIFICATIONS="false"
  33. DEFAULT_DETECT_HARDWARE="true"
  34. DEFAULT_CUSTOM_CONFIG=""
  35. DEFAULT_MARCH="native"
  36.  
  37. # --- Initialize directories ---
  38. mkdir -p "${CONFIG_DIR}" "${LOG_DIR}" "${WORK_DIR}"
  39. touch "${LOG_FILE}"
  40.  
  41. # --- Functions ---
  42.  
  43. log() {
  44. echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "${LOG_FILE}"
  45. }
  46.  
  47. error() {
  48. log "ERROR: $1"
  49. if [ -n "$2" ]; then
  50. show_msg "Error" "$1" "error"
  51. fi
  52. exit 1
  53. }
  54.  
  55. load_config() {
  56. if [ -f "${CONFIG_FILE}" ]; then
  57. source "${CONFIG_FILE}"
  58. log "Loaded configuration from ${CONFIG_FILE}"
  59. else
  60. log "No configuration file found. Using defaults."
  61. UPDATE_FREQ="${DEFAULT_UPDATE_FREQ}"
  62. INTERFACE="${DEFAULT_INTERFACE}"
  63. KEEP_OLD="${DEFAULT_KEEP_OLD}"
  64. AUTO_UPDATE="${DEFAULT_AUTO_UPDATE}"
  65. AUTO_CLEANUP="${DEFAULT_AUTO_CLEANUP}"
  66. SILENT_NOTIFICATIONS="${DEFAULT_SILENT_NOTIFICATIONS}"
  67. DETECT_HARDWARE="${DEFAULT_DETECT_HARDWARE}"
  68. CUSTOM_CONFIG="${DEFAULT_CUSTOM_CONFIG}"
  69. MARCH="${DEFAULT_MARCH}"
  70. fi
  71. }
  72.  
  73. save_config() {
  74. cat > "${CONFIG_FILE}" << EOF
  75. # Xanmod4Slack Configuration
  76. UPDATE_FREQ="${UPDATE_FREQ:-$DEFAULT_UPDATE_FREQ}"
  77. INTERFACE="${INTERFACE:-$DEFAULT_INTERFACE}"
  78. KEEP_OLD="${KEEP_OLD:-$DEFAULT_KEEP_OLD}"
  79. AUTO_UPDATE="${AUTO_UPDATE:-$DEFAULT_AUTO_UPDATE}"
  80. AUTO_CLEANUP="${AUTO_CLEANUP:-$DEFAULT_AUTO_CLEANUP}"
  81. SILENT_NOTIFICATIONS="${SILENT_NOTIFICATIONS:-$DEFAULT_SILENT_NOTIFICATIONS}"
  82. DETECT_HARDWARE="${DETECT_HARDWARE:-$DEFAULT_DETECT_HARDWARE}"
  83. CUSTOM_CONFIG="${CUSTOM_CONFIG:-$DEFAULT_CUSTOM_CONFIG}"
  84. MARCH="${MARCH:-$DEFAULT_MARCH}"
  85. EOF
  86. log "Configuration saved to ${CONFIG_FILE}"
  87. }
  88.  
  89. detect_distro() {
  90. if [ -f /etc/debian_version ]; then
  91. echo "debian"
  92. elif [ -f /etc/slackware-version ]; then
  93. echo "slackware"
  94. else
  95. echo "unknown"
  96. fi
  97. }
  98.  
  99. detect_init() {
  100. if pidof -q systemd 2>/dev/null && [ -d /run/systemd/system ]; then
  101. echo "systemd"
  102. return
  103. fi
  104. if command -v openrc-init &> /dev/null; then
  105. echo "openrc"
  106. return
  107. fi
  108. if command -v runsvdir &> /dev/null; then
  109. echo "runit"
  110. return
  111. fi
  112. if command -v dinit &> /dev/null; then
  113. echo "dinit"
  114. return
  115. fi
  116. if command -v shepherd &> /dev/null; then
  117. echo "shepherd"
  118. return
  119. fi
  120. if [ -f /sbin/init ] && file /sbin/init | grep -q "sysvinit"; then
  121. echo "sysvinit"
  122. return
  123. fi
  124. echo "unknown"
  125. }
  126.  
  127. detect_bootloader() {
  128. if command -v grub-mkconfig &> /dev/null; then
  129. echo "grub2"
  130. return
  131. elif [ -f /boot/grub/menu.lst ] || [ -f /boot/grub/grub.conf ]; then
  132. echo "grub-legacy"
  133. return
  134. elif command -v lilo &> /dev/null && [ -f /etc/lilo.conf ]; then
  135. echo "lilo"
  136. return
  137. elif command -v elilo &> /dev/null && [ -f /etc/elilo.conf ]; then
  138. echo "elilo"
  139. return
  140. elif command -v extlinux &> /dev/null || [ -f /boot/extlinux/extlinux.conf ]; then
  141. echo "syslinux"
  142. return
  143. elif [ -d /boot/efi/EFI/systemd ] || [ -d /boot/EFI/systemd ]; then
  144. echo "systemd-boot"
  145. return
  146. elif [ -d /sys/firmware/efi ] && [ -f /boot/vmlinuz-* ]; then
  147. echo "efistub"
  148. return
  149. else
  150. echo "unknown"
  151. return
  152. fi
  153. }
  154.  
  155. detect_interface() {
  156. if [ -n "$DISPLAY" ] && [ -x "$(command -v zenity)" ]; then
  157. echo "gui"
  158. elif [ -n "$DISPLAY" ] && [ -x "$(command -v kdialog)" ]; then
  159. echo "gui"
  160. elif [ -x "$(command -v dialog)" ]; then
  161. echo "dialog"
  162. else
  163. echo "text"
  164. fi
  165. }
  166.  
  167. show_msg() {
  168. local title="$1"
  169. local message="$2"
  170. local type="${3:-info}"
  171. local interface="${INTERFACE:-auto}"
  172.  
  173. if [ "$interface" = "auto" ]; then
  174. interface=$(detect_interface)
  175. fi
  176.  
  177. case "$interface" in
  178. gui)
  179. if [ -x "$(command -v zenity)" ]; then
  180. zenity --${type} --title="${title}" --text="${message}" --width=400 --timeout=30 2>/dev/null || true
  181. elif [ -x "$(command -v kdialog)" ]; then
  182. kdialog --${type} "${message}" --title "${title}" 2>/dev/null || true
  183. else
  184. echo "=== ${title} ==="
  185. echo "${message}"
  186. fi
  187. ;;
  188. dialog)
  189. dialog --title "${title}" --msgbox "${message}" 10 60 2>/dev/null || true
  190. ;;
  191. *)
  192. echo "=== ${title} ==="
  193. echo "${message}"
  194. ;;
  195. esac
  196. }
  197.  
  198. show_question() {
  199. local title="$1"
  200. local message="$2"
  201. local interface="${INTERFACE:-auto}"
  202.  
  203. if [ "$interface" = "auto" ]; then
  204. interface=$(detect_interface)
  205. fi
  206.  
  207. case "$interface" in
  208. gui)
  209. if [ -x "$(command -v zenity)" ]; then
  210. zenity --question --title="${title}" --text="${message}" --width=400 2>/dev/null && return 0 || return 1
  211. elif [ -x "$(command -v kdialog)" ]; then
  212. kdialog --yesno "${message}" --title "${title}" 2>/dev/null && return 0 || return 1
  213. else
  214. echo "${message} (y/N): "
  215. read answer
  216. [[ "$answer" =~ ^[Yy]$ ]] && return 0 || return 1
  217. fi
  218. ;;
  219. dialog)
  220. dialog --title "${title}" --yesno "${message}" 10 60 2>/dev/null && return 0 || return 1
  221. ;;
  222. *)
  223. echo "${message} (y/N): "
  224. read answer
  225. [[ "$answer" =~ ^[Yy]$ ]] && return 0 || return 1
  226. ;;
  227. esac
  228. }
  229.  
  230. show_menu() {
  231. local title="$1"
  232. local prompt="$2"
  233. shift 2
  234. local options=("$@")
  235. local interface="${INTERFACE:-auto}"
  236. local choice=""
  237. local i=0
  238.  
  239. if [ "$interface" = "auto" ]; then
  240. interface=$(detect_interface)
  241. fi
  242.  
  243. case "$interface" in
  244. gui)
  245. if [ -x "$(command -v zenity)" ]; then
  246. local menu_items=()
  247. i=0
  248. while [ $i -lt ${#options[@]} ]; do
  249. menu_items+=("${options[$i]}" "${options[$i+1]}")
  250. i=$((i+2))
  251. done
  252. choice=$(zenity --list --title="${title}" --text="${prompt}" \
  253. --column="Option" --column="Description" \
  254. "${menu_items[@]}" --width=600 --height=400 2>/dev/null || echo "cancel")
  255. echo "$choice"
  256. return
  257. elif [ -x "$(command -v kdialog)" ]; then
  258. local menu_string=""
  259. i=0
  260. while [ $i -lt ${#options[@]} ]; do
  261. menu_string="${menu_string}${options[$i]} \"${options[$i+1]}\" "
  262. i=$((i+2))
  263. done
  264. choice=$(kdialog --menu "${prompt}" ${menu_string} --title "${title}" 2>/dev/null || echo "cancel")
  265. echo "$choice"
  266. return
  267. else
  268. echo "cancel"
  269. return
  270. fi
  271. ;;
  272. dialog)
  273. local menu_items=()
  274. i=0
  275. while [ $i -lt ${#options[@]} ]; do
  276. menu_items+=("${options[$i]}" "${options[$i+1]}")
  277. i=$((i+2))
  278. done
  279. choice=$(dialog --title "${title}" --menu "${prompt}" 20 60 10 "${menu_items[@]}" 2>&1 >/dev/tty || echo "cancel")
  280. echo "$choice"
  281. return
  282. ;;
  283. *)
  284. echo "=== ${title} ==="
  285. echo "${prompt}"
  286. i=0
  287. while [ $i -lt ${#options[@]} ]; do
  288. echo " ${options[$i]}) ${options[$i+1]}"
  289. i=$((i+2))
  290. done
  291. echo -n "Select option: "
  292. read choice
  293. echo "${choice}"
  294. return
  295. ;;
  296. esac
  297. }
  298.  
  299. detect_hardware() {
  300. log "Detecting hardware..."
  301. local hw_profile="${WORK_DIR}/hw_profile.txt"
  302. mkdir -p "$(dirname "$hw_profile")"
  303.  
  304. {
  305. echo "# Hardware Profile for Xanmod Kernel"
  306. echo "Generated: $(date)"
  307. echo ""
  308. echo "=== CPU ==="
  309. lscpu 2>/dev/null || cat /proc/cpuinfo 2>/dev/null | head -20
  310. echo ""
  311. echo "=== PCI Devices ==="
  312. lspci -k 2>/dev/null || echo "lspci not available"
  313. echo ""
  314. echo "=== USB Devices ==="
  315. lsusb 2>/dev/null || echo "lsusb not available"
  316. echo ""
  317. echo "=== Block Devices ==="
  318. lsblk 2>/dev/null || echo "lsblk not available"
  319. echo ""
  320. echo "=== Network ==="
  321. ip link show 2>/dev/null || ifconfig -a 2>/dev/null
  322. echo ""
  323. echo "=== DMI Info ==="
  324. dmidecode -t system 2>/dev/null || echo "dmidecode not available"
  325. echo ""
  326. echo "=== Kernel Modules ==="
  327. lsmod 2>/dev/null | head -20
  328. } > "$hw_profile"
  329.  
  330. log "Hardware profile saved to $hw_profile"
  331. return 0
  332. }
  333.  
  334. generate_optimized_config() {
  335. log "Generating optimized kernel config..."
  336.  
  337. if ! command -v make &> /dev/null; then
  338. error "make is required but not installed"
  339. return 1
  340. fi
  341.  
  342. if [ -f "${WORK_DIR}/.config" ]; then
  343. rm "${WORK_DIR}/.config"
  344. fi
  345.  
  346. make -C "${WORK_DIR}" defconfig 2>&1 || error "Failed to generate default config"
  347.  
  348. if [ "${DETECT_HARDWARE}" = "true" ]; then
  349. log "Applying localmodconfig to strip unnecessary drivers..."
  350. make -C "${WORK_DIR}" localmodconfig 2>&1 || log "Warning: localmodconfig failed"
  351. fi
  352.  
  353. local march_flag=""
  354. case "${MARCH}" in
  355. native)
  356. march_flag="-march=native"
  357. ;;
  358. v3)
  359. march_flag="-march=x86-64-v3"
  360. ;;
  361. v4)
  362. march_flag="-march=x86-64-v4"
  363. ;;
  364. generic)
  365. march_flag="-march=x86-64"
  366. ;;
  367. *)
  368. march_flag="-march=native"
  369. ;;
  370. esac
  371.  
  372. scripts/config --file "${WORK_DIR}/.config" --set-val CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE y 2>/dev/null || true
  373.  
  374. if [ -f "${CUSTOM_CONFIG}" ]; then
  375. log "Applying custom configuration from ${CUSTOM_CONFIG}"
  376. cp "${CUSTOM_CONFIG}" "${WORK_DIR}/.config" || error "Failed to apply custom config"
  377. fi
  378.  
  379. log "Hardware detection and optimization completed"
  380. return 0
  381. }
  382.  
  383. check_updates() {
  384. log "Checking for XanMod updates..."
  385.  
  386. if ! command -v git &> /dev/null; then
  387. log "ERROR: git is not installed"
  388. show_msg "Error" "git is required but not installed. Please install git first." "error"
  389. return 1
  390. fi
  391.  
  392. mkdir -p "${WORK_DIR}"
  393.  
  394. local remote_version=""
  395. local local_version=""
  396.  
  397. if command -v git &> /dev/null; then
  398. remote_version=$(git ls-remote --tags "${XANMOD_REPO}" 2>/dev/null | grep -E "refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$" | sed 's|.*refs/tags/||' | sort -V | tail -n1)
  399. fi
  400.  
  401. if [ -d "${WORK_DIR}/.git" ]; then
  402. local_version=$(git -C "${WORK_DIR}" describe --tags --abbrev=0 2>/dev/null)
  403. fi
  404.  
  405. if [ -z "$remote_version" ]; then
  406. log "ERROR: Could not determine latest version"
  407. return 1
  408. fi
  409.  
  410. if [ -z "$local_version" ] || [ "$remote_version" != "$local_version" ]; then
  411. log "New version available: $remote_version (current: ${local_version:-none})"
  412. echo "$remote_version"
  413. return 0
  414. else
  415. log "Already up to date: $local_version"
  416. echo "$local_version"
  417. return 1
  418. fi
  419. }
  420.  
  421. send_notification() {
  422. local title="$1"
  423. local message="$2"
  424. local urgency="${3:-normal}"
  425.  
  426. if [ "${SILENT_NOTIFICATIONS}" = "true" ]; then
  427. log "Notifications silenced. Would have sent: $title"
  428. return 0
  429. fi
  430.  
  431. local interface=$(detect_interface)
  432.  
  433. case "$interface" in
  434. gui)
  435. if [ -x "$(command -v zenity)" ]; then
  436. zenity --notification --text="${title}: ${message}" 2>/dev/null || true
  437. elif [ -x "$(command -v notify-send)" ]; then
  438. notify-send -u "${urgency}" "${title}" "${message}" 2>/dev/null || true
  439. fi
  440. ;;
  441. dialog)
  442. echo "${title}: ${message}"
  443. ;;
  444. *)
  445. echo "${title}: ${message}"
  446. ;;
  447. esac
  448.  
  449. log "Notification sent: $title - $message"
  450. }
  451. build_kernel() {
  452. log "Building XanMod kernel..."
  453.  
  454. if ! command -v make &> /dev/null || ! command -v gcc &> /dev/null; then
  455. error "Build tools (make, gcc) are not installed. Please install them first."
  456. fi
  457.  
  458. if [ ! -d "${WORK_DIR}/.git" ]; then
  459. log "Cloning XanMod repository..."
  460. git clone "${XANMOD_REPO}" "${WORK_DIR}" 2>&1 || error "Failed to clone repository"
  461. else
  462. log "Updating XanMod repository..."
  463. git -C "${WORK_DIR}" fetch --tags 2>&1 || error "Failed to fetch updates"
  464. fi
  465.  
  466. local latest_version=$(git -C "${WORK_DIR}" describe --tags --abbrev=0 2>/dev/null)
  467. if [ -z "$latest_version" ]; then
  468. error "Failed to determine latest version from repository"
  469. fi
  470. log "Checking out version: $latest_version"
  471. git -C "${WORK_DIR}" checkout "${latest_version}" 2>&1 || error "Failed to checkout latest version"
  472.  
  473. if [ "${DETECT_HARDWARE}" = "true" ]; then
  474. detect_hardware
  475. fi
  476.  
  477. generate_optimized_config
  478.  
  479. local cpu_count=$(nproc 2>/dev/null || echo 1)
  480. log "Compiling kernel with $cpu_count parallel jobs..."
  481.  
  482. make -C "${WORK_DIR}" -j${cpu_count} all 2>&1 || error "Kernel compilation failed"
  483.  
  484. local distro=$(detect_distro)
  485. log "Packaging for distribution: $distro"
  486.  
  487. case "$distro" in
  488. debian)
  489. make -C "${WORK_DIR}" deb-pkg -j${cpu_count} 2>&1 || error "Debian package creation failed"
  490. log "Debian packages created successfully"
  491. ;;
  492. slackware)
  493. if [ -f "${WORK_DIR}/build-all-kernels.sh" ]; then
  494. ${WORK_DIR}/build-all-kernels.sh 2>&1 || error "Slackware package creation failed"
  495. log "Slackware packages created successfully"
  496. else
  497. local package_name="kernel-xanmod-${latest_version#v}"
  498. mkdir -p "${WORK_DIR}/pkg" "${WORK_DIR}/pkg/boot" "${WORK_DIR}/pkg/lib/modules"
  499. make -C "${WORK_DIR}" modules_install INSTALL_MOD_PATH="${WORK_DIR}/pkg" 2>&1 || error "Module installation failed"
  500. cp "${WORK_DIR}/arch/x86/boot/bzImage" "${WORK_DIR}/pkg/boot/vmlinuz-${latest_version#v}" || error "Failed to copy kernel image"
  501. cp "${WORK_DIR}/System.map" "${WORK_DIR}/pkg/boot/System.map-${latest_version#v}" || error "Failed to copy System.map"
  502. cp "${WORK_DIR}/.config" "${WORK_DIR}/pkg/boot/config-${latest_version#v}" || error "Failed to copy kernel config"
  503. cd "${WORK_DIR}/pkg" && tar czf "../${package_name}.txz" * 2>&1 || error "Package creation failed"
  504. cd ..
  505. log "Manual package created: ${package_name}.txz"
  506. PACKAGE_FILE="${WORK_DIR}/${package_name}.txz"
  507. fi
  508. ;;
  509. *)
  510. error "Unsupported distribution for packaging: $distro"
  511. ;;
  512. esac
  513.  
  514. log "Kernel build and packaging completed successfully"
  515. echo "$latest_version"
  516. return 0
  517. }
  518.  
  519. install_kernel() {
  520. log "Installing kernel..."
  521. local distro=$(detect_distro)
  522. local kernel_version=""
  523.  
  524. case "$distro" in
  525. debian)
  526. local deb_files=( "${WORK_DIR}"/*.deb )
  527. if [ ${#deb_files[@]} -gt 0 ]; then
  528. local latest_deb=$(ls -t "${WORK_DIR}"/*.deb 2>/dev/null | head -1)
  529. if [ -f "$latest_deb" ]; then
  530. kernel_version=$(basename "$latest_deb" | sed 's/linux-image-//' | sed 's/_.*$//' | sed 's/.*-//')
  531. log "Installing: $(basename $latest_deb)"
  532. dpkg -i "$latest_deb" 2>&1 || error "Failed to install Debian package"
  533. else
  534. error "No Debian packages found to install"
  535. fi
  536. else
  537. error "No Debian packages found to install"
  538. fi
  539. ;;
  540. slackware)
  541. local txz_files=( "${WORK_DIR}"/*.txz )
  542. if [ ${#txz_files[@]} -gt 0 ]; then
  543. local latest_txz=$(ls -t "${WORK_DIR}"/*.txz 2>/dev/null | head -1)
  544. if [ -f "$latest_txz" ]; then
  545. kernel_version=$(basename "$latest_txz" | sed 's/kernel-xanmod-//' | sed 's/\.txz$//')
  546. log "Installing: $(basename $latest_txz)"
  547. installpkg "$latest_txz" 2>&1 || error "Failed to install Slackware package"
  548. local modules_txz="${WORK_DIR}/kernel-modules-${kernel_version}.txz"
  549. if [ -f "$modules_txz" ]; then
  550. installpkg "$modules_txz" 2>&1 || log "Warning: Failed to install modules package"
  551. fi
  552. else
  553. error "No Slackware packages found to install"
  554. fi
  555. else
  556. error "No Slackware packages found to install"
  557. fi
  558. ;;
  559. *)
  560. error "Unsupported distribution for installation: $distro"
  561. ;;
  562. esac
  563.  
  564. if [ -z "$kernel_version" ]; then
  565. case "$distro" in
  566. debian)
  567. kernel_version=$(dpkg -l 2>/dev/null | grep -E 'linux-image-[0-9]+\.[0-9]+\.[0-9]+' | awk '{print $2}' | sort -V | tail -n1 | sed 's/linux-image-//')
  568. ;;
  569. slackware)
  570. kernel_version=$(ls -1 /boot/vmlinuz-* 2>/dev/null | sort -V | tail -n1 | sed 's|/boot/vmlinuz-||')
  571. ;;
  572. esac
  573. fi
  574.  
  575. if [ -n "$kernel_version" ]; then
  576. log "Installed kernel version: $kernel_version"
  577. update_bootloader "$kernel_version"
  578. update_initramfs "$kernel_version"
  579. else
  580. log "Warning: Could not determine installed kernel version"
  581. fi
  582.  
  583. log "Kernel installation completed successfully"
  584. return 0
  585. }
  586.  
  587. update_initramfs() {
  588. local kernel_version="$1"
  589. if [ -z "$kernel_version" ]; then
  590. log "No kernel version provided for initramfs update"
  591. return
  592. fi
  593.  
  594. log "Updating initramfs for kernel: $kernel_version"
  595. local distro=$(detect_distro)
  596.  
  597. case "$distro" in
  598. debian)
  599. if command -v update-initramfs &> /dev/null; then
  600. update-initramfs -u -k "$kernel_version" 2>&1 || log "Warning: update-initramfs failed"
  601. elif command -v mkinitramfs &> /dev/null; then
  602. mkinitramfs -o "/boot/initrd.img-$kernel_version" "$kernel_version" 2>&1 || log "Warning: mkinitramfs failed"
  603. else
  604. log "Warning: No initramfs tool found"
  605. fi
  606. ;;
  607. slackware)
  608. if command -v mkinitrd &> /dev/null; then
  609. mkinitrd -c -k "$kernel_version" 2>&1 || log "Warning: mkinitrd failed"
  610. else
  611. log "Warning: mkinitrd not found"
  612. fi
  613. ;;
  614. *)
  615. log "Warning: Unknown distribution for initramfs update"
  616. ;;
  617. esac
  618.  
  619. log "Initramfs update completed"
  620. }
  621.  
  622. update_grub() {
  623. if [ -z "$DISPLAY" ]; then
  624. return
  625. fi
  626.  
  627. if command -v grub-mkconfig &> /dev/null; then
  628. grub-mkconfig -o /boot/grub/grub.cfg 2>&1 || log "Warning: grub-mkconfig failed"
  629. elif command -v update-grub &> /dev/null; then
  630. update-grub 2>&1 || log "Warning: update-grub failed"
  631. else
  632. log "Warning: grub update command not found"
  633. fi
  634. }
  635.  
  636. update_bootloader() {
  637. local kernel_version="$1"
  638.  
  639. log "Updating bootloader..."
  640. local bootloader=$(detect_bootloader)
  641. local distro=$(detect_distro)
  642.  
  643. if [ -z "$kernel_version" ]; then
  644. case "$distro" in
  645. debian)
  646. kernel_version=$(dpkg -l 2>/dev/null | grep -E 'linux-image-[0-9]+\.[0-9]+\.[0-9]+' | awk '{print $2}' | sort -V | tail -n1 | sed 's/linux-image-//')
  647. ;;
  648. slackware)
  649. kernel_version=$(ls -1 /boot/vmlinuz-* 2>/dev/null | sort -V | tail -n1 | sed 's|/boot/vmlinuz-||')
  650. ;;
  651. *)
  652. kernel_version=$(uname -r)
  653. ;;
  654. esac
  655. fi
  656.  
  657. if [ -z "$kernel_version" ]; then
  658. log "ERROR: Could not determine kernel version for bootloader update"
  659. return 1
  660. fi
  661.  
  662. log "Detected bootloader: $bootloader"
  663. log "Kernel version: $kernel_version"
  664.  
  665. case "$bootloader" in
  666. grub2)
  667. log "Updating GRUB2 configuration..."
  668. if [ -f /etc/default/grub ] && grep -q "^GRUB_DISABLE_OS_PROBER=true" /etc/default/grub; then
  669. log "Note: OS_PROBER is disabled. Other OSes may not be detected."
  670. fi
  671. if command -v grub-mkconfig &> /dev/null; then
  672. grub-mkconfig -o /boot/grub/grub.cfg 2>&1 || error "Failed to update GRUB configuration"
  673. log "GRUB2 configuration updated"
  674. elif command -v update-grub &> /dev/null; then
  675. update-grub 2>&1 || error "Failed to update GRUB configuration"
  676. log "GRUB2 configuration updated (via update-grub)"
  677. else
  678. error "No GRUB2 update command found"
  679. fi
  680. ;;
  681. grub-legacy)
  682. log "Updating GRUB Legacy configuration..."
  683. if [ -f /boot/grub/menu.lst ]; then
  684. if ! grep -q "vmlinuz-${kernel_version}" /boot/grub/menu.lst; then
  685. local root_partition=$(grep "^kernel" /boot/grub/menu.lst | head -1 | sed 's/.*root=\([^ ]*\).*/\1/')
  686. [ -z "$root_partition" ] && root_partition="/dev/sda1"
  687. cat >> /boot/grub/menu.lst << EOF
  688.  
  689. title Linux ${kernel_version}
  690. root (hd0,0)
  691. kernel /boot/vmlinuz-${kernel_version} root=${root_partition} ro
  692. initrd /boot/initrd-${kernel_version}
  693. EOF
  694. log "Added new kernel entry to GRUB Legacy menu.lst"
  695. else
  696. log "Kernel already present in GRUB Legacy menu.lst"
  697. fi
  698. else
  699. log "Warning: GRUB Legacy menu.lst not found"
  700. fi
  701. ;;
  702. lilo)
  703. log "Updating LILO configuration..."
  704. if [ -f /etc/lilo.conf ]; then
  705. if ! grep -q "vmlinuz-${kernel_version}" /etc/lilo.conf; then
  706. local root_partition=$(grep "^root=" /etc/lilo.conf | head -1 | sed 's/root=//' | tr -d ' ')
  707. [ -z "$root_partition" ] && root_partition="/dev/sda1"
  708. cp /etc/lilo.conf /etc/lilo.conf.bak
  709. cat >> /etc/lilo.conf << EOF
  710.  
  711. image = /boot/vmlinuz-${kernel_version}
  712. root = ${root_partition}
  713. label = Linux-${kernel_version}
  714. read-only
  715. EOF
  716. log "Added new kernel entry to LILO configuration"
  717. else
  718. log "Kernel already present in LILO configuration"
  719. fi
  720. if command -v lilo &> /dev/null; then
  721. lilo 2>&1 || error "Failed to run lilo"
  722. log "LILO updated successfully"
  723. else
  724. error "lilo command not found"
  725. fi
  726. else
  727. error "LILO configuration file /etc/lilo.conf not found"
  728. fi
  729. ;;
  730. elilo)
  731. log "Updating ELILO configuration..."
  732. if [ -f /etc/elilo.conf ]; then
  733. if ! grep -q "vmlinuz-${kernel_version}" /etc/elilo.conf; then
  734. local root_partition=$(grep "^root=" /etc/elilo.conf | head -1 | sed 's/root=//' | tr -d ' ')
  735. [ -z "$root_partition" ] && root_partition="/dev/sda1"
  736. echo "
  737. image = /boot/vmlinuz-${kernel_version}
  738. root = ${root_partition}
  739. label = Linux-${kernel_version}
  740. read-only
  741. " >> /etc/elilo.conf
  742. log "Added new kernel entry to ELILO configuration"
  743. fi
  744. if command -v elilo &> /dev/null; then
  745. elilo 2>&1 || error "Failed to run elilo"
  746. log "ELILO updated successfully"
  747. else
  748. error "elilo command not found"
  749. fi
  750. else
  751. error "ELILO configuration file /etc/elilo.conf not found"
  752. fi
  753. ;;
  754. syslinux)
  755. log "Updating SYSLINUX configuration..."
  756. local syslinux_conf=""
  757. if [ -f /boot/extlinux/extlinux.conf ]; then
  758. syslinux_conf="/boot/extlinux/extlinux.conf"
  759. elif [ -f /boot/syslinux/syslinux.cfg ]; then
  760. syslinux_conf="/boot/syslinux/syslinux.cfg"
  761. fi
  762. if [ -n "$syslinux_conf" ]; then
  763. if ! grep -q "vmlinuz-${kernel_version}" "$syslinux_conf"; then
  764. echo "
  765. label Linux-${kernel_version}
  766. kernel /boot/vmlinuz-${kernel_version}
  767. append initrd=/boot/initrd-${kernel_version} root=/dev/sda1 ro
  768. " >> "$syslinux_conf"
  769. log "Added new kernel entry to $syslinux_conf"
  770. fi
  771. if command -v extlinux &> /dev/null && [ -f /boot/extlinux/extlinux.conf ]; then
  772. extlinux --update /boot/extlinux 2>&1 || log "Warning: extlinux update failed"
  773. fi
  774. else
  775. log "Warning: SYSLINUX configuration not found"
  776. fi
  777. ;;
  778. systemd-boot)
  779. log "Updating systemd-boot configuration..."
  780. local boot_dir=""
  781. if [ -d /boot/efi/EFI/systemd ]; then
  782. boot_dir="/boot/efi/EFI/systemd"
  783. elif [ -d /boot/EFI/systemd ]; then
  784. boot_dir="/boot/EFI/systemd"
  785. fi
  786. if [ -n "$boot_dir" ]; then
  787. mkdir -p "${boot_dir}/entries"
  788. local entry_file="${boot_dir}/entries/linux-${kernel_version}.conf"
  789. cat > "${entry_file}" << EOF
  790. title Linux ${kernel_version}
  791. linux /vmlinuz-${kernel_version}
  792. initrd /initrd-${kernel_version}
  793. options root=/dev/sda1 ro quiet
  794. EOF
  795. log "Created systemd-boot entry: ${entry_file}"
  796. if [ -f "${boot_dir}/loader/loader.conf" ]; then
  797. sed -i "s/default .*/default linux-${kernel_version}/" "${boot_dir}/loader/loader.conf" 2>/dev/null || true
  798. fi
  799. log "systemd-boot updated successfully"
  800. else
  801. log "Warning: systemd-boot directory not found"
  802. fi
  803. ;;
  804. efistub)
  805. log "EFISTUB detected. No bootloader to update."
  806. log "You may need to update your UEFI boot entries manually using efibootmgr."
  807. if command -v efibootmgr &> /dev/null; then
  808. log "Current EFI boot entries:"
  809. efibootmgr 2>&1 || true
  810. else
  811. log "efibootmgr not found. Install it to manage EFI entries."
  812. fi
  813. ;;
  814. unknown)
  815. log "Warning: Unknown bootloader. Please update your boot configuration manually."
  816. ;;
  817. *)
  818. log "Error: Unsupported bootloader: $bootloader"
  819. return 1
  820. ;;
  821. esac
  822.  
  823. log "Bootloader update completed"
  824. return 0
  825. }
  826.  
  827. cleanup_kernels() {
  828. log "Cleaning up old kernels..."
  829. local keep_count=${KEEP_OLD:-3}
  830. local distro=$(detect_distro)
  831.  
  832. local installed_kernels=()
  833. local current_kernel=$(uname -r)
  834.  
  835. case "$distro" in
  836. debian)
  837. installed_kernels=($(dpkg -l 2>/dev/null | grep -E 'linux-image-[0-9]+\.[0-9]+\.[0-9]+' | awk '{print $2}' | sort -V))
  838. ;;
  839. slackware)
  840. installed_kernels=($(ls -1 /boot/vmlinuz-* 2>/dev/null | sed 's|/boot/vmlinuz-||' | sort -V))
  841. ;;
  842. *)
  843. log "Warning: Unknown distribution for cleanup"
  844. return 1
  845. ;;
  846. esac
  847.  
  848. if [ ${#installed_kernels[@]} -eq 0 ]; then
  849. log "No kernels found to clean up"
  850. return 0
  851. fi
  852.  
  853. local keep_list=()
  854. local remove_list=()
  855. local count=0
  856.  
  857. for kernel in "${installed_kernels[@]}"; do
  858. if [ "$kernel" = "$current_kernel" ]; then
  859. keep_list+=("$kernel")
  860. continue
  861. fi
  862. if [ $count -lt $keep_count ]; then
  863. keep_list+=("$kernel")
  864. ((count++))
  865. else
  866. remove_list+=("$kernel")
  867. fi
  868. done
  869.  
  870. if [ ${#remove_list[@]} -eq 0 ]; then
  871. log "No old kernels to remove"
  872. return 0
  873. fi
  874.  
  875. local message="The following kernels will be removed:\n\n"
  876. for kernel in "${remove_list[@]}"; do
  877. message+=" - $kernel\n"
  878. done
  879. message+="\nKeep count: $keep_count (current + $((keep_count-1)) most recent)\n\nProceed with removal?"
  880.  
  881. if ! show_question "Cleanup Confirmation" "$message"; then
  882. log "Cleanup cancelled by user"
  883. return 0
  884. fi
  885.  
  886. for kernel in "${remove_list[@]}"; do
  887. log "Removing kernel: $kernel"
  888. case "$distro" in
  889. debian)
  890. if echo "$kernel" | grep -q "^linux-image-"; then
  891. dpkg --purge "$kernel" 2>&1 || log "Warning: Failed to remove $kernel"
  892. fi
  893. ;;
  894. slackware)
  895. removepkg "kernel-${kernel}" 2>&1 || log "Warning: Failed to remove kernel-$kernel"
  896. rm -rf "/lib/modules/${kernel}" 2>/dev/null
  897. rm -f "/boot/vmlinuz-${kernel}" "/boot/System.map-${kernel}" "/boot/config-${kernel}" 2>/dev/null
  898. ;;
  899. esac
  900. done
  901.  
  902. log "Removed ${#remove_list[@]} old kernels"
  903. return 0
  904. }
  905.  
  906. setup_cron() {
  907. local freq="${1:-$UPDATE_FREQ}"
  908. local script_path=$(realpath "$0" 2>/dev/null || echo "$0")
  909. local cron_cmd="${script_path} --auto-update"
  910.  
  911. crontab -l 2>/dev/null | grep -v "$cron_cmd" | crontab - 2>/dev/null || true
  912.  
  913. if [ "$freq" = "never" ]; then
  914. log "Cron job disabled"
  915. return 0
  916. fi
  917.  
  918. local cron_schedule=""
  919. case "$freq" in
  920. daily) cron_schedule="0 3 * * *" ;;
  921. weekly) cron_schedule="0 3 * * 0" ;;
  922. monthly) cron_schedule="0 3 1 * *" ;;
  923. *) log "Unknown frequency: $freq"; return 1 ;;
  924. esac
  925.  
  926. (crontab -l 2>/dev/null; echo "$cron_schedule $cron_cmd") | crontab - 2>/dev/null || {
  927. log "ERROR: Failed to install cron job"
  928. return 1
  929. }
  930.  
  931. log "Cron job installed: $freq updates at $cron_schedule"
  932. return 0
  933. }
  934. uninstall_kernel_menu() {
  935. log "Kernel uninstallation menu"
  936. local distro=$(detect_distro)
  937. local installed_kernels=()
  938. local current_kernel=$(uname -r)
  939.  
  940. case "$distro" in
  941. debian)
  942. installed_kernels=($(dpkg -l 2>/dev/null | grep -E 'linux-image-[0-9]+\.[0-9]+\.[0-9]+' | awk '{print $2}' | sort -V))
  943. ;;
  944. slackware)
  945. installed_kernels=($(ls -1 /boot/vmlinuz-* 2>/dev/null | sed 's|/boot/vmlinuz-||' | sort -V))
  946. ;;
  947. *)
  948. log "Warning: Unknown distribution"
  949. return 1
  950. ;;
  951. esac
  952.  
  953. if [ ${#installed_kernels[@]} -eq 0 ]; then
  954. show_msg "No Kernels" "No kernels found to uninstall."
  955. return 0
  956. fi
  957.  
  958. local menu_options=()
  959. for kernel in "${installed_kernels[@]}"; do
  960. local label="$kernel"
  961. if [ "$kernel" = "$current_kernel" ]; then
  962. label="$kernel (CURRENT)"
  963. fi
  964. menu_options+=("$kernel" "$label")
  965. done
  966. menu_options+=("back" "Return to main menu")
  967.  
  968. local choice=$(show_menu "Uninstall Kernel" "Select kernel to uninstall:" "${menu_options[@]}")
  969.  
  970. if [ "$choice" = "back" ] || [ -z "$choice" ]; then
  971. return 0
  972. fi
  973.  
  974. if [ "$choice" = "$current_kernel" ]; then
  975. show_msg "Cannot Remove" "You cannot remove the currently running kernel."
  976. return 0
  977. fi
  978.  
  979. if show_question "Confirm Removal" "Are you sure you want to remove kernel: $choice?"; then
  980. log "Removing kernel: $choice"
  981. case "$distro" in
  982. debian)
  983. dpkg --purge "linux-image-$choice" 2>&1 || log "Warning: Failed to remove $choice"
  984. ;;
  985. slackware)
  986. removepkg "kernel-$choice" 2>&1 || log "Warning: Failed to remove $choice"
  987. rm -rf "/lib/modules/$choice" 2>/dev/null
  988. rm -f "/boot/vmlinuz-$choice" "/boot/System.map-$choice" "/boot/config-$choice" 2>/dev/null
  989. ;;
  990. esac
  991.  
  992. update_bootloader "$(uname -r)"
  993. show_msg "Removal Complete" "Kernel $choice has been removed."
  994. fi
  995. }
  996.  
  997. main_menu() {
  998. while true; do
  999. local choice=$(show_menu "Xanmod4Slack v$VERSION" "Choose an action:" \
  1000. "update" "Check for kernel updates" \
  1001. "build" "Build and install new kernel" \
  1002. "cleanup" "Remove old kernels" \
  1003. "config" "Configure settings" \
  1004. "cron" "Manage automatic updates" \
  1005. "uninstall" "Uninstall a specific kernel" \
  1006. "quit" "Exit")
  1007.  
  1008. case "$choice" in
  1009. "update"|"Update")
  1010. local new_version=$(check_updates)
  1011. if [ $? -eq 0 ]; then
  1012. local current_version=$(uname -r)
  1013. send_notification "Kernel Update Available" "XanMod $new_version is available (current: $current_version)" "normal"
  1014. if show_question "Update Available" "XanMod $new_version is available.\nCurrent: $current_version\n\nBuild and install now?"; then
  1015. build_kernel
  1016. install_kernel
  1017. if [ "${AUTO_CLEANUP}" = "true" ]; then
  1018. cleanup_kernels
  1019. fi
  1020. show_msg "Complete" "Kernel $new_version installed successfully."
  1021. fi
  1022. else
  1023. show_msg "Up to Date" "Your XanMod kernel is current: $new_version"
  1024. fi
  1025. ;;
  1026. "build"|"Build")
  1027. if show_question "Confirm Build" "This will take a long time.\nProceed with kernel build?"; then
  1028. local new_version=$(build_kernel)
  1029. if [ $? -eq 0 ]; then
  1030. install_kernel
  1031. if [ "${AUTO_CLEANUP}" = "true" ]; then
  1032. cleanup_kernels
  1033. fi
  1034. show_msg "Complete" "Kernel $new_version built and installed successfully."
  1035. fi
  1036. fi
  1037. ;;
  1038. "cleanup"|"Cleanup")
  1039. cleanup_kernels
  1040. show_msg "Cleanup Complete" "Old kernels have been removed."
  1041. ;;
  1042. "config"|"Config")
  1043. local config_menu_choice=$(show_menu "Configuration" "Select setting to change:" \
  1044. "freq" "Update frequency (${UPDATE_FREQ:-$DEFAULT_UPDATE_FREQ})" \
  1045. "interface" "Interface type (${INTERFACE:-$DEFAULT_INTERFACE})" \
  1046. "keep" "Kernels to keep (${KEEP_OLD:-$DEFAULT_KEEP_OLD})" \
  1047. "auto" "Auto-update (${AUTO_UPDATE:-$DEFAULT_AUTO_UPDATE})" \
  1048. "clean" "Auto-cleanup (${AUTO_CLEANUP:-$DEFAULT_AUTO_CLEANUP})" \
  1049. "silent" "Silent notifications (${SILENT_NOTIFICATIONS:-$DEFAULT_SILENT_NOTIFICATIONS})" \
  1050. "hardware" "Hardware detection (${DETECT_HARDWARE:-$DEFAULT_DETECT_HARDWARE})" \
  1051. "march" "CPU optimization (${MARCH:-$DEFAULT_MARCH})" \
  1052. "back" "Return to main menu")
  1053.  
  1054. case "$config_menu_choice" in
  1055. "freq")
  1056. local new_freq=$(show_menu "Update Frequency" "Choose frequency:" \
  1057. "daily" "Check daily" \
  1058. "weekly" "Check weekly" \
  1059. "monthly" "Check monthly" \
  1060. "never" "Never check automatically")
  1061. if [ -n "$new_freq" ]; then
  1062. UPDATE_FREQ="$new_freq"
  1063. save_config
  1064. setup_cron "$UPDATE_FREQ"
  1065. log "Update frequency set to $UPDATE_FREQ"
  1066. fi
  1067. ;;
  1068. "interface")
  1069. local new_interface=$(show_menu "Interface Type" "Choose interface:" \
  1070. "auto" "Auto-detect" \
  1071. "gui" "GUI (zenity/kdialog)" \
  1072. "dialog" "Dialog (ncurses)" \
  1073. "text" "Text (CLI)")
  1074. if [ -n "$new_interface" ]; then
  1075. INTERFACE="$new_interface"
  1076. save_config
  1077. log "Interface set to $INTERFACE"
  1078. fi
  1079. ;;
  1080. "keep")
  1081. local new_keep=$(show_menu "Kernels to Keep" "Choose number to keep:" \
  1082. "1" "Keep 1 (most recent)" \
  1083. "2" "Keep 2" \
  1084. "3" "Keep 3" \
  1085. "4" "Keep 4" \
  1086. "5" "Keep 5")
  1087. if [[ "$new_keep" =~ ^[0-9]+$ ]]; then
  1088. KEEP_OLD="$new_keep"
  1089. save_config
  1090. log "Keeping $KEEP_OLD kernels"
  1091. fi
  1092. ;;
  1093. "auto")
  1094. local new_auto=$(show_menu "Auto-Update" "Enable automatic updates?" \
  1095. "true" "Yes" \
  1096. "false" "No")
  1097. if [ -n "$new_auto" ]; then
  1098. AUTO_UPDATE="$new_auto"
  1099. save_config
  1100. log "Auto-update set to $AUTO_UPDATE"
  1101. if [ "$AUTO_UPDATE" = "true" ]; then
  1102. setup_cron "$UPDATE_FREQ"
  1103. fi
  1104. fi
  1105. ;;
  1106. "clean")
  1107. local new_clean=$(show_menu "Auto-Cleanup" "Automatically remove old kernels after update?" \
  1108. "true" "Yes" \
  1109. "false" "No")
  1110. if [ -n "$new_clean" ]; then
  1111. AUTO_CLEANUP="$new_clean"
  1112. save_config
  1113. log "Auto-cleanup set to $AUTO_CLEANUP"
  1114. fi
  1115. ;;
  1116. "silent")
  1117. local new_silent=$(show_menu "Silent Notifications" "Silence update notifications?" \
  1118. "true" "Yes" \
  1119. "false" "No")
  1120. if [ -n "$new_silent" ]; then
  1121. SILENT_NOTIFICATIONS="$new_silent"
  1122. save_config
  1123. log "Silent notifications set to $SILENT_NOTIFICATIONS"
  1124. fi
  1125. ;;
  1126. "hardware")
  1127. local new_hardware=$(show_menu "Hardware Detection" "Detect hardware for optimized config?" \
  1128. "true" "Yes" \
  1129. "false" "No")
  1130. if [ -n "$new_hardware" ]; then
  1131. DETECT_HARDWARE="$new_hardware"
  1132. save_config
  1133. log "Hardware detection set to $DETECT_HARDWARE"
  1134. fi
  1135. ;;
  1136. "march")
  1137. local new_march=$(show_menu "CPU Optimization" "Choose optimization level:" \
  1138. "native" "Optimize for this CPU (-march=native)" \
  1139. "v3" "x86-64-v3 (Haswell/Excavator)" \
  1140. "v4" "x86-64-v4 (Skylake/Zen3)" \
  1141. "generic" "Generic x86-64")
  1142. if [ -n "$new_march" ]; then
  1143. MARCH="$new_march"
  1144. save_config
  1145. log "CPU optimization set to $MARCH"
  1146. fi
  1147. ;;
  1148. esac
  1149. ;;
  1150. "cron"|"Cron")
  1151. local cron_choice=$(show_menu "Automatic Updates" "Manage cron job:" \
  1152. "enable" "Enable automatic updates" \
  1153. "disable" "Disable automatic updates" \
  1154. "status" "Show current status" \
  1155. "back" "Return to main menu")
  1156.  
  1157. case "$cron_choice" in
  1158. "enable")
  1159. local freq_choice=$(show_menu "Update Frequency" "Choose frequency:" \
  1160. "daily" "Daily" \
  1161. "weekly" "Weekly" \
  1162. "monthly" "Monthly")
  1163. if [ -n "$freq_choice" ]; then
  1164. UPDATE_FREQ="$freq_choice"
  1165. save_config
  1166. setup_cron "$freq_choice"
  1167. show_msg "Cron Enabled" "Automatic updates enabled: $freq_choice"
  1168. fi
  1169. ;;
  1170. "disable")
  1171. setup_cron "never"
  1172. UPDATE_FREQ="never"
  1173. save_config
  1174. show_msg "Cron Disabled" "Automatic updates disabled."
  1175. ;;
  1176. "status")
  1177. local cron_status=$(crontab -l 2>/dev/null | grep "$(realpath "$0" 2>/dev/null || echo "$0")" || echo "No cron job found")
  1178. show_msg "Cron Status" "Current cron jobs:\n\n$cron_status"
  1179. ;;
  1180. esac
  1181. ;;
  1182. "uninstall"|"Uninstall")
  1183. uninstall_kernel_menu
  1184. ;;
  1185. "quit"|"Quit")
  1186. show_msg "Goodbye" "Exiting Xanmod4Slack."
  1187. exit 0
  1188. ;;
  1189. *)
  1190. exit 0
  1191. ;;
  1192. esac
  1193.  
  1194. sleep 2
  1195. done
  1196. }
  1197.  
  1198. # --- Main Execution ---
  1199.  
  1200. case "$1" in
  1201. --auto-update)
  1202. log "Running automatic update check..."
  1203. load_config
  1204. if [ "${AUTO_UPDATE}" != "true" ]; then
  1205. log "Auto-update is disabled in configuration. Exiting."
  1206. exit 0
  1207. fi
  1208.  
  1209. local new_version=$(check_updates)
  1210. if [ $? -eq 0 ]; then
  1211. send_notification "Kernel Update Available" "XanMod $new_version is available. Building now..." "normal"
  1212. build_kernel
  1213. install_kernel
  1214. if [ "${AUTO_CLEANUP}" = "true" ]; then
  1215. cleanup_kernels
  1216. fi
  1217. send_notification "Kernel Update Complete" "XanMod $new_version installed successfully." "low"
  1218. log "Automatic update completed successfully"
  1219. fi
  1220. exit 0
  1221. ;;
  1222. --force-update)
  1223. log "Forcing kernel update..."
  1224. load_config
  1225. local new_version=$(build_kernel)
  1226. if [ $? -eq 0 ]; then
  1227. install_kernel
  1228. if [ "${AUTO_CLEANUP}" = "true" ]; then
  1229. cleanup_kernels
  1230. fi
  1231. send_notification "Kernel Update Complete" "XanMod $new_version installed successfully." "low"
  1232. fi
  1233. exit 0
  1234. ;;
  1235. --help|-h)
  1236. echo "Xanmod4Slack v$VERSION - Universal XanMod Kernel Builder"
  1237. echo ""
  1238. echo "Usage: $0 [OPTIONS]"
  1239. echo " --auto-update Run automatic update check and build (cron mode)"
  1240. echo " --force-update Force update to latest version"
  1241. echo " --help, -h Show this help message"
  1242. echo " No options Run interactive menu"
  1243. echo ""
  1244. echo "Configuration file: $CONFIG_FILE"
  1245. echo "Log file: $LOG_FILE"
  1246. echo "Work directory: $WORK_DIR"
  1247. exit 0
  1248. ;;
  1249. *)
  1250. load_config
  1251. if [ $# -eq 0 ]; then
  1252. main_menu
  1253. else
  1254. echo "Unknown option: $1"
  1255. echo "Try '$0 --help' for usage information."
  1256. exit 1
  1257. fi
  1258. ;;
  1259. esac
  1260.  
  1261. exit 0
  1262.  
Advertisement
Add Comment
Please, Sign In to add comment