install-deb.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. # install-deb.sh
  3. #
  4. # Script for installing deb files on any operating system.
  5. # WARNING: Read the warning below before installing.
  6. # Usage: ./install-deb.sh /path/to/example.deb
  7. # License: CC0
  8. # Show warning
  9. echo ''
  10. echo ' ┌─────────────────────────────── WARNING! ───────────────────────────────┐'
  11. echo " │ This script just extracts the package files to your system's / │"
  12. echo ' │ directory. It does not install dependencies or adopt package to your │'
  13. echo ' │ init system. It will not update by itself with the system, so you have │'
  14. echo ' │ to update it manually when a new version comes along. │'
  15. echo ' │ Depending on what distro you are on, it may fail or break your system. │'
  16. echo ' │ Please consider backing up your system. You have been warned. │'
  17. echo ' └────────────────────────────────────────────────────────────────────────┘'
  18. echo ''
  19. # Variables
  20. TMPPATH='/tmp/debextract'
  21. DEBFILEPATH=$(realpath $1)
  22. FAIL=0
  23. # Check requirements and input file
  24. if [ -z "$(command -v ar)" ]; then
  25. echo '== This script uses ar command from binutils. Please install binutils package and continue.'
  26. FAIL=51
  27. fi
  28. if [ -z "$(command -v tar)" ]; then
  29. echo '== This script uses tar command. Please install tar package and continue.'
  30. FAIL=52
  31. fi
  32. if [ -z "$1" ]; then
  33. echo '== No deb file has been passed. Please run this script with a deb filename. e.g.'
  34. echo " $0 example-1.2.3.deb"
  35. FAIL=53
  36. fi
  37. if [ ! -f "$1" ]; then
  38. echo '== The deb file '"$1"' does not exist.'
  39. FAIL=54
  40. fi
  41. if [ "$FAIL" -gt 0 ]; then
  42. exit "$FAIL"
  43. fi
  44. # Make temporary directory
  45. mkdir -p "$TMPPATH"
  46. # If it had files from previous attempt, delete them
  47. rm -rf "$TMPPATH/*"
  48. # cd into temporary path
  49. cd "$TMPPATH"
  50. # Extract data from deb
  51. echo '== Extracting data.tar.xz from deb...'
  52. echo '== This is just extracting, you will be asked to install later...'
  53. ar -x "$DEBFILEPATH" data.tar.xz
  54. # Prompt to install
  55. echo -n '== Data inside deb has been extracted and is ready to be installed. Are you sure you want to install it on this system? [y/N] '
  56. read answer
  57. # Install (or not) based on answer
  58. if [ "$answer" != "${answer#[Yy]}" ] ;then
  59. if [[ $(id -u) -ne 0 ]] ; then
  60. echo '== Installing...'
  61. tar xvf data.tar.xz -C /
  62. else
  63. echo '== The script was not run as root user or using sudo. Trying to run with sudo...'
  64. sudo tar xvf data.tar.xz -C /
  65. fi
  66. echo '== Deleting temporary files...'
  67. rm -rf "$TMPPATH/*"
  68. echo '== Installation finished. Please make sure you install all the dependencies manually before running the program.'
  69. else
  70. echo '== Skipping installation. Exiting...'
  71. exit 45
  72. fi