Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c0e1393
install pkgin if not present, first try
gdelpierre Jan 18, 2016
c82e39f
indent ; rename some variables ; add some definers
gdelpierre Jan 18, 2016
5066da8
change some check ; rename some variables
gdelpierre Jan 18, 2016
5d46d8e
rename egrep to _egrep and curl to _curl
gdelpierre Jan 18, 2016
4b4fbe1
according to joyent's website, we do not need that
gdelpierre Jan 18, 2016
f468176
add egrep
gdelpierre Jan 19, 2016
64fe1fa
install 3rd party pkgs
gdelpierre Jan 19, 2016
21067c2
fix lots of stuff after iMil review
gdelpierre Jan 20, 2016
b23154b
indent EOF ; use loop instead of define several time the same kind of…
gdelpierre Jan 20, 2016
395d5cd
fix
gdelpierre Jan 20, 2016
91d82b7
revert rsync
gdelpierre Jan 20, 2016
d1c10fb
missing $
gdelpierre Jan 20, 2016
3daf8be
test before rm ; ask confirm if gpg failed
gdelpierre Jan 21, 2016
cb1c5df
teasing...
gdelpierre Jan 21, 2016
b04b857
add manpath, path on osx
gdelpierre Jan 21, 2016
90bfcb5
fix lowercase
gdelpierre Jan 21, 2016
3f79e21
fix
gdelpierre Jan 21, 2016
62a68c1
pkgin installation on netbsd
gdelpierre Jan 21, 2016
c271a1c
add pkgin installation on netbsd ; add confirm function ; clean sheba…
gdelpierre Jan 22, 2016
8cbf711
set up manpath and path ; typo
gdelpierre Jan 22, 2016
f1c236c
add check
gdelpierre Jan 22, 2016
45b23dd
it's better
gdelpierre Jan 22, 2016
821c6d3
move confirm to helpers.sh
gdelpierre Jan 28, 2016
110df65
Merge branch 'master' into feature/install_pkgin
gdelpierre Jan 28, 2016
39c90a7
fix localbase
gdelpierre Feb 3, 2016
2ef1d85
fix typo
gdelpierre Feb 3, 2016
3bba003
fix typo variable name
gdelpierre Feb 3, 2016
c085683
fix lots of stuff, now it works under centos ! \o/
gdelpierre Feb 4, 2016
6f231ca
add binary
gdelpierre Feb 4, 2016
8a614ff
fix install on osx ; re-organize ; fix typo ; fix tests
gdelpierre Feb 8, 2016
39daa2d
add bashrc_profile if not exists
gdelpierre Feb 9, 2016
0fb4097
correct test
gdelpierre Feb 12, 2016
c28f40c
nianiania posix grml
gdelpierre Feb 15, 2016
853573c
correct test ; re-define pkgin after installation
gdelpierre Feb 15, 2016
97f4c20
re-organize
gdelpierre Feb 15, 2016
7aea76e
CHUT
gdelpierre Feb 15, 2016
32134e5
define some usefull vars
gdelpierre Feb 16, 2016
5f889f9
fix bootstrap sha ; check id first
gdelpierre Feb 16, 2016
0ed36aa
define pkg_add first time ; add PKG_PATH if not define
gdelpierre Feb 19, 2016
6e4e2b5
fix typo
gdelpierre Feb 19, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions include/define.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
awk=$(which awk)
cat=$(which cat)
sh=$(which sh)
chmod=$(which chmod)
chown=$(which chown)
chroot=$(which chroot)
curl=$(which curl)
cut=$(which cut)
cp=$(${debug}which cp)
date=$(which date)
echo=$(which echo)
egrep=$(which egrep)
grep=$(which grep)
groupadd=$(which groupadd)
gpg=$(which gpg)
id=$(which id)
ifconfig=$(which ifconfig)
ls=$(which ls)
od=$(which od)
pax="${debug}$(which pax) -rwpe"
cp=$(${debug}which cp)
chown=$(which chown)
chmod=$(which chmod)
awk=$(which awk)
ping=$(which ping)
pkgin="$(which pkgin)"
pkg_add="$(which pkg_add)"
pkg_info="$(which pkg_info)"
mkdir="$(which mkdir) -p"
mount=$(which mount)
rm="$(which rm) -f"
rsync="$(which rsync) -av"
sh=$(which sh)
shasum=$(which shasum)
sort=$(which sort)
grep=$(which grep)
sudo=$(which sudo)
sleep=$(which sleep)
tar=$(which tar)
mkdir="$(which mkdir) -p"
touch=$(which touch)
rm="$(which rm) -f"
ls=$(which ls)
od=$(which od)
tr=$(which tr)
mount=$(which mount)
umount=$(which umount)
curl=$(which curl)
ifconfig=$(which ifconfig)
useradd=$(which useradd)
groupadd=$(which groupadd)
ping=$(which ping)
ARCH=$(uname -m)
DDATE=$(date +%Y%m%d)
SHELLRC=~/.$(${echo} $SHELL | ${awk} -F/ '{print$NF}')rc
PKGIN_VARDB="$(${pkg_info} -QVARBASE pkgin)/db/pkgin"
OS=$(uname -s)

