From 4d2538d329df9ddeb864dd6bb48e23a1eec87a70 Mon Sep 17 00:00:00 2001 From: fox Date: Wed, 25 Nov 2020 23:40:40 +0000 Subject: [PATCH] initial commit --- LICENSE | 20 +++++ README | 4 + alpine-prep.sh | 45 +++++++++++ bootstrap.sh | 23 ++++++ compendium.sh | 180 ++++++++++++++++++++++++++++++++++++++++++ convert-git.sh | 26 ++++++ convert-how.sh | 8 ++ convert-tarball.sh | 36 +++++++++ get-alpine-patches.sh | 39 +++++++++ install.sh | 51 ++++++++++++ installed.sh | 3 + leaves.sh | 18 +++++ list-upped.sh | 0 make-src-tarball.sh | 36 +++++++++ makechecks.sh | 6 ++ mkbootstrap.sh | 68 ++++++++++++++++ mkbootstrap2.sh | 69 ++++++++++++++++ o2n.sh | 68 ++++++++++++++++ sloc.sh | 25 ++++++ softlink.sh | 32 ++++++++ src-new-git.sh | 44 +++++++++++ src-new-tarball.sh | 55 +++++++++++++ 22 files changed, 856 insertions(+) create mode 100644 LICENSE create mode 100644 README create mode 100755 alpine-prep.sh create mode 100755 bootstrap.sh create mode 100644 compendium.sh create mode 100755 convert-git.sh create mode 100755 convert-how.sh create mode 100755 convert-tarball.sh create mode 100755 get-alpine-patches.sh create mode 100755 install.sh create mode 100644 installed.sh create mode 100755 leaves.sh create mode 100644 list-upped.sh create mode 100755 make-src-tarball.sh create mode 100755 makechecks.sh create mode 100755 mkbootstrap.sh create mode 100755 mkbootstrap2.sh create mode 100755 o2n.sh create mode 100755 sloc.sh create mode 100755 softlink.sh create mode 100755 src-new-git.sh create mode 100755 src-new-tarball.sh diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bd8c239 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright 2020 "yafox" + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README b/README new file mode 100644 index 0000000..0aa7e51 --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +lix-os-utilities +================ + +contains some scripts yafox has found useful for maintaining lix os. diff --git a/alpine-prep.sh b/alpine-prep.sh new file mode 100755 index 0000000..135d433 --- /dev/null +++ b/alpine-prep.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env sh +set -e + +export GITURL="http://git.fuwafuwaqtlkkxwc.onion/yafox" + +basicup() { + git clone $GITURL/$1 + cd $1 + make install + cd .. +} + +apk add build-base coreutils cmake git curl rsync cryptsetup autoconf + +git clone $GITURL/vercmp +cd vercmp +make lix-os-formats +make install +cd .. + +basicup shsort + +git clone $GITURL/how +cd how +make lix-os-how +make install +cd .. + +basicup chin +basicup src +basicup lmr +basicup lyr +basicup lix + +git clone $GITURL/lix-os-utilities +mkdir bootstrap +./lix-os-utilities/mkbootstrap.sh bootstrap + +# TODO: make this generic +mkdir linux-mnt +lix --bootstrap=bootstrap pull linux-kernel +lix --bootstrap=bootstrap mount linux-mnt linux-kernel +cp /mnt2/ppc64le-config linux-mnt/mnt/src/.config +lix umount linux-mnt linux-kernel +rmdir linux-mnt diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..747e95d --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +[ "$1" ] || { echo "usage: bootstrap.sh [--skip-to ] " && exit 0; } + +trap 'trap - INT; kill -s INT "$$"' INT + +deps="$(lix deps lix-os | cut -d' ' -f1)" +skipping=0 + +if [ "$1" = "--skip-to" ]; then + skipto="$2" + shift + shift +fi + +for dep in $deps; do + [ "$skipto" ] && [ "$dep" != "$skipto" ] || skipping=1 + [ "$skipping" -ne 0 ] || continue + echo "bootstrapping $dep" + lix --bootstrap=$1 add $dep +done diff --git a/compendium.sh b/compendium.sh new file mode 100644 index 0000000..614c1fc --- /dev/null +++ b/compendium.sh @@ -0,0 +1,180 @@ +#!/bin/sh -e + +# source this file and use these functions. + +# getalpinepatches / [timeout] +getalpinepatches() { + [ -n "$1" ] \ + || { echo "usage: $(basename $0) [timeout]" && exit 0; } + + [ "$1" != "-c" ] || { shift; cached="yes"; } + [ "$1" != "-r" ] || { shift; reparse="yes"; } + + name="$1" + timeout=${2:-5} + + cleanup() { [ -f "$temp" ] && rm "$temp"; } + trap cleanup EXIT + + temp="$(mktemp)" + + # main + #url="https://git.alpinelinux.org/aports/tree/$name?h=master" + #pre="tree listing" + #pst="<\/table" + #rex="href='.+\/([^\/]+.patch)'" + #plain="https://git.alpinelinux.org/aports/plain" + + # github mirror + url="https://github.com/alpinelinux/aports/tree/master/$name" + pre="repository-content" + pst="footer container" + rex='title="([^\/]+.patch)"' + plain="https://raw.githubusercontent.com/alpinelinux/aports/master" + + # extract the text between the pre and post regexes on the target webpage. + { curl --compressed -m $timeout -L -s $url \ + || { echo "url failed" >&2 && continue; }; } \ + | awk "sub(/^.*$pre/,\"\"){echo=1} /$pst/{echo=0} echo" \ + > $temp + + perl -n -e "/$rex/ && print \"\$1\\n\"" $temp | while read path; do + curl -LO "$plain/$name/$path" + done +} + +# importalpinepatches / [timeout] +importalpinepatches() { + mkdir patches-enabled patches-available + cd patches-available + getalpinepatches $1 $2 + [ "$(ls)" ] || { cd .. && return 0; } + cd ../patches-enabled + ln -s ../patches-available/* . + ls + cd .. +} + +# howfromalpine / [lix-name [timeout]] +howfromalpine() { + alpinepkg="$1" + pkg="$2" + pkgs="${HOWROOT:-/lix-os/how}/pkg" + + [ "$pkg" ] || pkg="${alpinepkg#*/}" + + cd "$pkgs" + mkdir -p "$pkg/default" + cd "$pkg/default" + + plain="https://raw.githubusercontent.com/alpinelinux/aports/master" + curl -LO "$plain/$alpinepkg/APKBUILD" + cp APKBUILD "conf.sh" + cp APKBUILD "make.sh" + cp APKBUILD "inst.sh" + cp "$pkgs/../default/deps" . + chmod +x *.sh + + importalpinepatches "$alpinepkg" $3 + + cat APKBUILD | grep "source=" +} + +# srcnewtar [sig url] +srcnewtar() { + [ "$SRCROOT" != "" ] || { echo "please specify SRCROOT" && exit 1; } + + if [ ! "$4" ]; then + echo "usage: $0 [sig url]" + exit + fi + + name="$1" + version="$2" + type="$3" + arcurl="$(eval "echo \"$4\"")" + sigurl="$(eval "echo \"$5\"")" + mkdir -p $SRCROOT/pkg/$name + tmpdir="$(mktemp -d)" + + arcdest="$tmpdir/$name-$version.$type" + sigdest="$tmpdir/$name-$version.$type.sig" + + [ ! "$(echo "$name" | cut -d/ -f2)" ] || mkdir -p "$tmpdir/$(dirname "$name")" + + curl -L -o "$arcdest" "$arcurl" + size="$(wc -c "$arcdest" | cut -d' ' -f1)" + sum="$(sha512sum "$arcdest" | cut -d' ' -f1)" + + cat << EOF > $SRCROOT/pkg/$name/defaults.sh +version="$version" +type="$type" +EOF + + printf "\$version\t\$type\tarc\t$4\n" >> $SRCROOT/pkg/$name/urls + printf "$version\t$type\tarc\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks + + if [ "$sigurl" ]; then + curl -L -o "$sigdest" "$sigurl" + size="$(wc -c "$sigdest" | cut -d' ' -f1)" + sum="$(sha512sum "$sigdest" | cut -d' ' -f1)" + + printf "\$version\t\$type\tsig\t$5\n" >> $SRCROOT/pkg/$name/urls + printf "$version\t$type\tsig\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks + fi + + printf "\n$name defaults.sh\n======\n" + cat $SRCROOT/pkg/$name/defaults.sh + + printf "\n$name urls\n======\n" + cat $SRCROOT/pkg/$name/urls + + printf "\n$name checks\n======\n" + cat $SRCROOT/pkg/$name/checks + + rm -fr "$tmpdir" +} + +# srcnewgit +srcnewgit() { + [ "$SRCROOT" != "" ] || { echo "please specify SRCROOT" && exit 1; } + + if [ ! "$3" ]; then + echo "usage: $0 " + exit + fi + + name="$1" + version="$2" + arcurl="$(eval "echo \"$3\"")" + mkdir -p $SRCROOT/pkg/$name + + tmpdir="$(mktemp -d)" + arcdest="$tmpdir/$name-$version" + + git clone --mirror "$arcurl" "$arcdest" + + cd "$arcdest" + size="$(git count-objects -vH | grep size-pack | cut -d': ' -f2)" + sum="$(find . -type f ! -path '**/.git/**' ! -name '.git' | sort | xargs sha512sum | cut -d' ' -f1 | sha512sum | cut -d' ' -f1)" + cd - >/dev/null + + cat << EOF > $SRCROOT/pkg/$name/defaults.sh +version="$version" +type="git" +EOF + + printf "\$version\tgit\tarc\t$3\n" >> $SRCROOT/pkg/$name/urls + printf "$version\tgit\tarc\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks + + printf "\n$name defaults.sh\n======\n" + cat $SRCROOT/pkg/$name/defaults.sh + + printf "\n$name urls\n======\n" + cat $SRCROOT/pkg/$name/urls + + printf "\n$name checks\n======\n" + cat $SRCROOT/pkg/$name/checks + + rm -fr "$tmpdir" +} diff --git a/convert-git.sh b/convert-git.sh new file mode 100755 index 0000000..4141167 --- /dev/null +++ b/convert-git.sh @@ -0,0 +1,26 @@ +set -e + +cp -a /mu/pkg/$1 . +cd $1 +[ -z "$2" ] || version="$(cat version)" + +git clone --bare "$(cat url)" "git-bare" +cd "git-bare" + +git worktree add -f "../git-worktree" $version + +cd ../git-worktree +[ -n "$version" ] || git log | head -n1 | cut -d' ' -f2 > ../version +cd .. +printf %s\\t%s\\t%s\\t%s\\t%s\\n "$(cat version)" "$(cat type)" "arc" "$(expr $(du -sk git-worktree | cut -f1) \* 1024)" "$(cat sha512)">checks +printf %s\\t%s\\t%s\\t%s\\n "$(cat version)" "$(cat type)" "arc" "$(cat url)">urls +printf "version=\"$(cat version)\"\\ntype=\"$(cat type)\"\\n">defaults.sh +rm -fr git-bare git-worktree type url sha512 version patch inst.sh make.sh conf.sh pull.sh + +echo "done!" + +cat urls +echo +cat checks +echo +cat defaults.sh diff --git a/convert-how.sh b/convert-how.sh new file mode 100755 index 0000000..4951529 --- /dev/null +++ b/convert-how.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +cd $1 +mkdir default +mv *.sh default/ +mv patch default/ +rm * +cat default/*.sh diff --git a/convert-tarball.sh b/convert-tarball.sh new file mode 100755 index 0000000..2d72a05 --- /dev/null +++ b/convert-tarball.sh @@ -0,0 +1,36 @@ +set -e + +mu="$MUROOT/pkg/$1" +[ -d $1 ] || cp -a /mu/pkg/$1 . +cd $1 + +export version="$(cat $mu/version)" +export type="$(cat $mu/type)" +export url="$(cat $mu/url)" +curl -L -o src.$type "$(eval "echo \"$url\"")" + +(echo "$url" | grep -q '$version') \ +&& urlversion='$version' \ +|| urlversion="$version" + +if [ -f sig-url ]; then + export sigurl="$(cat $mu/sig-url)" + curl -L -o src.${type}.sig "$(eval "echo \"$sigurl\"")" +fi +printf %s\\t%s\\t%s\\t%s\\t%s\\n "$version" "$type" "arc" "$(wc -c src.$type | cut -d' ' -f1)" "$(sha512sum src.$type | cut -d' ' -f1)">>checks +printf %s\\t%s\\t%s\\t%s\\n "$urlversion" "$type" "arc" "$url">>urls + +if [ -f "src.${type}.sig" ]; then + printf %s\\t%s\\t%s\\t%s\\t%s\\n "$version" "$type" "sig" "$(wc -c src.${type}.sig | cut -d' ' -f1)" "$(sha512sum src.${type}.sig | cut -d' ' -f1)">>checks + printf %s\\t%s\\t%s\\t%s\\n "$urlversion" "$type" "sig" "$sigurl">>urls +fi +printf "version=\"$version\"\\ntype=\"$type\"\\n">defaults.sh +rm "src.$type" "src.${type}.sig" type url sig-url sha512 version patch inst.sh make.sh conf.sh pull.sh || true + +echo "done!" + +cat urls +echo +cat checks +echo +cat defaults.sh diff --git a/get-alpine-patches.sh b/get-alpine-patches.sh new file mode 100755 index 0000000..38ad1bd --- /dev/null +++ b/get-alpine-patches.sh @@ -0,0 +1,39 @@ +#!/bin/sh -e + +[ -n "$1" ] \ +|| { echo "usage: $(basename $0) [timeout]" && exit 0; } + +[ "$1" != "-c" ] || { shift; cached="yes"; } +[ "$1" != "-r" ] || { shift; reparse="yes"; } + +name="$1" +timeout=${2:-5} + +cleanup() { [ -f "$temp" ] && rm "$temp"; } +trap cleanup EXIT + +temp="$(mktemp)" + +# main +#url="https://git.alpinelinux.org/aports/tree/$name?h=master" +#pre="tree listing" +#pst="<\/table" +#rex="href='.+\/([^\/]+.patch)'" +#plain="https://git.alpinelinux.org/aports/plain" + +# github mirror +url="https://github.com/alpinelinux/aports/tree/master/$name" +pre="repository-content" +pst="footer container" +rex='title="([^\/]+.patch)"' +plain="https://raw.githubusercontent.com/alpinelinux/aports/master" + +# extract the text between the pre and post regexes on the target webpage. +{ curl --compressed -m $timeout -L -s $url \ +|| { echo "url failed" >&2 && continue; }; } \ +| awk "sub(/^.*$pre/,\"\"){echo=1} /$pst/{echo=0} echo" \ +> $temp + +perl -n -e "/$rex/ && print \"\$1\\n\"" $temp | while read path; do + curl -LO "$plain/$name/$path" +done diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..1d02213 --- /dev/null +++ b/install.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +set -e + +[ "$1" ] || { echo "usage: install.sh " && exit 0; } + +lixmnt="$(mktemp -d)" +trap 'trap - INT; kill -s INT "$$"; rmdir "$lixmnt"' INT +trap 'rmdir "$lixmnt"' EXIT + +echo "pulling the lix-os package..." +lix pull lix-os + +echo "transferring lix-os dependency chroot contents to target..." +lix deps lix-os | awk '{ print "lix/" $1 "/" $2 "/fs" }' | while read layer; do + echo "copying from $layer" + rsync -ah --info=progress2 --force "$(lyr upperdir $layer)/" "$1/" +done + +## below is the old way this was done. this required a custom "mount" binary. +## works fine in lix os, but not in host distributions used for bootstrapping. +## lix os' mount sets aside a whopping 8KiB for the option string. if the +## option string is too long for the memory set aside, the "mount" +## implementations the author has used fail silently! +#echo "transferring lix-os chroot contents to target..." +#lix mount "$lixmnt" lix-os +#rsync -ah --info=progress2 --force "$lixmnt/" "$1/" +#lix umount "$lixmnt" lix-os +#umount "$lixmnt" + +transfer() { + if [ -d "$1" ]; then + mkdir -p "$2" + rsync -ah --info=progress2 --force "$1" "$2" + else + echo "unable to find $1! transfer manually before proceeding..." >&2 + fi +} + +echo "transferring lyr state to target..." +transfer "/usr/var/lyr/" "$1/var/lyr/" + +echo "transferring src state to target..." +transfer "/usr/var/src/" "$1/var/src/" + +echo "transferring src state to target..." +transfer "/usr/var/src/" "$1/var/src/" + +echo "removing LICENSE and README in target system root..." +[ ! -f "$1/LICENSE" ] || rm "$1/LICENSE" +[ ! -f "$1/README" ] || rm "$1/README" diff --git a/installed.sh b/installed.sh new file mode 100644 index 0000000..98bd34a --- /dev/null +++ b/installed.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +find /bin /lib /etc /share -type l -exec readlink {} \; | grep lyr/upper/lix | cut -d/ -f7-8 | sort | uniq diff --git a/leaves.sh b/leaves.sh new file mode 100755 index 0000000..be4a78b --- /dev/null +++ b/leaves.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh +set -e + +# given a sorted list of packages, finds the ones which appear in none of the +# dependencies of the listed packages. +[ "$1" ] || { >&2 echo "usage: leaves " && exit 1; } + +tmp="$(mktemp)" +#trap "rm $tmp" EXIT INT HUP + +cat "$1" | while read foobar; do + echo "getting $foobar dependencies..." + lix deps "$foobar" | cut -d' ' -f1 >> "$tmp" +done +cp "$tmp" "$tmp.bak" +cat "$tmp" | sort | uniq > "$tmp" +comm -23 "$1" "$tmp" +echo "$tmp" diff --git a/list-upped.sh b/list-upped.sh new file mode 100644 index 0000000..e69de29 diff --git a/make-src-tarball.sh b/make-src-tarball.sh new file mode 100755 index 0000000..b38e69c --- /dev/null +++ b/make-src-tarball.sh @@ -0,0 +1,36 @@ +set -e + +mu="$MUROOT/pkg/$1" +[ -d $1 ] || cp -a "$mu" . +cd $1 + +export version="$(cat $mu/version)" +export type="$(cat $mu/type)" +export url="$(cat $mu/url)" +curl -L -o src.$type "$(eval "echo \"$url\"")" + +(echo "$url" | grep -q '$version') \ +&& urlversion='$version' \ +|| urlversion="$version" + +if [ -f sig-url ]; then + export sigurl="$(cat $mu/sig-url)" + curl -L -o src.${type}.sig "$(eval "echo \"$sigurl\"")" +fi +printf %s\\t%s\\t%s\\t%s\\t%s\\n "$version" "$type" "arc" "$(wc -c src.$type | cut -d' ' -f1)" "$(sha512sum src.$type | cut -d' ' -f1)">>checks +printf %s\\t%s\\t%s\\t%s\\n "$urlversion" "$type" "arc" "$url">>urls + +if [ -f "src.${type}.sig" ]; then + printf %s\\t%s\\t%s\\t%s\\t%s\\n "$version" "$type" "sig" "$(wc -c src.${type}.sig | cut -d' ' -f1)" "$(sha512sum src.${type}.sig | cut -d' ' -f1)">>checks + printf %s\\t%s\\t%s\\t%s\\n "$urlversion" "$type" "sig" "$sigurl">>urls +fi +printf "version=\"$version\"\\ntype=\"$type\"\\n">defaults.sh +rm "src.$type" "src.${type}.sig" type url sig-url sha512 version patch inst.sh make.sh conf.sh pull.sh || true + +echo "done!" + +cat urls +echo +cat checks +echo +cat defaults.sh diff --git a/makechecks.sh b/makechecks.sh new file mode 100755 index 0000000..8a4c75a --- /dev/null +++ b/makechecks.sh @@ -0,0 +1,6 @@ +type="$1" +version="$2" +curl -o src.$type -L "$(eval "echo \"$(cat "urls")\"" | awk "/\tarc\t/" | cut -f4)" +printf %s\\t%s\\t%s\\t%s\\t%s\\n $version $type "arc" "$(wc -c src.$type | cut -d' ' -f1)" "$(sha512sum src.$type | cut -d' ' -f1)" >> checks +curl -o src.$type.sig -L "$(eval "echo \"$(cat "urls")\"" | awk "/\tsig\t/" | cut -f4)" +printf %s\\t%s\\t%s\\t%s\\t%s\\n $version $type "sig" "$(wc -c src.$type.sig | cut -d' ' -f1)" "$(sha512sum src.$type.sig | cut -d' ' -f1)" >> checks diff --git a/mkbootstrap.sh b/mkbootstrap.sh new file mode 100755 index 0000000..2f0dfd9 --- /dev/null +++ b/mkbootstrap.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# populates a directory with host directories. +# modify and use as needed. + +[ "$1" ] || echo "usage: mkbootstrap " + +if [ ! -d "$1" ]; then + echo "$1 is not a directory!" >&2 + exit 1 +fi +dest="$1" + +case "$dest" in + /usr/*|/lib/*|/libexec/*|/etc/*|/bin/*|/share/*) + echo "destination path cannot be a subpath of the source paths." >&2 + exit 1 + ;; +esac + +up() { + printf "$(echo "checking $1 .........." | head -c 20)" + if [ -d "/$1" ] && [ ! -d "$dest/$1" ]; then + printf " merging $1\n" + # is this a symlink to a directory? + [ -h "/$1" ] \ + && cp -a "/$1" "$dest/" \ + || mkdir "$dest/$1" && lmr "/$1" "$dest/$1" + else + printf " skipping $1\n" + fi +} + +up lib +up libexec +up etc +up bin +up share +mkdir -p "$dest/boot" + +# force bootstrap directory into lix os-style directory structure. +lmr -f /usr $dest \ +&& echo "merged /usr into $dest" \ +|| echo "did not lmr /usr into $dest" + +lmr -f $dest/local $dest \ +&& echo "merged $dest/local into $dest" \ +|| echo "did not lmr $dest/local into $dest" + +rm -fr $dest/local \ +&& echo "removed $dest/local" \ +|| echo "did not remove $dest/local" + +lmr -f $dest/sbin $dest/bin \ +&& echo "merged $dest/sbin into $dest/bin" \ +|| echo "did not lmr $dest/sbin into $dest/bin" + +rm -fr $dest/sbin \ +&& echo "removed $dest/sbin" \ +|| echo "did not remove $dest/sbin" + +ln -sf . $dest/usr \ +&& echo "ln'ed $dest/usr to ." \ +|| echo "did not ln $dest/usr to ." + +ln -sf ./bin $dest/sbin \ +&& echo "ln'ed $dest/sbin to ./bin" \ +|| echo "did not ln $dest/sbin to ./bin" diff --git a/mkbootstrap2.sh b/mkbootstrap2.sh new file mode 100755 index 0000000..75c2fb7 --- /dev/null +++ b/mkbootstrap2.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +# populates a directory with host directories. +# modify and use as needed. + +[ "$1" ] || echo "usage: mkbootstrap " + +if [ ! -d "$1" ]; then + echo "$1 is not a directory!" >&2 + exit 1 +fi +dest="$1" + +case "$dest" in + /usr/*|/lib/*|/libexec/*|/etc/*|/bin/*|/share/*) + echo "destination path cannot be a subpath of the source paths." >&2 + exit 1 + ;; +esac + +up() { + printf "$(echo "checking $1 .........." | head -c 20)" + if [ -d "/$1" ] && [ ! -d "$dest/$1" ]; then + printf " merging $1\n" + # is this a symlink to a directory? + [ -h "/$1" ] \ + && cp -a "/$1" "$dest/" \ + || mkdir "$dest/$1" && lmr "/$1" "$dest/$1" + else + printf " skipping $1\n" + fi +} + +up lib +up libexec +up etc +up bin +up sbin +up share +mkdir -p "$dest/boot" + +# facilitate lix os' "/usr is a soft link to /" scheme. +lmr -f /usr $dest \ +&& echo "merged /usr into $dest" \ +|| echo "did not lmr /usr into $dest" + +ln -sf . $dest/usr \ +&& echo "ln'ed $dest/usr to ." \ +|| echo "did not ln $dest/usr to ." + +#lmr -f $dest/local $dest \ +#&& echo "merged $dest/local into $dest" \ +#|| echo "did not lmr $dest/local into $dest" +# +##rm -fr $dest/local \ +#&& echo "removed $dest/local" \ +#|| echo "did not remove $dest/local" + +lmr -f $dest/sbin $dest/bin \ +&& echo "merged $dest/sbin into $dest/bin" \ +|| echo "did not lmr $dest/sbin into $dest/bin" + +rm -fr $dest/sbin \ +&& echo "removed $dest/sbin" \ +|| echo "did not remove $dest/sbin" + +ln -sf ./bin $dest/sbin \ +&& echo "ln'ed $dest/sbin to ./bin" \ +|| echo "did not ln $dest/sbin to ./bin" diff --git a/o2n.sh b/o2n.sh new file mode 100755 index 0000000..f1e4648 --- /dev/null +++ b/o2n.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +set -e + +[ "$1" ] \ +&& pkg="$1" \ +|| pkg="$(head -n1 ../todo)" +echo "converting $pkg" +cd $pkg + +type="$(cut -d' ' -f1 checksums)" +version="$(cut -d' ' -f2 checksums)" +checksum="$(cut -d' ' -f3 checksums)" +url="$(eval "echo \"$(head -n1 $type-urls)\"")" +echo "$type" +echo "$version" +echo "$checksum" +echo "$url" + +if [ -f "$type-sigurls" ]; then + sigurl="$(eval "echo \"$(head -n1 $type-sigurls)\"")" +fi + +echo "pulling archive" +if [ "$type" = "git" ]; then + git clone --bare "$url" "git-bare" + cd "git-bare" + git worktree add -f "../git-worktree" $version + + cd ../git-worktree + version="$(git log | head -n1 | cut -d' ' -f2)" # force use of commit hash + cd .. + size="$(expr $(du -sk git-worktree | cut -f1) \* 1024)" + rm -fr git-worktree git-bare + printf %s\\t%s\\t%s\\t%s\\n '$version' "$type" "arc" "$(head -n1 $type-urls)">urls + +else + curl -o src.$type -L "$url" + [ "$checksum" ] || checksum="$(sha512sum src.$type | cut -d' ' -f1)" + [ "$(sha512sum src.$type | cut -d' ' -f1)" = "$checksum" ] || { echo "checksum mismatch" && exit 1; } + size="$(wc -c src.$type | cut -d' ' -f1)" + rm src.$type + printf %s\\t%s\\t%s\\t%s\\n '$version' '$type' "arc" "$(head -n1 $type-urls)">urls +fi +printf %s\\t%s\\t%s\\t%s\\t%s\\n "$version" "$type" "arc" "$size" "$checksum">checks +printf "version=\"$version\"\\ntype=\"$type\"\\n">defaults.sh + + +if [ "$sigurl" ]; then + echo "pulling signature" + curl -o sig -L "$sigurl" + size="$(wc -c sig | cut -d' ' -f1)" + checksum="$(sha512sum sig | cut -d' ' -f1)" + [ "$(sha512sum sig | cut -d' ' -f1)" = "$checksum" ] || { echo "signature checksum mismatch" && exit 1; } + printf %s\\t%s\\t%s\\t%s\\n '$version' '$type' "sig" "$(head -n1 $type-sigurls)">>urls + printf %s\\t%s\\t%s\\t%s\\t%s\\n "$version" "$type" "sig" "$size" "$checksum">>checks + rm sig +fi + +rm -fr checksums defaults *-sigurls *-urls + +echo + +cat urls +echo +cat checks +echo +cat defaults.sh diff --git a/sloc.sh b/sloc.sh new file mode 100755 index 0000000..d0810df --- /dev/null +++ b/sloc.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env sh + +#find lix how src lyr lmr chin vercmp -name README ! -path "**/**/**" \ +#| xargs sed -n 's/^[^0-9]*\([0-9]\+\) ELOC.*$/\1/p' \ + +sum="0" +while read line; do + cd $line + loc="$(./sloc.sh)" + printf "%s:\\t%s\\n" "$line" "$loc" + sum="$(expr $sum + $loc)" + cd - > /dev/null +done <" && exit 0; } + +echo "chrooting into target and setting up softlinks..." +cd "$1" + +>"_softlink.sh" cat <&2 echo "refusing to overwrite /boot contents!" +# exit 1 +#fi + +echo "about to softlink..." +deps="\$(lix deps lix-os | cut -d' ' -f1)" +for dep in \$deps; do + echo "linking \$dep" + lix up -f \$dep +done + +echo "wiping /boot links." +rm -fr /boot/* +EOF + +chmod +x "_softlink.sh" +chin "$1" "./_softlink.sh" +cd - >/dev/null +rm "$1/_softlink.sh" diff --git a/src-new-git.sh b/src-new-git.sh new file mode 100755 index 0000000..9530253 --- /dev/null +++ b/src-new-git.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +set -e + +[ "$SRCROOT" != "" ] || { echo "please specify SRCROOT" && exit 1; } + +if [ ! "$3" ]; then + echo "usage: $0 " + exit +fi + +name="$1" +version="$2" +arcurl="$(eval "echo \"$3\"")" +mkdir -p $SRCROOT/pkg/$name + +tmpdir="$(mktemp -d)" +arcdest="$tmpdir/$name-$version" + +git clone --mirror "$arcurl" "$arcdest" + +cd "$arcdest" +size="$(git count-objects -vH | grep size-pack | cut -d': ' -f2)" +sum="$(find . -type f ! -path '**/.git/**' ! -name '.git' | sort | xargs sha512sum | cut -d' ' -f1 | sha512sum | cut -d' ' -f1)" +cd - >/dev/null + +cat << EOF > $SRCROOT/pkg/$name/defaults.sh +version="$version" +type="git" +EOF + +printf "\$version\tgit\tarc\t$3\n" >> $SRCROOT/pkg/$name/urls +printf "$version\tgit\tarc\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks + +printf "\n$name defaults.sh\n======\n" +cat $SRCROOT/pkg/$name/defaults.sh + +printf "\n$name urls\n======\n" +cat $SRCROOT/pkg/$name/urls + +printf "\n$name checks\n======\n" +cat $SRCROOT/pkg/$name/checks + +rm -fr "$tmpdir" diff --git a/src-new-tarball.sh b/src-new-tarball.sh new file mode 100755 index 0000000..1b10371 --- /dev/null +++ b/src-new-tarball.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +set -e + +[ "$SRCROOT" != "" ] || { echo "please specify SRCROOT" && exit 1; } + +if [ ! "$4" ]; then + echo "usage: $0 []" + exit +fi + +name="$1" +version="$2" +type="$3" +arcurl="$(eval "echo \"$4\"")" +sigurl="$(eval "echo \"$5\"")" +mkdir -p $SRCROOT/pkg/$name +tmpdir="$(mktemp -d)" + +arcdest="$tmpdir/$name-$version.$type" +sigdest="$tmpdir/$name-$version.$type.sig" + +[ ! "$(echo "$name" | cut -d/ -f2)" ] || mkdir -p "$tmpdir/$(dirname "$name")" + +curl -L -o "$arcdest" "$arcurl" +size="$(wc -c "$arcdest" | cut -d' ' -f1)" +sum="$(sha512sum "$arcdest" | cut -d' ' -f1)" + +cat << EOF > $SRCROOT/pkg/$name/defaults.sh +version="$version" +type="$type" +EOF + +printf "\$version\t\$type\tarc\t$4\n" >> $SRCROOT/pkg/$name/urls +printf "$version\t$type\tarc\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks + +if [ "$sigurl" ]; then + curl -L -o "$sigdest" "$sigurl" + size="$(wc -c "$sigdest" | cut -d' ' -f1)" + sum="$(sha512sum "$sigdest" | cut -d' ' -f1)" + + printf "\$version\t\$type\tsig\t$5\n" >> $SRCROOT/pkg/$name/urls + printf "$version\t$type\tsig\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks +fi + +printf "\n$name defaults.sh\n======\n" +cat $SRCROOT/pkg/$name/defaults.sh + +printf "\n$name urls\n======\n" +cat $SRCROOT/pkg/$name/urls + +printf "\n$name checks\n======\n" +cat $SRCROOT/pkg/$name/checks + +rm -fr "$tmpdir"