This book was written using Git version 2.8.0. Though most of the commands we use should work even in ancient versions of Git, some of them might not or might act slightly differently if you’re using an older version. Since Git is quite excellent at preserving backwards compatibility, any version after 2.8. The docx module creates, reads and writes Microsoft Office Word 2007 docx files. These are referred to as ‘WordML’, ‘Office Open XML’ and ‘Open XML’ by Microsoft. These documents can be opened in Microsoft Office 2007 / 2010, Microsoft Mac Office 2008, Google Docs, OpenOffice.org 3. Starting May 2013 ('Installing Git from GitHub for Mac'), you don't have to install another git distribution: everything is included.you can now easily install Git for use on the command line, without needing to download any separate packages. And whenever we update the version of Git included with GitHub for Mac, you'll get the changes automatically – no work required on your part! GitHub Desktop Focus on what matters instead of fighting with Git. Whether you're new to Git or a seasoned user, GitHub Desktop simplifies your development workflow. Download for macOS Download for Windows (64bit) Download for macOS or Windows (msi) Download for Windows. By downloading, you agree to the Open Source Applications Terms.
Love Child or Demon Spawn?
This article describes the use of PowerShell scripting on Mac and Linux.
“PowerShell” refers to both the command-line shell and scripting language designed system administration.
PowerShell is an object-centered “management engine”that can be hosted in an application program.
ISE = “Integrated Scripting Environment” is a GUI that providespopup tab completion and other assists.
PowerShell promises more consistency than the various commands added over time by various parties.
Open source on Linux and MacOS
From the PowerShell and DSC Team YouTube channel:
This 51-minute series of demos was published Aug 18, 2016, the same dayPowerShell is open-sourced for all OSs at
https://github.com/PowerShell/PowerShell.
This article notes Desired State Configuration for Linux and the promise of SSH support arrived in 2014 (several months before Microsoft open sourced .NET and brought .NET Core to Linux). But “you had to author your scripts on the Windows platform, you had to configure things on the Windows platform and then deliver the desired configuration to a Linux box and have it be configured; now you can do all of that on Linux.”
Install PowerShell on MacOS
Visual Studio Code Editor
One text editor built for PowerShell is Microsoft’s Visual Studio Code.
Keith Hill notesdebugging support provided by the PowerShell Editor Services extension currently runs only on Windows.
Install .NET Core
PowerShell is written on top of .NET.NET’s previous dependencies on Windows components have been removedin .NET Core.
PowerShell errors occur if .NET Core is not installed, so:
Execute script file
I like using script files rather than typing becauseit allows me to focus on the latest in what is usuallya long string of commands necessary in today’s complex world.
To call scripts, an example:
PROTIP: Make sure that when a file with .ps1 extension is clicked from Folder, the script is not launched to run, but that the script appears in a text editor.
A sample command to invoke the script including an execution policy :
Notice it’s “powershell” and not “powershell.exe” because Mac and Linux don’t recognize .exe.
When a script is signed, its location is locked to a specific full directory path, even when it’s in the current folder.
“remotesigned” is important because if this script has not been digitally signed, one needs to set PS execution policy to “RemoteSigned” (or “Unrestricted”) after reopening PowerShell as an Administrator to run:
By default PowerShell prevents the execution of PowerShell scripts on Windows systems.
Set-ExecutionPolicy RemoteSigned
Get a list of current security settings:
Get-ExecutionPolicy -List | Format-Table -AutoSize
See https://blog.netspi.com/15-ways-to-bypass-the-powershell-execution-policy/
https://github.com/MeshkDevs/InvokeTwitterAPIs
## Verify a signed script can be used #
Install a signing cert on Mac
To add the CA root certificate (either PEM or DER format) into the OSX global keychain:
Automatic logging![]()
Increasingly, hackers are using PowerShell to create havoc.
So it’s a good idea to automatically logging using the
start-transcript and stop-transcript commands.
BLAH: The sample script at https://github.com/wilsonmar/git-utilities/ps-auto-log.ps1,causes errors during execution of scripts.
Inside the file:
PROTIP: This can use up a lot of space quickly, so some management of its use is necessary.
Version Logic: If Then Else
I haven’t found a way to have a Bash script that can also be run as a PowerShell script.
PROTIP: Switching from Bash to PowerShell means a one-time migration and there is no turning back unless you want to maintainparallel scripts.
This is largely because of differences in if/then/else coding. The same if/then/else syntax in PowerShell scripts for Mac and PC is needed for the same script file to be used.
On Bash:
The question is whether a single PowerShell script can reallyrun on both Mac and Windows. Do a parallel run.
For different actions in PowerShell according to type of operating system:
NOTE: Because braces define actions, there is no “end if” (“fi”) in PowerShell.
Comparison Operators
-eq / -ne / -ge
-Like / -NotLike wildcard string - $name -Like “*sh”
-Match / -NotMatch regular expression - $name -Match “sh$”
-Contains / -NotContains a value in array - $name -contains “jo”
-In / -NotIn Is a value in an array - “joe” -in $name
Logical operators
-And
-Or
-Xor = Logical exclusive or.
Tilde and Providers
PROTIP: Use $home instead of the tilde (~)in PowerShell because tilde does not always represent the the user’s home folder as in Linux.This is because PS has different“providers” that include HKLM and HKCU top-levels in the Windows Registry.Get a list of providers and disk space:
Get-PSDrive
The response:
PowerShell calls files “items” as a term that groups files with registry keys and variables.
returns the Mode and LastWriteTime of the user.
Instead of “mkdir” to create folders, use
New-Item
To list files in a folder, it’s the same as in Bash:
ls -al
PowerShell cmdlets (command-lets) enables computers to be managed from the command line,much like Bash shell scripts on Linux machines.How many are there?
(get-command).count
https://github.com/pester/Pester/wiki/Mock
Handling secrets
PROTIP: Files containing secrets, such as passwords andcertificates are NOT stored in GitHub nor script files, but in a separate location, and backed up among other local files.
The secrets are retrieved into the script at run-time.
See my tutorial on GitHub Data Security
Hash tables
BTW, keys in a hash table must be unique.
Hash tables are used throughout PowerShell.
An example of a REST API call:
Sort a hash tables using the GetEnumertor():
Objects
Get-Service m* | where {$_.status -eq ‘running’}
Get-Service m* | where status -eq ‘running’
The “$_” represents the current object in v2 can handle more complexity than v3 syntax:
Alias not parameters
Many Bash commands work in PowerShell (ls, cat, echo) becauseAliases make many commands in Bash scripts work:
get-alias echo
The response is “Write-Output”, which is what is executed.
BLAH: Many parameters to aliases are not recognized. For example, this common command results in an error:
ls -al
Instead, use:
dir -File | format-table
NOTE: dir is an alias to Get-ChildItem.
Thus,
Write-Host $env:computername -foreground Green
”–passthru” means do not go through Pipeline.
You can reset a default alias.
Environment Variables
PROTIP: Environment variables defined in Bash scripts can be read by PowerShell scripts and visa-versa.
Lists of environment variables:
The command “dir” is an alias of Get-ChildItem.
For the value of a single environment variable: How to download from youtube mac firefox.
Get-ChildItem Env:USER
Get-ChildItem Env:AWS_DEFAULT_REGION Paths
Instead of “rm -rf” in Bash:https://blogs.technet.microsoft.com/heyscriptingguy/2012/02/22/the-best-way-to-use-powershell-to-delete-folders/
“-WhatIf” specifies a dry-run.
Combine files
Ro add the content of several files into a single text file:
Cmdlets
PS has some smarter parameters, such as filtering for files onlyand running recursively into sub-folders:
dir c:work*.ps1 -file -recurse
All PowerShell cmdlets follow a standardized verb-noun naming convention that makes it easy to look up, find, and use cmdlets.For a list of all the verbs:
get-verb
REMEMBER: Capitalization counts within PowerShell.
get-command -verb export
get-command -noun ACL paths
Only 25% of cmdlets are shipped with paths.
Strings
PROTIP: Don’t use “+” for string concatenation.
.NET Framework members
Initially built on Microsoft’s .NET Framework, PowerShell can refer to a static .NET member in square brackets with two colons to specify Pi:
[math]::pi
It’s wonderful that PowerShell doesn’t require an echo to display the value of objects.
To delete a file in the .NET I/O directory object:
The issue with using .NET objects is that they may execute in a different folder context than PowerShell.
TODO: $prompt
Other pre-defined variables
Dates
Based on http://ss64.com/ps/syntax-dateformats.html
Zip files using functionsPipelines
Instead of just parsing text (as *Nix shells do),PowerShell works with objects in a pipeline.
Piping:
To list all variables defined and their values:
Get-Variable | Out-String
PROTIP: With PowerShell, it’s best to use out-file instead of “>” redirect character:
dir -file -hidden | out-file -filepath rootfiles.txt
Error handling:
Use preference variables for stream redirection:
1> Success 2> Error 3> Warning 4> Verbose 5> Debug
NOTE: Can Only merge to the success stream.
$Error is the automatic array that stores the last 256 exceptions (objects in error) - the default $MaximumErrorCount.
Error action preferences:
0 = Silently Continue
1 = Stop 2 = Continue 3 = Inquire 4 = Ignore [parameter value only] Module to call REST API
This suggests:
PROTIP: To press the trailing back-tick that breaks up a command into several lines, press the key at the upper left corner of the keyboard with your left hand while you press shift key using your right hand.
A space character is required before the tick.
PROTIP: Break up long text into a string block (which Microsoft calls here-string):
The output is:
From https://apps.twitter.com/ define a new app. In Permissions tab, select Read-only. Click Update Settings. In Key and Access Tokens tab, click “Create my access tokens”. Copy the Consumer Key (API key) and paste in ~/.passwords as TWITTER_TOKEN.
It takes many lines to mess with OAuth, so I make use of Adam’s library for Twitter’s v1.1 API described at:
http://www.adamtheautomator.com/twitter-module-powershell/
Trevor Sullivan (@pcgeek86) made a 20:40 video Mar 17, 2016
A PowerShell Module for manipulating PowerShell ProfilesbyThomas Malkewitz
Curl
curl is an alias for Invoke-WebRequest in PowerShell.
https://channel9.msdn.com/Blogs/trevor-powershell/Automating-the-GitHub-REST-API-Using-PowerShell
## JSON from REST API #
To extract out a key from the JSON file:
https://www.pluralsight.com/courses/powershell-modules-advanced-functions-building
Profile scripts
Jeff Hicks notes these profile scripts execute automatically at start:
To view all profiles:
$profile | select *
API calls
Corporate IT departments often use Group Policies.
$Headers = “Authorization: token ${GITHUB_TOKEN}” echo “Headers=$Headers” # DEBUGGING
$Token=$GITHUBUSER +’:’+ $SECRETS.GITHUB_TOKEN; $Base64Token=[System.Convert]::ToBase64String([char[]]$Token); $Headers = @{ Authorization = ‘Basic(0)’ -f $Base64Token; }; # -f is for substitution of (0). # See https://technet.microsoft.com/en-us/library/ee692795.aspx # Write-Host (“Headers=”+$Headers.Authorization) $Headers = “{ Authorization: = Basic $GITHUB_TOKEN }” # -f is for substitution of (0). # See https://technet.microsoft.com/en-us/library/ee692795.aspx Write-Host (“Headers=”+$Headers)
Iterate
More Libraries
https://www.simple-talk.com/blogs/psyaml-powershell-yaml/
Read in CSV file
This blog gives an example of importing a CSV file:
$data = Import-CSV C:scriptsmoviedata.csv
Sorting by date requires creating a new property:
The new property persists, so can be used this way:
More on DevOps
This is one of a series on DevOps:
PrevNext
When searching a Perl module, sooner or later you will end up on one of two sites sites providing information about CPAN modules.Both Meta CPAN, and search.cpan.orgwill show you a link to download the module, but in most cases that's not what you need.
So how do you really install Perl modules from CPAN?
(As always, some people will disagree with the recommendations below, they probably have not readthe article of Dave Cross, or reachedother conclusions.)
In most cases the installation of a CPAN module works just as installing an app from the Apple Appstore or the Google Play.Except, that these modules are all open source and free software.
Depending on the Operating System and which Perl distribution you have, the specific instructions differ.In order to make the examples clearer, let's try to install the module called Try::Tiny.
It has its description both on Meta CPAN and onsearch.cpan.org. Both have the Download linksthat we won't click on.
CasesStrawberry Perl or DWIM Perl on Windows
Strawberry Perl,comes with an already configured cpan client. We will use this client to install modules directly from CPAN:
Open the Command Window (Start -> Run -> type in cmd) When you get the 'DOS' prompttype in cpan Path::Tiny.Please note, module names are case sensitive,so typing cpan path::tiny or cpan PATH::TINY will not work!
Also, in normal circumstances, the cpan client is expecting the full name of the module, not one part of the name,and not the name of the zip-file.So cpan Path or cpan Tiny will attempt to install different modules.(One called Path, the other one called Tiny.)
What you need to do is type in:
ActivePerl
There is a graphical tool for this as well, but it might be more simple just to open theCommand Window (Start -> Run -> type cmd). When you get the 'DOS' prompt, type inppm install Path::Tiny. Please note, this too is case sensitive!
The problem you might encounter is that this command uses the 'CPAN store' of ActiveState that for varioustechnical and legal reasons does not carry all the the modules from CPAN. It can also be out-of datecarrying older versions of the modules. On newer versions of ActivePerl you can also enable a realcpan-client that will access the CPAN server just as it does in the case of Strawberry/DWIM Perl above.
GitPerl
TBD.
Cygwin Perl
TBD. Cygwin.
Debian/Ubuntu Linux
If you have root rights, and if you use the system perl located in /usr/bin/perl,then probably the best is to try to install from the package management system of your Linux distribution.If you don't have root rights, you could ask your system administrator to do it on your behalf.
Apparently there is a nice way to find out if a Perl module is on Debian or Ubuntu.
If the module you are looking for is not available in the repositories of your Debian/Ubuntu/etc. distribution(and there are only about 10% of the modules available), or if you don't use the system Perl,then you can follow the instructions with cpan/cpanm below.
To install for the system-perl as root you can use either aptitude or apt-getdepending on your personal preferences.
If the name of the module in Perl-land is Path::Tiny, then the name of the package in Debian/Ubuntu-landis most likely going to be libpath-tiny-perl.
RedHat/Fedora/CentOS Linux
Just as in the case of Debian/Ubuntu above, the instructions here are relevant ifyou use the system perl located in /usr/bin/perl and if you haveroot rights:
Using the package management system:
As Dave Cross mentioned, if you don't know the name of the RH package, you can also use
The subtle difference is that the former installs the named RPM whereas the secondinstalls the RPM that provides the named Perl module.
So if you would like to install the Path::Tiny module then the second command isactually the better one.
If your vendor does not carry this Perl package, you can add other RPM repositories.Check out EPEL, andthe Magnum Solutions CPAN RPM Repositorymaintained by Dave Cross.
Mac OSX
Follow the instructions with cpan/cpanm below.
Using the cpan client
While the cpan program comes with most operating system,and it works well after some configuration, there is probably a better,and certainly lighter solution called cpan minus or cpanm.
Using cpanm
This is for Linux and OSX systems. (For Windows, see described above.)
First, if you don't have it installed yet,then install cpan minus by typing
Once it is installed type:
If you still have questions related to the installation of Perl modules,please ask them below! I'll try to update this articleto answer those questions and to explain other situations.
Specific instructions for
TODO
Separate explanation of installing using cpan/cpanm as root stepping on the system perl, using local::lib to install in a private directory while using system perl.
Using a manually compiled perl.
Using perlbrew, creating 'virtual environments'.
Published on 2014-03-13
CommentsIn the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.Please enable JavaScript to view the comments powered by Disqus.comments powered by DisqusHow To Download Modules Via Github Mac Os
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2020
Categories |