# columns sizes for ls
Expand Down
24 changes: 24 additions & 0 deletions include/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,27 @@ epoch_to_hms()

printf "%02d:%02d:%02d\n" $h $m $s
}

confirm()
{
confirm_msg="${1}"
err_msg="${2}"
default_msg="${3}"
while true
do
read -p "${confirm_msg}" yn
case ${yn} in
[y])
break
;;
[N])
printf "${err_msg}\n"
exit 1
;;
*)
confirm_msg=${default_msg}
continue
;;
esac
done
}
210 changes: 210 additions & 0 deletions include/install_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
ARCH=$(uname -m)
OS=$(uname -s)

case ${OS} in
[Dd]arwin)
# Try to find a real way to define if another packages manager is installed.
# According to their own documentation.
if [ -f /usr/local/bin/brew ]; then
printf "Homebrew detected, pkgsrc can conflict with\n"
exit 1
fi
# According to their own documentation.
if [ -f /opt/local/bin/port ]; then
printf "MacPorts detected, pkgsrc can conflict with\n"
exit 1
fi

os="osx"
;;

[Ll]inux)
# sha1sum under Linux
shasum="$(which sha1sum)"
os="linux"
;;

NetBSD)
;;

*)
printf "System not yet supported, sorry.\n"
exit 1
;;
esac

install_pkgin_netbsd()
{
ver="$(uname -r)"
pkg_add=$(which pkg_add)

repository="http://ftp.netbsd.org/pub/pkgsrc/packages/${OS}/${ARCH}/${ver}/All"
pkgin_conf="/usr/pkg/etc/pkgin/repositories.conf"

[ -z "${PKG_PATH}" ] && PKG_PATH="${repository}" && export PKG_PATH

if ! ${pkg_add} pkgin ; then
printf "An error has occured during pkgin's installation!\n"
exit 1
fi

if [ ! -f ${pkgin_conf} ] ; then
echo ${repository} > ${pkgin_conf}
fi

pkgin=$(which pkgin)

${pkgin} -y update
}

install_pkgin()
{
. ${include}/helpers.sh

# We define here binaries because define.sh not yet loaded.
_curl="$(which curl) --silent --max-time 5 --connect-timeout 2"
_egrep="$(which egrep) -o"
cut=$(which cut)
gpg=$(which gpg 2>/dev/null)
rm=$(which rm)
tar=$(which tar)

# Unset until pkg_info / pkgin are installed.
PKGIN_VARDB="/var/db/pkgin"

joyent_base_url="https://pkgsrc.joyent.com/"
bootstrap_install_url="${joyent_base_url}install-on-${os}/"
bootstrap_doc="/tmp/pkgin_install.txt"
${_curl} -o ${bootstrap_doc} ${bootstrap_install_url}
bootstrap_url=$(${_egrep} -m1 "${joyent_base_url}packages/${OS}/bootstrap/.*.${ARCH}.tar.gz" ${bootstrap_doc})
strip_bootstrap_url="${bootstrap_url#curl -Os }"

read bootstrap_hash bootstrap_tar <<-EOF
$(${_egrep} "[0-9a-z]{32}.+${ARCH}.tar.gz" ${bootstrap_doc})
EOF

if ! fetch_localbase="$(${_curl} ${strip_bootstrap_url} |
${tar} ztf - |
${_egrep} '(./)?.+/pkg_install.conf$')" ; then
printf "ERR: Downloading failed\n"
exit 1
fi
pkgin_localbase_tmp="${fetch_localbase#./}"
pkgin_localbase="/${pkgin_localbase_tmp%/*/*}"

for p in bin sbin man; do
export "pkgin_localbase_${p}=${pkgin_localbase}/${p}"
done
pkgin_bin="${pkgin_localbase_bin}/pkgin"

## Generic variables and commands.
bootstrap_tmp="${HOME}/${bootstrap_tar}"

# Download bootstrap kit ; exit if fails.
if ! ${_curl} -o "${bootstrap_tmp}" "${strip_bootstrap_url}"; then
printf "version of bootstrap for ${OS} not found.\nplease install it by yourself.\n"
exit 1
fi

# Verify SHA1 checksum of the bootstrap kit.
bootstrap_sha="$(${shasum} ${bootstrap_tmp} | ${cut} -c 1-40)"
if [ "${bootstrap_hash}" != "${bootstrap_sha}" ]; then
printf "SHA mismatch ! ABOOORT Cap'tain !\n"
exit 1
fi

