Skip to content
Permalink
Browse files

Add get script, Derek and version command

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
  • Loading branch information...
alexellis committed Aug 15, 2019
1 parent 1dd518c commit 489e517ebbce19d367ccc49964af070157a4f14f
Showing with 141 additions and 2 deletions.
  1. +1 −0 .DEREK.yml
  2. +7 −1 README.md
  3. +117 −0 get.sh
  4. +16 −1 main.go
@@ -0,0 +1 @@
redirect: https://raw.githubusercontent.com/openfaas/faas/master/.DEREK.yml
@@ -43,4 +43,10 @@ kubectl get node

## License

MIT
MIT

## Contributing

As per [OpenFaaS](https://github.com/openfaas/faas/blob/master/CONTRIBUTING.md)

All commits must be signed-off as part of the [Developer Certificate of Origin (DCO)](https://developercertificate.org)
117 get.sh
@@ -0,0 +1,117 @@
#!/bin/bash
# This script was adapted from https://github.com/openfaas/cli.openfaas.com/blob/master/get.sh

export OWNER=alexellis
export REPO=k3sup

version=$(curl -sI https://github.com/$OWNER/$REPO/releases/latest | grep Location | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')

if [ ! $version ]; then
echo "Failed while attempting to install $REPO. Please manually install:"
echo ""
echo "1. Open your web browser and go to https://github.com/$OWNER/$REPO/releases"
echo "2. Download the latest release for your platform. Call it '$REPO'."
echo "3. chmod +x ./$REPO"
echo "4. mv ./$REPO /usr/local/bin"
exit 1
fi

hasCli() {

has=$(which $REPO)

if [ "$?" = "0" ]; then
echo
echo "You already have the $REPO cli!"
export n=1
echo "Overwriting in $n seconds.. Press Control+C to cancel."
echo
sleep $n
fi

hasCurl=$(which curl)
if [ "$?" = "1" ]; then
echo "You need curl to use this script."
exit 1
fi
}

getPackage() {
uname=$(uname)
userid=$(id -u)

suffix=""
case $uname in
"Darwin")
suffix="-darwin"
;;
"Linux")
arch=$(uname -m)
echo $arch
case $arch in
"aarch64")
suffix="-arm64"
;;
esac
case $arch in
"armv6l" | "armv7l")
suffix="-armhf"
;;
esac
;;
esac

targetFile="/tmp/$REPO$suffix"

if [ "$userid" != "0" ]; then
targetFile="$(pwd)/$REPO$suffix"
fi

if [ -e $targetFile ]; then
rm $targetFile
fi

url=https://github.com/alexellis/$REPO/releases/download/$version/$REPO$suffix
echo "Downloading package $url as $targetFile"

curl -sSLf $url --output $targetFile

if [ "$?" = "0" ]; then

chmod +x $targetFile

echo "Download complete."

if [ "$userid" != "0" ]; then

echo
echo "========================================================="
echo "== As the script was run as a non-root user the =="
echo "== following commands may need to be run manually =="
echo "========================================================="
echo
echo " sudo cp $REPO$suffix /usr/local/bin/$REPO"
echo

else

echo
echo "Running as root - Attempting to move $REPO to /usr/local/bin"

mv $targetFile /usr/local/bin/$REPO

if [ "$?" = "0" ]; then
echo "New version of $REPO installed to /usr/local/bin"
fi

if [ -e $targetFile ]; then
rm $targetFile
fi

$REPO version
fi
fi
}

hasCli
getPackage
17 main.go
@@ -14,13 +14,28 @@ func main() {

cmdInstall := makeInstallCmd()

cmdVersion := makeVersionCmd()

var rootCmd = &cobra.Command{Use: "app"}

rootCmd.AddCommand(cmdInstall)

rootCmd.AddCommand(cmdVersion)
rootCmd.Execute()
}

func makeVersionCmd() *cobra.Command {
var cmd = &cobra.Command{
Use: "version",
Short: "Print the version",
Example: ` k3sup version`,
SilenceUsage: false,
}
cmd.Run = func(cmd *cobra.Command, args []string) {
fmt.Printf("Welcome to k3sup!\n")
}
return cmd
}

func makeInstallCmd() *cobra.Command {
var cmd = &cobra.Command{
Use: "install k3s",

0 comments on commit 489e517

Please sign in to comment.
You can’t perform that action at this time.