├── README.md └── deb-builder.sh /README.md: -------------------------------------------------------------------------------- 1 | # deb-builder 2 | Super simple bash script to create Debian packages 3 | 4 | ### Running 5 | Warning, running as root may cause errors. 6 | 7 | make sure `git` and `dpkg-dev` are installed. 8 | 9 | ``` 10 | # setup 11 | git clone https://github.com/ryanfortner/deb-builder.git 12 | cd deb-builder 13 | chmod +x deb-builder.sh 14 | 15 | # run deb builder 16 | ./deb-builder.sh 17 | ``` 18 | 19 | ### Notes 20 | - Be sure to have a directory before running the script containing the files you want to be in the deb. 21 | - For example, if I wanted a script in /usr/bin to be in my deb, I would make a directory, and make another two subdirectories, and place my file within `pre-dir/usr/bin/`. 22 | - When you get to the control file creation part, you may be able to exclude certain fields. Check [this page](https://www.debian.org/doc/debian-policy/ch-controlfields.html) for optional and required entries. 23 | - Open an issue on this repository if you encounter any problems. 24 | -------------------------------------------------------------------------------- /deb-builder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Any packages specified here will be installed if not installed already. 4 | DEPENDS="dpkg-dev" 5 | 6 | DATA_DIR="${HOME}/deb-builder/data" 7 | 8 | # Color variables (thanks @Itai-Nelken) 9 | bold="\e[1m" 10 | red="\e[31m" 11 | green="\e[32m" 12 | yellow="\e[33m" 13 | light_cyan="\e[96m" 14 | normal="\e[0m" 15 | 16 | function error { 17 | echo -e "\e[91m$1\e[39m" 18 | exit 1 19 | } 20 | 21 | # Define control c function, intialised when ctrl c is pressed 22 | function ctrl_c() { 23 | break &>/dev/null 24 | exit 1 25 | } 26 | # Have the ctrl_c function run if ctrl+c is pressed 27 | trap "ctrl_c" 2 28 | 29 | echo "deb-builder.sh: script to create a deb file." 30 | echo "by @ryanfortner on GitHub" 31 | 32 | if [ "$EUID" = 0 ]; then 33 | error "This script can't be run with root." 34 | fi 35 | 36 | mkdir -p $DATA_DIR 37 | 38 | # ask user to input the directory with the files. 39 | # the directory should not cointain a DEBIAN folder or a control file, only the files that are to be installed into the system and their target directory. 40 | read -rp "Enter the full directory with the desired contents for the deb: " DIRECTORYB 41 | if [ ! -d "$DIRECTORYB" ]; then 42 | error "Sorry, that directory can't be located. Try running the script again." 43 | else 44 | echo "continuing." 45 | fi 46 | 47 | # install dependencies with apt 48 | sudo apt-get update || error "Failed to update apt lists. Check the errors above." 49 | sudo apt-get install $DEPENDS -y || error "Failed to install $DEPENDS" 50 | 51 | cd $DATA_DIR 52 | NOWDAY="$(printf '%(%Y-%m-%d)T\n' -1)" || error "Failed to get current date." 53 | rm -rf $NOWDAY || sudo rm -rf $NOWDAY 54 | mkdir $NOWDAY || error "Failed to make $NOWDAY directory." 55 | cd $NOWDAY 56 | 57 | # copy contents from source folder into the deb-builder/data/nowday folder 58 | cp -r ${DIRECTORYB}/* . || sudo cp -r ${DIRECTORYB}/* . 59 | 60 | echo "Review the contents of the folder. If it's not correct, answer 'n'. If the contents are correct, answer 'y'." 61 | echo "" 62 | ls ${DATA_DIR}/${NOWDAY} 63 | echo "" 64 | read -rp "Continue (y/n)? " choicea 65 | case "$choicea" in 66 | y|Y ) CONTINUE=1 ;; 67 | n|N ) CONTINUE=0 ;; 68 | * ) echo "Invalid input" ;; 69 | esac 70 | if [[ "$CONTINUE" == 1 ]]; then 71 | echo "Continuing." 72 | elif [[ "$CONTINUE" == 0 ]]; then 73 | error "Exiting." 74 | fi 75 | 76 | echo "Creating control file." 77 | read -rp "Maintainer? (Usually this is in the form of 'Name ') " MAINTAINER 78 | read -rp "Short summary? " SUMMARY 79 | read -rp "Name? Usually this is the package name. " NAME 80 | read -rp "Description? " DESCRIPTION 81 | read -rp "Version? " VERSIONA 82 | read -rp "License? (example: gpl) " LICENSE 83 | read -rp "Architecture? (armhf, all, arm64, etc.) " ARCHA 84 | read -rp "Provides? (what packages does this package provide) " PROVIDES 85 | read -rp "Priority? (usually 'optional') " PRIORITY 86 | read -rp "Section? (example: unknown, utils, etc.) " SECTION 87 | read -rp "Depends? (packages needed to install/run) " DEPENDSAB 88 | read -rp "Recommends? (packages suggested to install but not required) " RECOMMENDS 89 | read -rp "Conflicts? (packages that can't be alongside this package) " CONFLICTS 90 | read -rp "Package? (should be the same as the name in most cases) " PACKAGE 91 | 92 | mkdir -p DEBIAN && cd DEBIAN 93 | 94 | echo "Maintainer: ${MAINTAINER} 95 | Summary: ${SUMMARY} 96 | Name: ${NAME} 97 | Description: ${DESCRIPTION} 98 | Version: ${VERSIONA} 99 | License: ${LICENSE} 100 | Architecture: ${ARCHA} 101 | Provides: ${PROVIDES} 102 | Priority: ${PRIORITY} 103 | Depends: ${DEPENDSAB} 104 | Section: ${SECTION} 105 | Recommends: ${RECOMMENDS} 106 | Conflicts: ${CONFLICTS} 107 | Package: ${PACKAGE}" > control 108 | 109 | sudo chmod 775 control || error "Failed to change control file permissions!" 110 | 111 | # go two directories up 112 | cd ../.. 113 | 114 | echo "Last chance: review the contents of the folder. If it's not correct, answer 'n'. If the contents are correct, answer 'y'." 115 | echo "" 116 | ls ${DATA_DIR}/${NOWDAY} 117 | echo "" 118 | read -rp "Continue (y/n)? " choiceab 119 | case "$choiceab" in 120 | y|Y ) CONTINUEB=1 ;; 121 | n|N ) CONTINUEB=0 ;; 122 | * ) echo "Invalid input" ;; 123 | esac 124 | if [[ "$CONTINUEB" == 1 ]]; then 125 | echo "Continuing." 126 | elif [[ "$CONTINUEB" == 0 ]]; then 127 | error "Exiting." 128 | fi 129 | 130 | DEBDIR="$(pwd)" 131 | 132 | read -rp "Name of the deb file? (ex: helloworld_0.1.0_armhf.deb) " DEBNAME 133 | 134 | echo "Your deb will be built at $DEBDIR" 135 | 136 | echo "Building deb..." 137 | dpkg-deb --build $NOWDAY/ ${DEBNAME} || error "Failed to create ${DEBNAME}" 138 | 139 | echo "Done!" 140 | --------------------------------------------------------------------------------