# If GPG available, verify GPG signature.
if [ ! -n "${gpg}" ]; then
# Verifiy PGP signature.
repo_gpgkey="$(${_egrep} -m1 'gpg --recv-keys.*' ${bootstrap_doc})"
if ! ${gpg} --keyserver hkp://keys.gnupg.net --recv-keys ${repo_gpgkey##* } >/dev/null 2>&1 ; then
confirm "Retrieve GPG keys failed, continue? [y/N] " "" "Please answer y or N "
fi
${_curl} -o "${bootstrap_tmp}.asc" "${strip_bootstrap_url}.asc"
if ! ${gpg} --verify "${bootstrap_tmp}.asc" >/dev/null 2>&1 ; then
confirm "GPG verification failed, would you still proceed? [y/N] " "" "Please answer y or N "
fi
fi

# Install bootstrap kit to the right path regarding your distribution.
${tar} xfp "${bootstrap_tmp}" -C / >/dev/null 2>&1

for var in "$bootstrap_tmp" "$bootstrap_doc"; do
if [ ! -z ${var} ] && [ ${var} != "/" ] ; then
${rm} -r -- "${var}"
fi
done

# Add {man,}path
case ${OS} in
[Dd]arwin)
pkgsrc_path="/etc/paths.d/pkgsrc"
pkgsrc_manpath="/etc/manpaths.d/pkgsrc"
path_helper="/usr/libexec/path_helper"

if [ ! -f ${pkgsrc_path} ]; then
printf "%s\n%s\n" "${pkgin_localbase_bin}" "${pkgin_localbase_sbin}" >> ${pkgsrc_path}
fi
if [ ! -f ${pkgsrc_manpath} ]; then
printf "MANPATH %s\nMANPATH %s/share/man\n" "${pkgin_localbase_man}" "${pkgin_localbase}" >> ${manpkgsrc_path}
fi
if ! ${grep} -q "path_helper" ${SHELLRC} ; then
printf "\n# Evaluate system PATH\nif [ -x /usr/libexec/path_helper ]; then\n\teval \"$(${path_helper} -s)\"\nfi\n" >> ${SHELLRC}
fi
if [ ${SHELLRC##*/} = ".bashrc" ] && [ ! -f "${SHELLRC%rc}_profile" ] ; then
printf "# Load .bashrc if it exists\ntest -f ~/.bashrc && source ~/.bashrc\n" >> "${SHELLRC%rc}_profile"
fi
if [ -x ${path_helper} ]; then
eval "$(${path_helper} -s)"
fi
;;

[Ll]inux)
# TODO: manpath.config ? manpath(5)
pkgsrc_path="/etc/profile.d/pkgsrc.sh"

if [ ! -d ${pkgsrc_path%/*} ]; then
pkgsrc_path=${pkgsrc_path%.d/*}
fi

printf "
export PATH=${pkgin_localbase_sbin}:${pkgin_localbase_bin}:${PATH}\n
export MANPATH=${pkgin_localbase_man}:${MANPATH}\n" >> "${pkgsrc_path}"

. "${pkgsrc_path}"

;;
esac

# Fetch packages.
"${pkgin_bin}" -y update
}

test_if_pkgin_is_installed()
{
pkgin="$(which pkgin 2>/dev/null)"

[ -z ${pkgin} ] &&
case ${OS} in
[Ll]inux|[Dd]arwin)
install_pkgin
;;
NetBSD)
install_pkgin_netbsd
;;
esac
return 0
}

install_3rd_party_pkg()
{
pkg=${1}
test_if_pkgin_is_installed

if ! ${pkgin} search ${pkg}; then
printf "Package not found.\n"
exit 1
else
${pkgin} -y in ${pkg}
fi
}
20 changes: 17 additions & 3 deletions include/platform.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
# platform specific variables and functions

. ${include}/helpers.sh

# needed 3rd party programs
for bin in pkg_info pkg_tarup pkgin rsync curl
for bin in pkg_info pkg_tarup pkgin rsync curl pax
do
binpath=`which ${bin}`
[ -f /etc/profile ] && . /etc/profile

binpath="$(which ${bin} 2>/dev/null)"
if [ -z "${binpath}" ]; then
echo "${bin} is required for sailor to work"
exit 1
if confirm "Would you like to install ${bin}? [y/N] " "${bin} is required for sailor to work" "Please answer y or N " ; then
case ${bin} in
pkg_info|pkgin)
. ${include}/install_deps.sh
test_if_pkgin_is_installed
;;
*)
. ${include}/install_deps.sh
install_3rd_party_pkg "${bin}"
esac
fi
fi
eval ${bin}=${binpath}
done
Expand Down
12 changes: 6 additions & 6 deletions sailor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ usage()
cmd=${1}
param=${2}

. ${include}/define.sh
. ${include}/platform.sh
. ${include}/deps.sh
. ${include}/helpers.sh

if [ "$(${id} -u)" != "0" ]; then
if [ "$($(which id) -u)" != "0" ]; then
echo "please run $0 with UID 0"
exit 1
fi

. ${include}/platform.sh
. ${include}/define.sh
. ${include}/deps.sh
. ${include}/helpers.sh

reqs=""
libs=""
varbase=$(${pkg_info} -QVARBASE pkgin)
Expand Down