Juicy lil' bytes

A Generic Reusable Install Shell Script That You Can Modify for Your Projects

Here is a generic bash shell script for single file installs that you can easily modify and include in your own projects.

Description

The script confirms that the target directory path exists and copies the developer-specified file into that path. If it does not exist, it creates the directory path and then copies the file into the new directory.

Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
# Scriptacular - install.sh
# Copyright 2013 Christopher Simpkins
# MIT License

TARGET_DIR="path/to/the/install/directory"
INSTALL_FILE="your-file.txt"
SUCCESS_MSG="Sexy message for user goes here!"

if [ -d "$TARGET_DIR" ]; then
  cp "$INSTALL_FILE" "$TARGET_DIR"
  echo "$SUCCESS_MSG"
else
  echo "Creating the install directory path..."
  mkdir -p "$TARGET_DIR"
  echo "Done. Installing '$INSTALL_FILE'..."
  cp "$INSTALL_FILE" "$TARGET_DIR"
  echo "$SUCCESS_MSG"
fi
exit 0

Save the script as install.sh.

Customization

  1. Modify TARGET_DIR with the target install directory
  2. Modify INSTALL_FILE with the path to the file that is to be installed
  3. Modify SUCCESS_MSG with the message to present to the user after a successful install

Use

The user will need navigate to the directory that contains install.sh in your release and set the file permissions so that they can execute the script:

1
chmod 744 install.sh

and then use it with the following command:

1
./install.sh

Script Repository

The script is available on GitHub.

License

MIT license