Skip to content

Commit

Permalink
Merge pull request #6 from framps/installer
Browse files Browse the repository at this point in the history
Add simple installer for rpi-clone
  • Loading branch information
geerlingguy authored Feb 13, 2024
2 parents 2fb52fc + 5e84596 commit 5fb247b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ only Debian packages with apt-get.

#### On a Raspberry Pi:
```
Either
$ curl https://github.com/geerlingguy/rpi-clone/blob/master/install | sudo bash
or
$ git clone https://github.com/geerlingguy/rpi-clone.git
$ cd rpi-clone
$ sudo cp rpi-clone rpi-clone-setup /usr/local/sbin
Expand Down
53 changes: 53 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Simple installer for rpi-clone
#
# Downloads and installs rpi-clone and rpi-clone-setup into /usr/local/bin
#
# Command to use to install rpi-clone:
# curl https://github.com/geerlingguy/rpi-clone/blob/master/install | sudo bash
#
# rpi-clone is Copyright (c) 2018-2019 Bill Wilson
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted under the conditions of the BSD LICENSE file at
# the rpi-clone github source repository:
# https://github.com/billw2/rpi-clone

# This updated code is located in a fork of Bill Willsons git repository
# at https://github.com/geerlingguy/rpi-clone

set -uo pipefail

readonly PACKAGE="rpi-clone"
readonly DOWNLOAD_REPOSITORY="https://github.com/geerlingguy/rpi-clone/blob/master"
readonly DOWNLOAD_REPOSITORY_4_MESSAGE="$(sed 's@/blob/master@@' <<< "$DOWNLOAD_REPOSITORY")"
readonly FILES_2_DOWNLOAD"=rpi-clone rpi-clone-setup"
readonly TMP_DIR=$(mktemp -d)
readonly INSTALLATION_DIR="/usr/local/sbin"

trap "{ rmdir $TMP_DIR &>/dev/null; }" SIGINT SIGTERM EXIT

pwd=$PWD
cd $TMP_DIR

echo "Installing $PACKAGE ..."

for file in $FILES_2_DOWNLOAD; do

echo -n "Downloading $file from $DOWNLOAD_REPOSITORY_4_MESSAGE ... "
http_code=$(curl -w "%{http_code}" -L -s $DOWNLOAD_REPOSITORY/$file -o $file)
(( $? )) && { echo "Curl failed"; exit 1; }
[[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
echo "done"
echo -n "Installing $file into $INSTALLATION_DIR ... "
sudo chmod +x $file
(( $? )) && { echo "chmod failed"; exit 1; }
sudo mv $file $INSTALLATION_DIR
(( $? )) && { echo "mv failed"; exit 1; }
echo "done"

done

echo "$PACKAGE installed"
cd $pwd

0 comments on commit 5fb247b

Please sign in to comment.