#!/bin/bash # # V9.0 # # EZ Installer. Run from the bash command line: # # curl -L https://raw.githubusercontent.com/gitbls/sdm/master/EZsdmInstaller | bash # # $1: Branch to install from (D:master) # $2: Target install directory (D:/usr/local/sdm) # ** To use either of these arguments you must download this script to your system # and start it from the command line: # e.g., bash$ EZsdmInstaller V9.0 # Install V9.0 release to /usr/local/sdm # bash$ EZsdmInstaller "" /home/$(whoami)/sdm # Install master branch to /home/$(whoami)/sdm # $3: Source Github repo (D:gitbls/sdm) # # NOTE: Using this version on the master branch requires that the master branch is updated to V9.0 (NYI) # # At the moment requires apt-based package installs. Easy to fix, of course. It's only code... # function errexit() { echo "$1" exit 1 } function askyn() { local ans echo -n "$1" '[y/n]? ' ; read $2 ans case "$ans" in y*|Y*) return 0 ;; *) return 1 ;; esac } function getosdistro() { local osdistro osversion if [ -f "/etc/os-release" ] then osdistro=$(grep ^ID= /etc/os-release | (IFS='='; read a b ; echo $b)) osversion=$(grep ^VERSION_ID= /etc/os-release | (IFS='='; read a b ; echo $b)) [ "$osversion" == "" ] && osversion=$(grep ^VERSION= /etc/os-release | (IFS='='; read a b ; echo $b)) else osdistro="unknown" osversion="unknown" fi osdistro=${osdistro%\"} #Strip leading and trailing quotes osdistro=${osdistro#\"} osdistro=${osdistro,,} #Lower case [ "$osdistro" == "raspbian" ] && osdistro="raspios" osversion=${osversion%\"} osversion=${osversion#\"} echo "$osdistro:$osversion" } # # Check OS Distro and version # myscript="$0 $@" #IFS=":" read osdistro osversion <<< $(getosdistro) [ "$(type -p apt)" == "" ] && errexit "? apt not found; cannot install on this system" # # Create directories and download sdm # [ "$1" == "" ] && branch="master" || branch="$1" [ "$2" != "" ] && dir="$2" || dir="/usr/local/sdm" [ "$3" != "" ] && repo="$3" || repo="gitbls/sdm" if [ "$SDMLAN" != "" ] then src=$SDMLAN curl="scp" else src="https://github.com/$repo/raw/$branch" curl="curl" fi sudo="" if [ -d $dir ] then [ ! -w $dir ] && sudo="sudo" # Directory exists; do we have write access? else [ ! -w ${dir%/*} ] && sudo="sudo" # Directory does not exist; do we have write access to where it will be created? fi echo "* Make directory '$dir' and download sdm files to it" $sudo mkdir -p $dir $dir/1piboot $dir/plugins $dir/local-plugins dlerrors=0 for f in sdm sdm-phase0 \ sdm-phase1 \ sdm-cparse \ sdm-cmdsubs \ sdm-readparams \ sdm-rpcsubs \ sdm-firstboot \ sdm-cryptconfig \ sdmcryptfs \ sdm-apt-cacher \ sdm-apt \ sdm-customphase \ sdm-apps-example \ sdm-xapps-example \ sdm-cportal \ sdm-logmsg \ sdm-gburn \ plugins/apps \ plugins/apt-addrepo \ plugins/apt-cacher-ng \ plugins/apt-file \ plugins/bootconfig \ plugins/btwifiset \ plugins/chrony \ plugins/clockfake \ plugins/copydir \ plugins/copyfile \ plugins/cryptroot \ plugins/disables \ plugins/explore \ plugins/extractfs \ plugins/graphics \ plugins/hotspot \ plugins/imon \ plugins/knockd \ plugins/L10n \ plugins/lxde \ plugins/mkdir \ plugins/ndm \ plugins/network \ plugins/parted \ plugins/piapps \ plugins/pistrong \ plugins/postfix \ plugins/quietness \ plugins/raspiconfig \ plugins/runatboot \ plugins/rxapp \ plugins/samba \ plugins/serial \ plugins/sdm-plugin-template \ plugins/system \ plugins/trim-enable \ plugins/ufw \ plugins/user \ plugins/vnc \ plugins/wificonfig \ plugins/wsdd \ 1piboot/1piboot.conf do echo "Downloading '$f' to '$dir/$f'" if [ "$SDMLAN" == "" ] then $sudo curl --fail --silent --show-error -L $src/$f -o $dir/$f sts=$? else scp $SDMLAN/$f $dir/$f sts=$? fi if [ ! -f $dir/$f -o $sts -ne 0 ] then echo "? Error downloading '$src/$f' to $dir" dlerrors=$((dlerrors+1)) fi done if [ "$dir" == "/usr/local/sdm" ] then echo "* Create link for sdm: /usr/local/bin/sdm" [ -L /usr/local/bin/sdm ] && $sudo rm -f /usr/local/bin/sdm $sudo ln -s /usr/local/sdm/sdm /usr/local/bin/sdm fi $sudo chmod -R 755 $dir/* $sudo chmod 644 $dir/{sdm-apps-example,sdm-xapps-example} $dir/1piboot/1piboot.conf $sudo mkdir -p /etc/sdm $sudo chmod 700 /etc/sdm $sudo rm -f /etc/sdm/sdm-readparams /etc/sdm/cparams.old $sudo cp -a $dir/sdm-readparams /etc/sdm $sudo rm -f /etc/sdm/cparams.old $sudo mv /etc/sdm/cparams /etc/sdm/cparams.old 2>/dev/null cat </dev/null sdmdir:/usr/local/sdm src:/usr/local/sdm plugindebug:0 EOF pkgs="binfmt-support gdisk parted qemu-user-static rsync systemd-container" echo "* Ensure required packages are installed: $pkgs" [[ $EUID -ne 0 ]] && sudo="sudo" $sudo apt-get install --yes --no-install-recommends $pkgs echo "" if [ "$dir" == "/usr/local/sdm" -a "$(type -p sdm)" != "" ] then echo "* Invoke sdm with 'sudo sdm'" else echo "* Invoke sdm with 'sudo $dir/sdm'" echo "* You can make an ease-of-use link with: sudo ln -s $dir/sdm /usr/local/bin/sdm" echo " so you can invoke sdm with 'sudo sdm'" fi echo $" Complete sdm documentation: https://github.com/$repo/tree/$branch/Docs " if [ $dlerrors -ne 0 ] then echo $"%% The sdm download was not complete $dlerrors file(s) not downloaded This must be corrected before you can use sdm If you need help, open an issue at https://github.com/$repo " fi